Changeset 352

Show
Ignore:
Timestamp:
02/21/2006 11:09:57 AM (3 years ago)
Author:
Hubertus
Message:

update to interface from meeting in Hamburg, 2006/01/21

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • Modelica/trunk/Media/IdealGases/Common/package.mo

    r340 r352  
    204204  end BaseProperties; 
    205205   
    206   function density "return density of ideal gas"  
    207     extends Modelica.Icons.Function; 
    208     input ThermodynamicState state "thermodynamic state"; 
    209     output Density d "density"; 
     206    redeclare function setState_pTX "Return thermodynamic state as function of p, T and composition X"  
     207      extends Modelica.Icons.Function; 
     208      input AbsolutePressure p "Pressure"; 
     209      input Temperature T "Temperature"; 
     210      input MassFraction X[:] = fill(0,0) "Mass fractions"; 
     211      output ThermodynamicState state; 
     212    algorithm 
     213      state := ThermodynamicState(p=p,T=T); 
     214    end setState_pTX; 
     215     
     216    redeclare function setState_phX "Return thermodynamic state as function of p, h and composition X"  
     217      extends Modelica.Icons.Function; 
     218      input AbsolutePressure p "Pressure"; 
     219      input SpecificEnthalpy h "Specific enthalpy"; 
     220      input MassFraction X[:] = fill(0,0) "Mass fractions"; 
     221      output ThermodynamicState state; 
     222    algorithm 
     223      state := ThermodynamicState(p=p,T=T_h(h)); 
     224    end setState_phX; 
     225     
     226    redeclare function setState_psX "Return thermodynamic state as function of p, s and composition X"  
     227      extends Modelica.Icons.Function; 
     228      input AbsolutePressure p "Pressure"; 
     229      input SpecificEntropy s "Specific entropy"; 
     230      input MassFraction X[:] = fill(0,0) "Mass fractions"; 
     231      output ThermodynamicState state; 
     232    algorithm 
     233      state := ThermodynamicState(p=p,T=T_ps(s,p)); 
     234    end setState_psX; 
     235     
     236    redeclare function setState_dTX "Return thermodynamic state as function of d, T and composition X"  
     237      extends Modelica.Icons.Function; 
     238      input Density d "density"; 
     239      input Temperature T "Temperature"; 
     240      input MassFraction X[:] = fill(0,0) "Mass fractions"; 
     241      output ThermodynamicState state; 
     242    algorithm 
     243      state := ThermodynamicState(p=d*data.R*T,T=T); 
     244    end setState_dTX; 
     245     
     246  redeclare function extends pressure "return pressure of ideal gas"  
     247  algorithm  
     248    p := state.p; 
     249  end pressure; 
     250 
     251  redeclare function extends temperature "return temperature of ideal gas"  
     252  algorithm  
     253    T := state.T; 
     254  end temperature; 
     255 
     256  redeclare function extends density "return density of ideal gas"  
    210257  algorithm  
    211258    d := state.p/(data.R*state.T); 
    212259  end density; 
    213260   
    214   redeclare function extends heatCapacity_cp  
    215     "Return specific heat capacity at constant pressure"  
    216   algorithm  
    217     cp := cp_T(data, state.T); 
    218   end heatCapacity_cp; 
    219    
    220   redeclare function extends heatCapacity_cv  
    221     "Compute specific heat capacity at constant volume from temperature and gas data"  
    222   algorithm  
    223     cv := cp_T(data, state.T) - data.R; 
    224   end heatCapacity_cv; 
    225    
    226   redeclare function extends isentropicExponent "Return isentropic exponent"  
    227   algorithm  
    228     gamma := heatCapacity_cp(state)/heatCapacity_cv(state); 
    229   end isentropicExponent; 
     261  redeclare function extends specificEnthalpy "Return specific enthalpy"  
     262    extends Modelica.Icons.Function; 
     263  algorithm  
     264    h := h_T(data,state.T); 
     265  end specificEnthalpy; 
     266   
     267  redeclare function extends specificInternalEnergy "Return specific internal energy"  
     268    extends Modelica.Icons.Function; 
     269  algorithm  
     270    u := h_T(data,state.T) - data.R*state.T; 
     271  end specificInternalEnergy; 
    230272   
    231273  redeclare function extends specificEntropy "Return specific entropy"  
     
    234276    s := s0_T(data, state.T) - data.R*Modelica.Math.log(state.p/reference_p); 
    235277  end specificEntropy; 
     278 
     279  redeclare function extends specificGibbsEnergy "Return specific Gibbs energy"  
     280    extends Modelica.Icons.Function; 
     281  algorithm  
     282    g := h_T(data,state.T) - state.T*specificEntropy(state); 
     283  end specificGibbsEnergy; 
     284   
     285  redeclare function extends specificHelmholtzEnergy "Return specific Helmholtz energy"  
     286    extends Modelica.Icons.Function; 
     287  algorithm  
     288    f := h_T(data,state.T) - data.R*state.T - state.T*specificEntropy(state); 
     289  end specificHelmholtzEnergy; 
     290   
     291  redeclare function extends specificHeatCapacityCp  
     292    "Return specific heat capacity at constant pressure"  
     293  algorithm  
     294    cp := cp_T(data, state.T); 
     295  end specificHeatCapacityCp; 
     296   
     297  redeclare function extends specificHeatCapacityCv  
     298    "Compute specific heat capacity at constant volume from temperature and gas data"  
     299  algorithm  
     300    cv := cp_T(data, state.T) - data.R; 
     301  end specificHeatCapacityCv; 
     302   
     303  redeclare function extends isentropicExponent "Return isentropic exponent"  
     304  algorithm  
     305    gamma := specificHeatCapacityCp(state)/specificHeatCapacityCv(state); 
     306  end isentropicExponent; 
    236307   
    237308  redeclare function extends velocityOfSound "Return velocity of sound"  
    238309    extends Modelica.Icons.Function; 
    239310  algorithm  
    240     a := sqrt(data.R*state.T*cp_T(data, state.T)/heatCapacity_cv(state)); 
     311    a := sqrt(data.R*state.T*cp_T(data, state.T)/specificHeatCapacityCv(state)); 
    241312  end velocityOfSound; 
    242313   
     
    570641    assert(fluidConstants[1].hasCriticalData, 
    571642    "Failed to compute thermalConductivity: For the species \"" + mediumName + "\" no critical data is available."); 
    572     lambda := thermalConductivityEstimate(heatCapacity_cp(state), 
     643    lambda := thermalConductivityEstimate(specificHeatCapacityCp(state), 
    573644      dynamicViscosity(state), method=method); 
    574645  end thermalConductivity; 
     
    579650  end molarMass; 
    580651   
    581   redeclare function extends specificEnthalpy_pTX  
    582     "Compute specific enthalpy from pressure, temperature and mass fractions"  
    583   algorithm  
    584     h := h_T(data,T); 
    585   end specificEnthalpy_pTX; 
    586    
    587   redeclare function extends temperature_phX  
    588     "Compute temperature from pressure, specific enthalpy and mass fraction"  
    589      
     652  function T_h "Compute temperature from specific enthalpy"      
     653    input SpecificEnthalpy h "Specific enthalpy"; 
     654    output Temperature T "Temperature"; 
    590655  protected  
    591656  package Internal  
     
    609674  algorithm  
    610675    T := Internal.solve(h, 200, 6000, 1.0e5, {1}, data); 
    611   end temperature_phX; 
    612    
    613   redeclare function extends temperature_psX  
    614     "Compute temperature from pressure, specific entropy and mass fraction"  
     676  end T_h; 
     677   
     678  function T_ps "Compute temperature from pressure and specific entropy"  
     679    input AbsolutePressure p "Pressure"; 
     680    input SpecificEntropy s "Specific entropy"; 
     681    output Temperature T "Temperature"; 
    615682  protected  
    616683  package Internal  
     
    634701  algorithm  
    635702    T := Internal.solve(s, 200, 6000, 1.0e5, {1}, data); 
    636   end temperature_psX; 
    637    
    638   redeclare function extends specificEnthalpy_psX  
    639   protected  
    640     Temperature T =  temperature_psX(p,s,X); 
    641   algorithm  
    642   end specificEnthalpy_psX; 
    643    
    644   redeclare function extends density_phX  
    645     "Compute density from pressure, specific enthalpy and mass fraction"  
    646   protected  
    647     Temperature T "temperature"; 
    648   algorithm  
    649     T := temperature_phX(p,h,X); 
    650     d := p/(data.R*T); 
    651   end density_phX; 
    652    
     703  end T_ps; 
     704 
    653705end SingleGasNasa; 
    654706 
     
    721773  equation  
    722774    assert(T >= 200 and T <= 6000, " 
    723 Temperature T (="   + String(T) + " K) is not in the allowed range 
     775Temperature T (="   + String(T) + " K = 200 K) is not in the allowed range 
    724776200 K <= T <= 6000 K 
    725777required from medium model \""   + mediumName + "\"."); 
    726778     
    727779    MM = molarMass(state); 
    728     h = h_TX(T, Xi); 
     780    h = h_TX(T, X); 
    729781    R = data.R*X; 
    730782    u = h - R*T; 
     
    733785    state.T = T; 
    734786    state.p = p; 
    735     state.X = if fixedX then reference_X else Xi; 
     787    state.X = if fixedX then reference_X else X; 
    736788  end BaseProperties; 
    737789   
    738 /*   
    739   redeclare replaceable model extends EquilibriumProperties 
    740     extends Interfaces.PartialMixtureMedium.BaseProperties 
    741       (MM(start = 0.04), 
    742        X(start = reference_X), 
    743        T(stateSelect=if preferredMediumStates then StateSelect.prefer else StateSelect.default),  
    744        p(stateSelect=if preferredMediumStates then StateSelect.prefer else StateSelect.default));  
    745     import Modelica.Media.IdealGases.Common.SingleGasNasa; 
    746     parameter MolarMass[nX] MMX=data[:].MM "molar masses of components"; 
    747     SpecificEnthalpy h_component[nX] "component specific enthalpy"; 
    748     SpecificEntropy[nX] s_component "component specific entropy"; 
    749     SI.MolarInternalEnergy[nX] g_formation "component Gibbs energy of formation, molar base!"; 
    750     Real p_red(start=1.0) "reduced pressure"; 
    751     parameter Integer n_reaction=size(nu, 1) "number of reactions"; 
    752     SI.MolarInternalEnergy[n_reaction] g_reaction "change of Gibbs energy due to reaction"; 
    753     Real[n_reaction] kr "reaction constants, computed via Gibbs energy"; 
    754     parameter Integer[n_reaction, nX] nu "stochiometry matrix (Evaluate true for removing zeros symbolically)"  
    755       annotation (Evaluate); 
    756     annotation (structurallyIncomplete); 
    757   equation  
    758     assert(T >= 200 and T <= 6000, " 
    759        Temperature T (= 200 K) is not in the allowed range 
    760        200 K <= T (= " + String(T) + " <= 6000 K 
    761        required from medium model \"" + mediumName + "\"."); 
    762      
    763     p_red = max(p/reference_p, 1e-6); 
    764     MM = molarMass(state); 
    765     h_component = {SingleGasNasa.h_T(data[i], T, excludeEnthalpyOfFormation,  
    766                          referenceChoice, h_offset) for i in 1:nX}; 
    767     s_component = {Common.SingleGasNasa.s0_T(data[i], T) - 
    768            data[i].R*Math.log(p_red) for i in 1:size(substanceNames, 1)};     
    769     g_formation = {(h_component[i] - T*s_component[i])*MMX[i] for i in 1:size(substanceNames, 1)}; 
    770     h = h_component*X; 
    771     R = data.R*X; 
    772     u = h - R*T; 
    773     p = d*R*T; 
    774     // connect state with BaseProperties 
    775     state.T = T; 
    776     state.p = p; 
    777     state.X = X; 
    778     // for a concrete example, a stochiometric matrix is missing 
    779     g_reaction = nu*g_formation; 
    780     kr = {-g_reaction[i]/(Modelica.Constants.R*T) for i in 1:n_reaction}; 
    781   end EquilibriumProperties; 
    782 */ 
    783    
    784   function h_TX "Return specific enthalpy"  
     790    redeclare function setState_pTX "Return thermodynamic state as function of p, T and composition X"  
     791      extends Modelica.Icons.Function; 
     792      input AbsolutePressure p "Pressure"; 
     793      input Temperature T "Temperature"; 
     794      input MassFraction X[:] "Mass fractions"; 
     795      output ThermodynamicState state; 
     796    algorithm 
     797      state := if size(X,1) == nX then ThermodynamicState(p=p,T=T, X=X) 
     798        else ThermodynamicState(p=p,T=T, X=cat(1,X,{1-sum(X)})); 
     799    end setState_pTX; 
     800     
     801    redeclare function setState_phX "Return thermodynamic state as function of p, h and composition X"  
     802      extends Modelica.Icons.Function; 
     803      input AbsolutePressure p "Pressure"; 
     804      input SpecificEnthalpy h "Specific enthalpy"; 
     805      input MassFraction X[:] "Mass fractions"; 
     806      output ThermodynamicState state; 
     807    algorithm 
     808      state := if size(X,1) == nX then ThermodynamicState(p=p,T=T_hX(h,X),X=X) 
     809        else ThermodynamicState(p=p,T=T_hX(h,X), X=cat(1,X,{1-sum(X)})); 
     810    end setState_phX; 
     811     
     812    redeclare function setState_psX "Return thermodynamic state as function of p, s and composition X"  
     813      extends Modelica.Icons.Function; 
     814      input AbsolutePressure p "Pressure"; 
     815      input SpecificEntropy s "Specific entropy"; 
     816      input MassFraction X[:] "Mass fractions"; 
     817      output ThermodynamicState state; 
     818    algorithm 
     819      state := if size(X,1) == nX then ThermodynamicState(p=p,T=T_psX(s,p,X),X=X) 
     820        else ThermodynamicState(p=p,T=T_psX(p,s,X), X=cat(1,X,{1-sum(X)}));         
     821    end setState_psX; 
     822     
     823    redeclare function setState_dTX "Return thermodynamic state as function of d, T and composition X"  
     824      extends Modelica.Icons.Function; 
     825      input Density d "density"; 
     826      input Temperature T "Temperature"; 
     827      input MassFraction X[:] "Mass fractions"; 
     828      output ThermodynamicState state; 
     829    algorithm 
     830      state := if size(X,1) == nX then ThermodynamicState(p=d*(data.R*X)*T,T=T,X=X) 
     831        else ThermodynamicState(p=d*(data.R*cat(1,X,{1-sum(X)}))*T,T=T, X=cat(1,X,{1-sum(X)})); 
     832    end setState_dTX; 
     833       
     834    redeclare function extends pressure "return pressure of ideal gas"  
     835      algorithm  
     836      p := state.p; 
     837    end pressure; 
     838 
     839    redeclare function extends temperature "return temperature of ideal gas"  
     840      algorithm  
     841      T := state.T; 
     842    end temperature; 
     843 
     844    redeclare function extends density "return density of ideal gas"  
     845      algorithm  
     846      d := state.p/((state.X*data.R)*state.T); 
     847    end density; 
     848   
     849  redeclare function extends specificEnthalpy "Return specific enthalpy"  
     850    extends Modelica.Icons.Function; 
     851  algorithm  
     852    h := h_TX(state.T,state.X); 
     853  end specificEnthalpy; 
     854   
     855  redeclare function extends specificInternalEnergy "Return specific internal energy"  
     856    extends Modelica.Icons.Function; 
     857  algorithm  
     858    u := h_TX(state.T,state.X) - gasConstant(state)*state.T; 
     859  end specificInternalEnergy; 
     860   
     861  redeclare function extends specificEntropy "Return specific entropy"  
     862    extends Modelica.Icons.Function; 
     863  algorithm  
     864    s := s_TX(state.T, state.X) - gasConstant(state)*Modelica.Math.log(state.p/reference_p); 
     865  end specificEntropy; 
     866 
     867  redeclare function extends specificGibbsEnergy "Return specific Gibbs energy"  
     868    extends Modelica.Icons.Function; 
     869  algorithm  
     870    g := h_TX(state.T,state.X) - state.T*specificEntropy(state); 
     871  end specificGibbsEnergy; 
     872   
     873  redeclare function extends specificHelmholtzEnergy "Return specific Helmholtz energy"  
     874    extends Modelica.Icons.Function; 
     875  algorithm  
     876    f := h_TX(state.T,state.X) - gasConstant(state)*state.T - state.T*specificEntropy(state); 
     877  end specificHelmholtzEnergy; 
     878   
     879  function h_TX "Return specific enthalpy (requires full X-vector)"  
    785880    import Modelica.Media.Interfaces.PartialMedium.Choices; 
    786881     extends Modelica.Icons.Function; 
    787882     input SI.Temperature T "Temperature"; 
    788      input MassFraction Xi[nXi] "Independent Mass fractions of gas mixture"; 
     883     input MassFraction X[nX] "Independent Mass fractions of gas mixture"; 
    789884     input Boolean exclEnthForm=excludeEnthalpyOfFormation  
    790885      "If true, enthalpy of formation Hf is not included in specific enthalpy h"; 
     
    800895      //                            zeroDerivative=h_off) = h_TX_der); 
    801896  algorithm  
    802       h :=(if fixedX then reference_X else Xi)* 
     897    h :=(if fixedX then reference_X else X)* 
    803898         {SingleGasNasa.h_T(data[i], T, exclEnthForm, refChoice, h_off) for i in 1:nX}; 
    804899  end h_TX; 
     
    808903     extends Modelica.Icons.Function; 
    809904     input SI.Temperature T "Temperature"; 
    810      input MassFraction Xi[nXi] "Independent Mass fractions of gas mixture"; 
     905     input MassFraction X[nX] "Independent Mass fractions of gas mixture"; 
    811906     input Boolean exclEnthForm=excludeEnthalpyOfFormation  
    812907      "If true, enthalpy of formation Hf is not included in specific enthalpy h"; 
     
    816911      "User defined offset for reference enthalpy, if referenceChoice = UserDefined"; 
    817912    input Real dT "Temperature derivative"; 
    818     input Real dXi[nXi] "independent mass fraction derivative"; 
     913    input Real dXi[nX] "independent mass fraction derivative"; 
    819914    output Real h_der "Specific enthalpy at temperature T"; 
    820915    annotation (InlineNoEvent=false, Inline = false); 
    821916  algorithm  
    822     assert(reducedX == false, "reducedX = true is not supported"); 
    823917    h_der := if fixedX then  
    824918      dT*sum((SingleGasNasa.cp_T(data[i], T)*reference_X[i]) for i in 1:nX) else  
    825       dT*sum((SingleGasNasa.cp_T(data[i], T)*Xi[i]) for i in 1:nX)+ 
    826       sum((SingleGasNasa.h_T(data[i], T)*dXi[i]) for i in 1:nX); 
     919      dT*sum((SingleGasNasa.cp_T(data[i], T)*X[i]) for i in 1:nX)+ 
     920      sum((SingleGasNasa.h_T(data[i], T)*dX[i]) for i in 1:nX); 
    827921  end h_TX_der; 
    828922   
    829   redeclare function extends gasConstant "compute gasConstant"  
    830   algorithm  
    831     R := if (not reducedX) then  
    832       sum(data[i].R*state.X[i] for i in 1:size(substanceNames, 1)) else  
    833       sum(data[i].R*state.X[i] for i in 1:size(substanceNames, 1)-1) + data[end].R*(1-sum(state.X[i])); 
     923  redeclare function extends gasConstant "compute gasConstant" 
     924  algorithm  
     925    R := data.R*state.X; 
    834926  end gasConstant; 
    835    
    836   function density "return density of ideal gas"  
    837     extends Modelica.Icons.Function; 
    838     input ThermodynamicState state "thermodynamic state"; 
    839     output Density d "density"; 
    840   algorithm  
    841     d := state.p/(gasConstant(state)*state.T); 
    842   end density; 
    843    
    844   redeclare function extends heatCapacity_cp  
     927     
     928  redeclare function extends specificHeatCapacityCp  
    845929    "Return specific heat capacity at constant pressure"  
    846   algorithm  
    847     cp := 0; 
    848     for i in 1:size(data,1) loop 
    849       cp:=cp+SingleGasNasa.cp_T(data[i], state.T)*state.X[i]; 
    850     end for; 
    851   end heatCapacity_cp; 
    852    
    853   redeclare function extends heatCapacity_cv  
     930  algorithm 
     931    cp := SingleGasNasa.cp_T(data, state.T)*state.X; 
     932  end specificHeatCapacityCp; 
     933   
     934  redeclare function extends specificHeatCapacityCv  
    854935    "Compute specific heat capacity at constant volume from temperature and gas data"  
    855936  algorithm  
    856     cv := 0; 
    857     for i in 1:size(data,1) loop 
    858       cv:=cv+(SingleGasNasa.cp_T(data[i], state.T)-data[i].R)*state.X[i]; 
    859     end for; 
    860   end heatCapacity_cv; 
     937    cv := SingleGasNasa.cp_T(data, state.T)*state.X -data.R*state.X; 
     938  end specificHeatCapacityCv; 
    861939   
    862940  function MixEntropy "calculate the mixing entropy of ideal gases / R"  
     
    865943    output Real smix "mixing entropy contribution, divided by gas constant"; 
    866944  algorithm  
    867     smix := sum(if x[i] > Modelica.Constants.eps then -x[i]*Modelica.Math.log(x[i]) else  
    868                     x[i] for i in 1:size(x,1)); 
     945    smix := sum(if x[i] > Modelica.Constants.eps then -x[i]*Modelica.Math.log(x[i]) 
     946                else x[i] for i in 1:size(x,1)); 
    869947  end MixEntropy; 
    870948   
    871   function s_TX "temperature dependent part of the entropy"  
     949  function s_TX "temperature dependent part of the entropy, expects full entropy vector" 
    872950    input Temperature T "temperature"; 
    873     input MassFraction[:] X "mass fraction"; 
     951    input MassFraction[nX] X "mass fraction"; 
    874952    output SpecificEntropy s "specific entropy"; 
    875   algorithm  
    876     s := sum(SingleGasNasa.s0_T(data[i], T)*X[i] for i in 1:nS); 
     953  algorithm 
     954    s := SingleGasNasa.s0_T(data, T)*X "automatic vectorization due to data"; 
    877955  end s_TX; 
    878    
    879   redeclare function extends specificEntropy "Return specific entropy"  
    880   protected  
    881     MassFraction[nS] X "complete X-vector"; 
    882   algorithm  
    883     X := if reducedX then cat(1,state.X,{1-sum(state.X)}) else state.X; 
    884     s := s_TX(state.T,X) - (data.R*X)*(Modelica.Math.log(state.p/reference_p)) 
    885       + MixEntropy(massToMoleFractions(X,data[:].MM)); 
    886   end specificEntropy; 
    887    
     956 
    888957  redeclare function extends isentropicExponent "Return isentropic exponent"  
    889958  algorithm  
    890     gamma := heatCapacity_cp(state)/heatCapacity_cv(state); 
     959    gamma := specificHeatCapacityCp(state)/specificHeatCapacityCv(state); 
    891960  end isentropicExponent; 
    892961   
     
    895964    input ThermodynamicState state "properties at upstream location"; 
    896965  algorithm  
    897     a := sqrt(gasConstant(state)*state.T*heatCapacity_cp(state)/heatCapacity_cv(state)); 
     966    a := sqrt(gasConstant(state)*state.T*specificHeatCapacityCp(state)/specificHeatCapacityCv(state)); 
    898967  end velocityOfSound; 
    899968   
     
    908977    SpecificEnthalpy h_component[nX] "specific enthalpy at upstream location"; 
    909978    IsentropicExponent gamma =  isentropicExponent(state) "Isentropic exponent"; 
    910   algorithm  
     979  protected 
     980    MassFraction[nX] X "complete X-vector"; 
     981  algorithm  
     982    X := if reducedX then cat(1,state.X,{1-sum(state.X)}) else state.X; 
    911983    h_component :={SingleGasNasa.h_T(data[i], state.T, excludeEnthalpyOfFormation, 
    912984      referenceChoice, h_offset) for i in 1:nX}; 
    913     h :=h_component*state.X; 
     985    h :=h_component*X; 
    914986    h_is := h + gamma/(gamma - 1.0)*(state.T*gasConstant(state))* 
    915987      ((p2/state.p)^((gamma - 1)/gamma) - 1.0); 
     
    917989   
    918990  redeclare function extends isentropicEnthalpy "Return isentropic enthalpy"  
    919   algorithm  
    920     h_is := isentropicEnthalpyApproximation(p_downstream,refState); 
     991    input Boolean exact = false "flag wether exact or approximate version should be used"; 
     992  algorithm  
     993    h_is := if exact then specificEnthalpy_psX(p_downstream,specificEntropy(refState),refstate.X) 
     994      else isentropicEnthalpyApproximation(p_downstream,refState); 
    921995  end isentropicEnthalpy; 
    922996   
     
    13391413  end molarMass; 
    13401414   
    1341   redeclare function extends specificEnthalpy_pTX  
    1342     "Compute specific enthalpy from pressure, temperature and mass fractions"  
    1343   algorithm  
    1344     h := h_TX(T,X[1:nXi]); 
    1345   end specificEnthalpy_pTX; 
    1346    
    1347   redeclare function extends temperature_phX  
    1348     "Compute temperature from pressure, specific enthalpy and mass fraction"  
    1349      
     1415  function T_hX  
     1416    "Compute temperature from specific enthalpy and mass fraction"  
     1417    input SpecificEnthalpy h "specific enthalpy"; 
     1418    input MassFraction[:] X "mass fractions of composition"; 
     1419    output Temperature T "temperature"; 
    13501420  protected  
    13511421  package Internal  
     
    13681438     
    13691439  algorithm  
    1370     T := Internal.solve(h, 200, 6000, p, X[1:nXi], data[1]); 
    1371   end temperature_phX; 
    1372    
    1373   redeclare function extends temperature_psX  
     1440    T := Internal.solve(h, 200, 6000, 1.0e5, X[1:nXi], data[1]); 
     1441  end T_hX; 
     1442   
     1443  function T_psX  
    13741444    "Compute temperature from pressure, specific entropy and mass fraction"  
    1375   protected  
     1445    input AbsolutePressure p "pressure"; 
     1446    input SpecificEntropy s "specific entropy"; 
     1447    input MassFraction[:] X "mass fractions of composition"; 
     1448    output Temperature T "temperature"; 
     1449  protected 
     1450    MassFraction[nX] Xfull = if size(X,1) == nX then X else cat(1,X,{1-sum(X)});  
    13761451  package Internal  
    13771452      "Solve h(data,T) for T with given h (use only indirectly via temperature_phX)"  
     
    13821457    end f_nonlinear_Data; 
    13831458       
    1384     redeclare function extends f_nonlinear  
    1385       protected  
    1386       MassFraction[nS] Xf "complete X-vector"; 
     1459    redeclare function extends f_nonlinear "note that this function always sees the complete mass fraction vector" 
    13871460    algorithm  
    1388       Xf := if reducedX then cat(1,X,{1-sum(X)}) else X; 
    1389       y := s_TX(x,Xf)- data.R*Xf*Modelica.Math.log(p/reference_p) 
    1390         + MixEntropy(massToMoleFractions(Xf,data[:].MM)); 
     1461      y := s_TX(x,X)- data.R*X*Modelica.Math.log(p/reference_p) 
     1462        + MixEntropy(massToMoleFractions(X,data[:].MM)); 
    13911463    end f_nonlinear; 
    13921464       
     
    13971469     
    13981470  algorithm  
    1399     T := Internal.solve(s, 200, 6000, 1.0e5, {1}, data[1]); 
    1400   end temperature_psX; 
    1401    
    1402   redeclare function extends specificEnthalpy_psX  
    1403   protected  
    1404     Temperature T "temperature"; 
    1405   algorithm  
    1406     T := temperature_psX(p,s,X); 
    1407     h := specificEnthalpy_pTX(p,T,X); 
    1408   end specificEnthalpy_psX; 
    1409    
    1410   redeclare function extends density_phX  
    1411     "Compute density from pressure, specific enthalpy and mass fraction"  
    1412   protected  
    1413     Temperature T "temperature"; 
    1414     SpecificHeatCapacity R "gas constant"; 
    1415   algorithm  
    1416     T := temperature_phX(p,h,X); 
    1417     R := if (not reducedX) then  
    1418       sum(data[i].R*X[i] for i in 1:size(substanceNames, 1)) else  
    1419       sum(data[i].R*X[i] for i in 1:size(substanceNames, 1)-1) + data[end].R*(1-sum(X[i])); 
    1420     d := p/(R*T); 
    1421   end density_phX; 
     1471    T := Internal.solve(s, 200, 6000, p, Xfull, data[1]); 
     1472  end T_psX; 
     1473   
     1474 
     1475//   redeclare function extends specificEnthalpy_psX 
     1476//   protected 
     1477//     Temperature T "temperature"; 
     1478//   algorithm 
     1479//     T := temperature_psX(p,s,X); 
     1480//     h := specificEnthalpy_pTX(p,T,X); 
     1481//   end extends; 
     1482   
     1483       
     1484//   redeclare function extends density_phX  
     1485//     "Compute density from pressure, specific enthalpy and mass fraction"  
     1486//     protected 
     1487//     Temperature T "temperature"; 
     1488//     SpecificHeatCapacity R "gas constant";  
     1489//   algorithm  
     1490//     T := temperature_phX(p,h,X); 
     1491//     R := if (not reducedX) then 
     1492//       sum(data[i].R*X[i] for i in 1:size(substanceNames, 1)) else 
     1493//       sum(data[i].R*X[i] for i in 1:size(substanceNames, 1)-1) + data[end].R*(1-sum(X[i]));  
     1494//     d := p/(R*T); 
     1495//   end density_phX; 
     1496   
    14221497   
    14231498end MixtureGasNasa;