BridgmansTables

record BridgmansTables "Calculates all entries in Bridgmans tables if first seven variables given"
    extends Modelica.Icons.Record;

    SI.SpecificVolume v "Specific volume";
    SI.Pressure p "Pressure";
    SI.Temperature T "Temperature";
    SI.SpecificEntropy s "Specific entropy";
    SI.SpecificHeatCapacity cp "Heat capacity at constant pressure";
    IsobaricVolumeExpansionCoefficient alpha "Isobaric volume expansion coefficient";
    IsothermalCompressibility gamma "Isothermal compressibility";
    Real dTp = 1 "Coefficient in Bridgmans table, see info for usage";
    Real dpT = -dTp "Coefficient in Bridgmans table, see info for usage";
    Real dvp = alpha * v "Coefficient in Bridgmans table, see info for usage";
    Real dpv = -dvp "Coefficient in Bridgmans table, see info for usage";
    Real dsp = cp / T "Coefficient in Bridgmans table, see info for usage";
    Real dps = -dsp "Coefficient in Bridgmans table, see info for usage";
    Real dup = cp - alpha * p * v "Coefficient in Bridgmans table, see info for usage";
    Real dpu = -dup "Coefficient in Bridgmans table, see info for usage";
    Real dhp = cp "Coefficient in Bridgmans table, see info for usage";
    Real dph = -dhp "Coefficient in Bridgmans table, see info for usage";
    Real dfp = -s - alpha * p * v "Coefficient in Bridgmans table, see info for usage";
    Real dpf = -dfp "Coefficient in Bridgmans table, see info for usage";
    Real dgp = -s "Coefficient in Bridgmans table, see info for usage";
    Real dpg = -dgp "Coefficient in Bridgmans table, see info for usage";
    Real dvT = gamma * v "Coefficient in Bridgmans table, see info for usage";
    Real dTv = -dvT "Coefficient in Bridgmans table, see info for usage";
    Real dsT = alpha * v "Coefficient in Bridgmans table, see info for usage";
    Real dTs = -dsT "Coefficient in Bridgmans table, see info for usage";
    Real duT = alpha * T * v - gamma * p * v "Coefficient in Bridgmans table, see info for usage";
    Real dTu = -duT "Coefficient in Bridgmans table, see info for usage";
    Real dhT = -v + alpha * T * v "Coefficient in Bridgmans table, see info for usage";
    Real dTh = -dhT "Coefficient in Bridgmans table, see info for usage";
    Real dfT = -gamma * p * v "Coefficient in Bridgmans table, see info for usage";
    Real dTf = -dfT "Coefficient in Bridgmans table, see info for usage";
    Real dgT = -v "Coefficient in Bridgmans table, see info for usage";
    Real dTg = -dgT "Coefficient in Bridgmans table, see info for usage";
    Real dsv = alpha * alpha * v * v - gamma * v * cp / T "Coefficient in Bridgmans table, see info for usage";
    Real dvs = -dsv "Coefficient in Bridgmans table, see info for usage";
    Real duv = T * alpha * alpha * v * v - gamma * v * cp "Coefficient in Bridgmans table, see info for usage";
    Real dvu = -duv "Coefficient in Bridgmans table, see info for usage";
    Real dhv = T * alpha * alpha * v * v - alpha * v * v - gamma * v * cp "Coefficient in Bridgmans table, see info for usage";
    Real dvh = -dhv "Coefficient in Bridgmans table, see info for usage";
    Real dfv = gamma * v * s "Coefficient in Bridgmans table, see info for usage";
    Real dvf = -dfv "Coefficient in Bridgmans table, see info for usage";
    Real dgv = gamma * v * s - alpha * v * v "Coefficient in Bridgmans table, see info for usage";
    Real dvg = -dgv "Coefficient in Bridgmans table, see info for usage";
    Real dus = dsv * p "Coefficient in Bridgmans table, see info for usage";
    Real dsu = -dus "Coefficient in Bridgmans table, see info for usage";
    Real dhs = -v * cp / T "Coefficient in Bridgmans table, see info for usage";
    Real dsh = -dhs "Coefficient in Bridgmans table, see info for usage";
    Real dfs = alpha * v * s + dus "Coefficient in Bridgmans table, see info for usage";
    Real dsf = -dfs "Coefficient in Bridgmans table, see info for usage";
    Real dgs = alpha * v * s - v * cp / T "Coefficient in Bridgmans table, see info for usage";
    Real dsg = -dgs "Coefficient in Bridgmans table, see info for usage";
    Real dhu = p * alpha * v * v + gamma * v * cp * p - v * cp - p * T * alpha * alpha * v * v "Coefficient in Bridgmans table, see info for usage";
    Real duh = -dhu "Coefficient in Bridgmans table, see info for usage";
    Real dfu = s * T * alpha * v - gamma * v * cp * p - gamma * v * s * p + p * T * alpha * alpha * v * v "Coefficient in Bridgmans table, see info for usage";
    Real duf = -dfu "Coefficient in Bridgmans table, see info for usage";
    Real dgu = alpha * v * v * p + alpha * v * s * T - v * cp - gamma * v * s * p "Coefficient in Bridgmans table, see info for usage";
    Real dug = -dgu "Coefficient in Bridgmans table, see info for usage";
    Real dfh = (s - v * alpha * p) * (v - v * alpha * T) - gamma * v * cp * p "Coefficient in Bridgmans table, see info for usage";
    Real dhf = -dfh "Coefficient in Bridgmans table, see info for usage";
    Real dgh = alpha * v * s * T - v * (s + cp) "Coefficient in Bridgmans table, see info for usage";
    Real dhg = -dgh "Coefficient in Bridgmans table, see info for usage";
    Real dfg = gamma * v * s * p - v * s - alpha * v * v * p "Coefficient in Bridgmans table, see info for usage";
    Real dgf = -dfg "Coefficient in Bridgmans table, see info for usage";

    annotation (Documentation(info = "<html>\n<p>\nImportant: the phase equilibrium conditions are not yet considered.\nthis means that Bridgman's tables do not yet work in the two phase region.\nSome derivatives are 0 or infinity anyways.\nIdea: Do not use the values in Bridgmans table directly, all\nderivatives are calculated as the quotient of two entries in the\ntable. The last letter indicates which variable is held constant in\ntaking the derivative. The second letters are the two variables\ninvolved in the derivative and the first letter is always a d to remind\nof differentiation.\n</p>\n\n<pre>\nExample 1: Get the derivative of specific entropy s w.r.t. Temperature at\nconstant specific volume (between identical to constant density)\nconstant volume  --> last letter v\nTemperature      --> second letter T\nSpecific entropy --> second letter s\n--> the needed value is dsv/dTv\nKnown variables:\nTemperature T\npressure p\nspecific volume v\nspecific inner energy u\nspecific enthalpy h\nspecific entropy s\nspecific Helmholtz energy f\nspecific gibbs enthalpy g\nNot included but useful:\ndensity d\nIn order to convert derivatives involving density use the following\nrules:\nat constant density == at constant specific volume\nddx/dyx = -d*d*dvx/dyx with y,x any of T,p,u,h,s,f,g\ndyx/ddx = -1/(d*d)dyx/dvx with y,x any of T,p,u,h,s,f,g\nUsage example assuming water as the medium:\nmodel BridgmansTablesForWater\nextends ThermoFluid.BaseClasses.MediumModels.Water.WaterSteamMedium_ph;\nReal derOfsByTAtConstantv \"derivative of sp. entropy by temperature at constant sp. volume\"\nThermoFluid.BaseClasses.MediumModels.Common.ExtraDerivatives dpro;\nThermoFluid.BaseClasses.MediumModels.Common.BridgmansTables bt;\nequation\ndpro = ThermoFluid.BaseClasses.MediumModels.SteamIF97.extraDerivs_pT(p[1],T[1]);\nbt.p = p[1];\nbt.T = T[1];\nbt.v = 1/pro[1].d;\nbt.s = pro[1].s;\nbt.cp = pro[1].cp;\nbt.alpha = dpro.alpha;\nbt.gamma = dpro.gamma;\nderOfsByTAtConstantv =  bt.dsv/bt.dTv;\n                ...\nend BridgmansTablesForWater;\n                </pre>\n\n                </html>"));
end BridgmansTables;