diff -ur "/home/hudson/saved_omc/libraries/.openmodelica/libraries/ThermoPower 3.1.0-master/Examples.mo" "converted-libraries/.openmodelica/libraries/ThermoPower 3.1.0-master/Examples.mo"
--- "/home/hudson/saved_omc/libraries/.openmodelica/libraries/ThermoPower 3.1.0-master/Examples.mo"	2022-03-10 09:57:37.952144121 +0000
+++ "converted-libraries/.openmodelica/libraries/ThermoPower 3.1.0-master/Examples.mo"	2022-03-10 09:59:05.900155259 +0000
@@ -859,7 +859,7 @@
         Models.CISEPlant Plant
           annotation (Placement(transformation(extent={{120,-40},{180,20}})));
       initial equation
-        // Additional equations to determine the non-fixed parameters
+// Additional equations to determine the non-fixed parameters
         Plant.Drum.y = InitialDrumLevel;
         Plant.Drum.p = InitialDrumPressure;
 
@@ -1029,7 +1029,7 @@
         connect(sum_1.y, wfeed.u3) annotation (Line(points={{-59,-20},{-46,-20},{
                 -46,2},{-22,2}}, color={0,0,127}));
       initial equation
-        // Additional equations to determine the non-fixed parameters
+// Additional equations to determine the non-fixed parameters
         Plant.DrumLevel = InitialDrumLevel;
         Plant.DrumPressure = InitialDrumPressure;
 
@@ -1351,7 +1351,7 @@
     extends Modelica.Icons.ExamplesPackage;
 
     package Models
-      extends Modelica.Icons.Library;
+      extends Modelica.Icons.Package;
       model HeatExchanger "Base class for heat exchanger fluid - gas"
         constant Real pi=Modelica.Constants.pi;
         replaceable package GasMedium =
@@ -1517,7 +1517,7 @@
 
         parameter Integer N=2 "Number of node of the gas side";
 
-        //Nominal parameter
+//Nominal parameter
         parameter SI.MassFlowRate gasNomFlowRate
           "Nominal flow rate through the gas side";
         parameter SI.MassFlowRate fluidNomFlowRate
@@ -1527,7 +1527,7 @@
         parameter SI.Pressure fluidNomPressure
           "Nominal pressure in the fluid side inlet";
 
-        //Physical Parameter
+//Physical Parameter
         parameter SI.Area exchSurface
           "Exchange surface between gas - metal tube";
         parameter SI.Volume gasVol "Gas volume";
@@ -1537,7 +1537,7 @@
         parameter SI.SpecificHeatCapacity cm
           "Specific heat capacity of the metal";
 
-        //Start value
+//Start value
         parameter SI.Temperature Tstart "Average gas temperature start value"
           annotation (Dialog(tab="Initialization"));
         parameter SI.CoefficientOfHeatTransfer gamma
@@ -1849,7 +1849,7 @@
       model DigitalPI
         extends Modelica.Blocks.Interfaces.DiscreteBlock;
         parameter Real Kp "Gain";
-        parameter Modelica.SIunits.Time Ti(min=0) "Integral time";
+        parameter Modelica.Units.SI.Time Ti(min=0) "Integral time";
         parameter Real b(min=0) = 1 "Set-point weight (proportional action)";
         parameter Real CSmax "Control signal saturation upper bound";
         parameter Real CSmin "Control signal saturation lower bound";
@@ -2029,9 +2029,9 @@
       model OpenLoopSimulatorHtc
         "Open-loop plant simulator with parameter computation"
         extends OpenLoopSimulatorSS(Plant(Boiler(gamma_nom = gamma_unknown)));
-        parameter Modelica.SIunits.CoefficientOfHeatTransfer gamma_unknown(fixed = false, start = 150);
+        parameter Modelica.Units.SI.CoefficientOfHeatTransfer gamma_unknown(fixed = false, start = 150);
       initial equation
-        Plant.GasOut.T = Modelica.SIunits.Conversions.from_degC(130);
+        Plant.GasOut.T = Modelica.Units.Conversions.from_degC(130);
         annotation (Documentation(revisions="<html>
 <ul>
 <li><i>20 Sep 2013</i>
@@ -2222,7 +2222,7 @@
             redeclare package GasMedium =
                 Modelica.Media.IdealGases.MixtureGases.CombustionAir (
                  fixedX=true)));
-            //redeclare package WaterMedium = Media.LiquidWaterConstant,
+            //redeclare package WaterMedium = Media.LiquidWaterConstant,
         annotation (experiment(
             StopTime=300,
             Tolerance=1e-006,
@@ -2308,7 +2308,7 @@
         parameter Integer N_G=2 "Number of node of the gas side";
         parameter Integer N_F=2 "Number of node of the fluid side";
 
-        //Nominal parameter
+//Nominal parameter
         parameter SI.MassFlowRate gasNomFlowRate
           "Nominal flow rate through the gas side";
         parameter SI.MassFlowRate fluidNomFlowRate
@@ -2318,7 +2318,7 @@
         parameter SI.Pressure fluidNomPressure
           "Nominal pressure in the fluid side inlet";
 
-        //Physical Parameter
+//Physical Parameter
         parameter SI.Area exchSurface_G
           "Exchange surface between gas - metal tube";
         parameter SI.Area exchSurface_F
@@ -2331,8 +2331,7 @@
         parameter SI.ThermalConductivity lambda
           "Thermal conductivity of the metal (density by specific heat capacity)";
 
-        //Start values
-
+//Start values
         parameter SI.Temperature Tstart_G "Average gas temperature start value"
           annotation (Dialog(tab="Initialization"));
         parameter SI.Temperature Tstart_M
@@ -2489,19 +2488,19 @@
       model PrescribedSpeedPump "Prescribed speed pump"
         replaceable package FluidMedium =
             Modelica.Media.Interfaces.PartialTwoPhaseMedium;
-        parameter Modelica.SIunits.VolumeFlowRate q_nom[3]
+        parameter Modelica.Units.SI.VolumeFlowRate q_nom[3]
           "Nominal volume flow rates";
-        parameter Modelica.SIunits.Height head_nom[3] "Nominal heads";
-        parameter Modelica.SIunits.Density rho0 "Nominal density";
-        parameter Modelica.SIunits.Conversions.NonSIunits.AngularVelocity_rpm n0
+        parameter Modelica.Units.SI.Height head_nom[3] "Nominal heads";
+        parameter Modelica.Units.SI.Density rho0 "Nominal density";
+        parameter Modelica.Units.NonSI.AngularVelocity_rpm n0
           "Nominal rpm";
-        parameter Modelica.SIunits.Pressure nominalOutletPressure
+        parameter Modelica.Units.SI.Pressure nominalOutletPressure
           "Nominal live steam pressure";
-        parameter Modelica.SIunits.Pressure nominalInletPressure
+        parameter Modelica.Units.SI.Pressure nominalInletPressure
           "Nominal condensation pressure";
-        parameter Modelica.SIunits.MassFlowRate nominalMassFlowRate
+        parameter Modelica.Units.SI.MassFlowRate nominalMassFlowRate
           "Nominal steam mass flow rate";
-        parameter Modelica.SIunits.SpecificEnthalpy hstart=1e5
+        parameter Modelica.Units.SI.SpecificEnthalpy hstart=1e5
           "Fluid Specific Enthalpy Start Value";
         parameter Boolean SSInit=false "Steady-state initialization";
 
@@ -2572,10 +2571,10 @@
         replaceable package Medium = Water.StandardWater constrainedby
           Modelica.Media.Interfaces.PartialMedium "Medium model";
         //Parameters
-        parameter Modelica.SIunits.Pressure p "Nominal inlet pressure";
-        parameter Modelica.SIunits.Volume Vtot=10
+        parameter Modelica.Units.SI.Pressure p "Nominal inlet pressure";
+        parameter Modelica.Units.SI.Volume Vtot=10
           "Total volume of the fluid side";
-        parameter Modelica.SIunits.Volume Vlstart=0.15*Vtot
+        parameter Modelica.Units.SI.Volume Vlstart=0.15*Vtot
           "Start value of the liquid water volume"
           annotation (Dialog(tab="Initialisation"));
         parameter Choices.Init.Options initOpt=system.initOpt
@@ -2586,20 +2585,20 @@
 
 
         //Variables
-        Modelica.SIunits.Density rhol "Density of saturated liquid";
-        Modelica.SIunits.Density rhov "Density of saturated steam";
+        Modelica.Units.SI.Density rhol "Density of saturated liquid";
+        Modelica.Units.SI.Density rhov "Density of saturated steam";
         Medium.SaturationProperties sat "Saturation properties";
         Medium.SpecificEnthalpy hl "Specific enthalpy of saturated liquid";
         Medium.SpecificEnthalpy hv "Specific enthalpy of saturated vapour";
-        Modelica.SIunits.Mass M "Total mass, steam+liquid";
-        Modelica.SIunits.Mass Ml "Liquid mass";
-        Modelica.SIunits.Mass Mv "Steam mass";
-        Modelica.SIunits.Volume Vl(start=Vlstart) "Liquid volume";
-        Modelica.SIunits.Volume Vv "Steam volume";
-        Modelica.SIunits.Energy E "Internal energy";
-        Modelica.SIunits.Power Q "Thermal power";
+        Modelica.Units.SI.Mass M "Total mass, steam+liquid";
+        Modelica.Units.SI.Mass Ml "Liquid mass";
+        Modelica.Units.SI.Mass Mv "Steam mass";
+        Modelica.Units.SI.Volume Vl(start=Vlstart) "Liquid volume";
+        Modelica.Units.SI.Volume Vv "Steam volume";
+        Modelica.Units.SI.Energy E "Internal energy";
+        Modelica.Units.SI.Power Q "Thermal power";
 
-        //Connectors
+//Connectors
         Water.FlangeA steamIn(redeclare package Medium = Medium) annotation (
             Placement(transformation(extent={{-20,80},{20,120}}, rotation=0)));
         Water.FlangeB waterOut(redeclare package Medium = Medium) annotation (
@@ -2622,14 +2621,13 @@
         Vtot = Vv + Vl;
         M = Ml + Mv;
         E = Ml*hl + Mv*inStream(steamIn.h_outflow) - p*Vtot;
-
-        //Energy and Mass Balances
+//Energy and Mass Balances
         der(M) = steamIn.m_flow + waterOut.m_flow;
         der(E) = steamIn.m_flow*hv + waterOut.m_flow*hl - Q;
 
       initial equation
         if initOpt == Choices.Init.Options.noInit then
-          // do nothing
+// do nothing
         elseif initOpt == Choices.Init.Options.fixedState then
           Vl = Vlstart;
         elseif initOpt == Choices.Init.Options.steadyState then
@@ -3056,13 +3054,13 @@
             Placement(transformation(extent={{88,-12},{112,12}}, rotation=0)));
         Modelica.Blocks.Interfaces.RealInput SP "Set point signal" annotation (
             Placement(transformation(extent={{-112,28},{-88,52}}, rotation=0)));
-      equation
-        // Scaling
-        SPs = (SP - PVmin)/(PVmax - PVmin);
+      equation
+// Scaling
+        SPs = (SP - PVmin) / (PVmax - PVmin);
         PVs = (PV - PVmin)/(PVmax - PVmin);
-        CS = CSmin + CSs*(CSmax - CSmin);
-        // Controller actions
-        P = b*SPs - PVs;
+        CS = CSmin + CSs*(CSmax - CSmin);
+// Controller actions
+        P = b * SPs - PVs;
         if integralAction then
           assert(Ti>0, "Integral time must be positive");
           Ti*der(I) = SPs - PVs + track;
diff -ur "/home/hudson/saved_omc/libraries/.openmodelica/libraries/ThermoPower 3.1.0-master/Gas.mo" "converted-libraries/.openmodelica/libraries/ThermoPower 3.1.0-master/Gas.mo"
--- "/home/hudson/saved_omc/libraries/.openmodelica/libraries/ThermoPower 3.1.0-master/Gas.mo"	2022-03-10 09:57:37.952144121 +0000
+++ "converted-libraries/.openmodelica/libraries/ThermoPower 3.1.0-master/Gas.mo"	2022-03-10 09:59:04.980155144 +0000
@@ -118,8 +118,7 @@
 
     flange.h_outflow = gas.h;
     flange.Xi_outflow = gas.Xi;
-
-    // Connect protected connectors to public conditional connectors
+// Connect protected connectors to public conditional connectors
     connect(in_p0, in_p0_internal);
     connect(in_T, in_T_internal);
     connect(in_X, in_X_internal);
@@ -216,8 +215,7 @@
 
     flange.h_outflow = gas.h;
     flange.Xi_outflow = gas.Xi;
-
-    // Connect protected connectors to public conditional connectors
+// Connect protected connectors to public conditional connectors
     connect(in_p0, in_p0_internal);
     connect(in_T, in_T_internal);
     connect(in_X, in_X_internal);
@@ -318,8 +316,7 @@
     flange.p = gas.p;
     flange.h_outflow = gas.h;
     flange.Xi_outflow = gas.Xi;
-
-    // Connect protected connectors to public conditional connectors
+// Connect protected connectors to public conditional connectors
     connect(in_w0, in_w0_internal);
     connect(in_T, in_T_internal);
     connect(in_X, in_X_internal);
@@ -419,8 +416,7 @@
     flange.p = gas.p;
     flange.h_outflow = gas.h;
     flange.Xi_outflow = gas.Xi;
-
-    // Connect protected connectors to public conditional connectors
+// Connect protected connectors to public conditional connectors
     connect(in_w0, in_w0_internal);
     connect(in_T, in_T_internal);
     connect(in_X, in_X_internal);
@@ -480,17 +476,14 @@
     w = in_w0_internal;
     if not use_in_w0 then
       in_w0_internal = w0 "Flow rate set by parameter";
-    end if;
-
-    // Energy and partial mass balance
+    end if;
+// Energy and partial mass balance
     inlet.h_outflow = inStream(outlet.h_outflow);
     inStream(inlet.h_outflow) = outlet.h_outflow;
     inlet.Xi_outflow = inStream(outlet.Xi_outflow);
-    inStream(inlet.Xi_outflow) = outlet.Xi_outflow;
-
-    // Connect protected connectors to public conditional connectors
+    inStream(inlet.Xi_outflow) = outlet.Xi_outflow;
+// Connect protected connectors to public conditional connectors
     connect(in_w0, in_w0_internal);
-
     annotation (Documentation(info="<html>
 <p><b>Modelling options</b></p>
 <p>The actual gas used in the component is determined by the replaceable <tt>Medium</tt> package. In the case of multiple component, variable composition gases, the nominal gas composition is given by <tt>Xnom</tt>,whose default value is <tt>Medium.reference_X</tt> .
@@ -565,8 +558,7 @@
       M*der(gas.Xi[j]) = inlet.m_flow*(Xi_i[j] - gas.Xi[j]) + outlet.m_flow*(
         Xi_o[j] - gas.Xi[j]) "Independent component mass balance";
     end for;
-
-    // Boundary conditions
+// Boundary conditions
     hi = homotopy(if not allowFlowReversal then inStream(inlet.h_outflow) else
       actualStream(inlet.h_outflow), inStream(inlet.h_outflow));
     Xi_i = homotopy(if not allowFlowReversal then inStream(inlet.Xi_outflow)
@@ -586,9 +578,9 @@
     Tr = noEvent(M/max(abs(-outlet.m_flow), Modelica.Constants.eps))
       "Residence time";
   initial equation
-    // Initial conditions
+// Initial conditions
     if initOpt == Choices.Init.Options.noInit then
-      // do nothing
+// do nothing
     elseif initOpt == Choices.Init.Options.fixedState then
       if not noInitialPressure then
         gas.p = pstart;
@@ -701,8 +693,7 @@
     else
       Tm = gas.T;
     end if;
-
-    // Boundary conditions
+// Boundary conditions
     hi = homotopy(if not allowFlowReversal then inStream(inlet.h_outflow) else
       actualStream(inlet.h_outflow), inStream(inlet.h_outflow));
     Xi_i = homotopy(if not allowFlowReversal then inStream(inlet.Xi_outflow)
@@ -722,9 +713,9 @@
     Tr = noEvent(M/max(abs(-outlet.m_flow), Modelica.Constants.eps))
       "Residence time";
   initial equation
-    // Initial conditions
+// Initial conditions
     if initOpt == Choices.Init.Options.noInit then
-      // do nothing
+// do nothing
     elseif initOpt == Choices.Init.Options.fixedState then
       if not noInitialPressure then
         gas.p = pstart;
@@ -855,8 +846,7 @@
     else
       Tm = gas.T;
     end if;
-
-    // Boundary conditions
+// Boundary conditions
     hi1 = homotopy(if not allowFlowReversal then inStream(in1.h_outflow) else
       actualStream(in1.h_outflow), inStream(in1.h_outflow));
     Xi1 = homotopy(if not allowFlowReversal then inStream(in1.Xi_outflow) else
@@ -883,9 +873,9 @@
     Tr = noEvent(M/max(abs(-out.m_flow), Modelica.Constants.eps))
       "Residence time";
   initial equation
-    // Initial conditions
+// Initial conditions
     if initOpt == Choices.Init.Options.noInit then
-      // do nothing
+// do nothing
     elseif initOpt == Choices.Init.Options.fixedState then
       if not noInitialPressure then
         gas.p = pstart;
@@ -1016,10 +1006,10 @@
     Real dddX[N, nX](each unit="kg/m3") "Derivative of density by composition";
   equation
     assert(FFtype == ThermoPower.Choices.Flow1D.FFtypes.NoFriction or dpnom > 0,
-      "dpnom=0 not supported, it is also used in the homotopy trasformation during the inizialization");
-    //All equations are referred to a single tube
-    // Friction factor selection
-    omega_hyd = 4*A/Dhyd;
+      "dpnom=0 not supported, it is also used in the homotopy trasformation during the inizialization");
+//All equations are referred to a single tube
+// Friction factor selection
+    omega_hyd = 4 * A / Dhyd;
     if FFtype == ThermoPower.Choices.Flow1D.FFtypes.Kfnom then
       Kf = Kfnom*Kfc;
       Cf = 2*Kf*A^3/(omega_hyd*L);
@@ -1045,9 +1035,8 @@
       Kf = 0;
     end if;
     assert(Kf >= 0, "Negative friction coefficient");
-    Kfl = wnom/Nt*wnf*Kf "Linear friction factor";
-
-    // Dynamic momentum term
+    Kfl = wnom/Nt*wnf*Kf "Linear friction factor";
+// Dynamic momentum term
     dwdt = if DynamicMomentum and not QuasiStatic then der(w) else 0;
 
     sum(dMdt) = (infl.m_flow + outfl.m_flow)/Nt "Mass balance";
@@ -1055,65 +1044,61 @@
     Dpfric = (if FFtype == ThermoPower.Choices.Flow1D.FFtypes.NoFriction then 0
               else homotopy((smooth(1, Kf*squareReg(w, wnom/Nt*wnf))*sum(vbar)/(N - 1)),
                              dpnom/(wnom/Nt)*w))
-      "Pressure drop due to friction";
-    for j in 1:N - 1 loop
-      if not QuasiStatic then
-        // Dynamic mass and energy balances
-        A*l*rhobar[j]*cvbar[j]*der(Ttilde[j]) + wbar[j]*(gas[j + 1].h - gas[j].h)
-          = Q_single[j] "Energy balance";
-        dMdt[j] = A*l*(drbdp[j]*der(p) + drbdT1[j]*der(gas[j].T) + drbdT2[j]*
-          der(gas[j + 1].T) + vector(drbdX1[j, :])*vector(der(gas[j].X)) +
-          vector(drbdX2[j, :])*vector(der(gas[j + 1].X))) "Mass balance";
-        /*
+      "Pressure drop due to friction";
+  for j in 1:N - 1 loop
+      if not QuasiStatic then
+// Dynamic mass and energy balances
+        A * l * rhobar[j] * cvbar[j] * der(Ttilde[j]) + wbar[j] * (gas[j + 1].h - gas[j].h) = Q_single[j] "Energy balance";
+        dMdt[j] = A * l * (drbdp[j] * der(p) + drbdT1[j] * der(gas[j].T) + drbdT2[j] * der(gas[j + 1].T) + vector(drbdX1[j, :]) * vector(der(gas[j].X)) + vector(drbdX2[j, :]) * vector(der(gas[j + 1].X))) "Mass balance";
+/*
       dMdt[j] = A*l*(drbdT[j]*der(Ttilde[j]) + drbdp[j]*der(p) + vector(drbdX[j, :])*
       vector(der(Xtilde[if UniformComposition then 1 else j, :])))
       "Mass balance";
-*/
-        // Average volume quantities
-        if avoidInletEnthalpyDerivative and j == 1 then
-          // first volume properties computed by the volume outlet properties
-          rhobar[j] = gas[j + 1].d;
-          drbdp[j] = dddp[j + 1];
-          drbdT1[j] = 0;
-          drbdT2[j] = dddT[j + 1];
-          drbdX1[j, :] = zeros(size(Xtilde, 2));
-          drbdX2[j, :] = dddX[j + 1, :];
-        else
-          // volume properties computed by averaging
-          rhobar[j] = (gas[j].d + gas[j + 1].d)/2;
-          drbdp[j] = (dddp[j] + dddp[j + 1])/2;
-          drbdT1[j] = dddT[j]/2;
-          drbdT2[j] = dddT[j + 1]/2;
-          drbdX1[j, :] = dddX[j, :]/2;
-          drbdX2[j, :] = dddX[j + 1, :]/2;
-        end if;
-        vbar[j] = 1/rhobar[j];
-        if fixedMassFlowSimplified then
-          wbar[j] = homotopy(infl.m_flow/Nt - sum(dMdt[1:j - 1]) - dMdt[j]/2,
-                             wnom/Nt);
-        else
-          wbar[j] = infl.m_flow/Nt - sum(dMdt[1:j - 1]) - dMdt[j]/2;
-        end if;
-        cvbar[j] = (cv[j] + cv[j + 1])/2;
-      else
-        // Static mass and energy balances
-        wbar[j]*(gas[j + 1].h - gas[j].h) = Q_single[j] "Energy balance";
-        dMdt[j] = 0 "Mass balance";
-        // Dummy values for unused average quantities
-        rhobar[j] = 0;
-        drbdp[j] = 0;
-        drbdT1[j] = 0;
-        drbdT2[j] = 0;
-        drbdX1[j, :] = zeros(nX);
-        drbdX2[j, :] = zeros(nX);
-        vbar[j] = 0;
-        if fixedMassFlowSimplified then
-          wbar[j] = homotopy(infl.m_flow/Nt, wnom/Nt);
-        else
-          wbar[j] = infl.m_flow/Nt;
-        end if;
-        cvbar[j] = 0;
-      end if;
+*/
+// Average volume quantities
+        if avoidInletEnthalpyDerivative and j == 1 then
+// first volume properties computed by the volume outlet properties
+          rhobar[j] = gas[j + 1].d;
+          drbdp[j] = dddp[j + 1];
+          drbdT1[j] = 0;
+          drbdT2[j] = dddT[j + 1];
+          drbdX1[j, :] = zeros(size(Xtilde, 2));
+          drbdX2[j, :] = dddX[j + 1, :];
+        else
+// volume properties computed by averaging
+          rhobar[j] = (gas[j].d + gas[j + 1].d) / 2;
+          drbdp[j] = (dddp[j] + dddp[j + 1]) / 2;
+          drbdT1[j] = dddT[j] / 2;
+          drbdT2[j] = dddT[j + 1] / 2;
+          drbdX1[j, :] = dddX[j, :] / 2;
+          drbdX2[j, :] = dddX[j + 1, :] / 2;
+        end if;
+        vbar[j] = 1 / rhobar[j];
+        if fixedMassFlowSimplified then
+          wbar[j] = homotopy(infl.m_flow / Nt - sum(dMdt[1:j - 1]) - dMdt[j] / 2, wnom / Nt);
+        else
+          wbar[j] = infl.m_flow / Nt - sum(dMdt[1:j - 1]) - dMdt[j] / 2;
+        end if;
+        cvbar[j] = (cv[j] + cv[j + 1]) / 2;
+      else
+// Static mass and energy balances
+        wbar[j] * (gas[j + 1].h - gas[j].h) = Q_single[j] "Energy balance";
+        dMdt[j] = 0 "Mass balance";
+// Dummy values for unused average quantities
+        rhobar[j] = 0;
+        drbdp[j] = 0;
+        drbdT1[j] = 0;
+        drbdT2[j] = 0;
+        drbdX1[j, :] = zeros(nX);
+        drbdX2[j, :] = zeros(nX);
+        vbar[j] = 0;
+        if fixedMassFlowSimplified then
+          wbar[j] = homotopy(infl.m_flow / Nt, wnom / Nt);
+        else
+          wbar[j] = infl.m_flow / Nt;
+        end if;
+        cvbar[j] = 0;
+      end if;
     end for;
     Q = heatTransfer.Q "Total heat flow through the lateral boundary";
     if Medium.fixedX then
@@ -1136,35 +1121,33 @@
       gas[j].p = p;
       gas[j].T = T[j];
       gas[j].h = h[j];
-    end for;
-    // Fluid property computations
-    for j in 1:N loop
-      if not QuasiStatic then
-        cv[j] = Medium.heatCapacity_cv(gas[j].state);
-        dddT[j] = Medium.density_derT_p(gas[j].state);
-        dddp[j] = Medium.density_derp_T(gas[j].state);
-        if nX > 0 then
-          dddX[j, :] = Medium.density_derX(gas[j].state);
-        end if;
-      else
-        // Dummy values (not needed by dynamic equations)
-        cv[j] = 0;
-        dddT[j] = 0;
-        dddp[j] = 0;
-        dddX[j, :] = zeros(nX);
-      end if;
-    end for;
-
-    // Selection of representative pressure and flow rate variables
-    if HydraulicCapacitance ==ThermoPower.Choices.Flow1D.HCtypes.Upstream then
-      p = infl.p;
-      w = -outfl.m_flow/Nt;
-    else
-      p = outfl.p;
-      w = infl.m_flow/Nt;
-    end if;
-
-    // Boundary conditions
+    end for;
+// Fluid property computations
+    for j in 1:N loop
+      if not QuasiStatic then
+        cv[j] = Medium.heatCapacity_cv(gas[j].state);
+        dddT[j] = Medium.density_derT_p(gas[j].state);
+        dddp[j] = Medium.density_derp_T(gas[j].state);
+        if nX > 0 then
+          dddX[j, :] = Medium.density_derX(gas[j].state);
+        end if;
+      else
+// Dummy values (not needed by dynamic equations)
+        cv[j] = 0;
+        dddT[j] = 0;
+        dddp[j] = 0;
+        dddX[j, :] = zeros(nX);
+      end if;
+    end for;
+// Selection of representative pressure and flow rate variables
+    if HydraulicCapacitance == ThermoPower.Choices.Flow1D.HCtypes.Upstream then
+      p = infl.p;
+      w = -outfl.m_flow / Nt;
+    else
+      p = outfl.p;
+      w = infl.m_flow / Nt;
+    end if;
+// Boundary conditions
     infl.h_outflow = gas[1].h;
     outfl.h_outflow = gas[N].h;
     infl.Xi_outflow = gas[1].Xi;
@@ -1188,7 +1171,7 @@
     assert(infl.m_flow > -wnom*wnm, "Reverse flow not allowed, maybe you connected the component with wrong orientation");
   initial equation
     if initOpt == Choices.Init.Options.noInit or QuasiStatic then
-      // do nothing
+// do nothing
     elseif initOpt == Choices.Init.Options.fixedState then
       if not noInitialPressure then
         p = pstart;
@@ -1323,25 +1306,12 @@
             allowFlowReversal then +Modelica.Constants.inf else 0)) annotation (
        Placement(transformation(extent={{40,-20},{80,20}}, rotation=0)));
   equation
-    inlet1.m_flow + inlet2.m_flow + outlet.m_flow = 0 "Mass balance";
-
-    // Momentum balance
+    inlet1.m_flow + inlet2.m_flow + outlet.m_flow = 0 "Mass balance";
+// Momentum balance
     inlet1.p = outlet.p;
-    inlet2.p = outlet.p;
-
-    // Energy balance
-    outlet.h_outflow = homotopy(
-      if (inlet2.m_flow < 0 and rev_inlet2) then
-        inStream(inlet1.h_outflow)
-      else if (inlet1.m_flow < 0 and rev_inlet1) then
-        inStream(inlet2.h_outflow)
-      else
-        (inStream(inlet1.h_outflow)*(inlet1.m_flow+ wzero) +
-         inStream(inlet2.h_outflow)*(inlet2.m_flow + wzero))/
-        (inlet1.m_flow + 2*wzero + inlet2.m_flow),
-      (inStream(inlet1.h_outflow)*(inlet1.m_flow + wzero) +
-       inStream(inlet2.h_outflow)*(inlet2.m_flow + wzero))/
-      (inlet1.m_flow + 2*wzero + inlet2.m_flow));
+    inlet2.p = outlet.p;
+// Energy balance
+    outlet.h_outflow = homotopy(if inlet2.m_flow < 0 and rev_inlet2 then inStream(inlet1.h_outflow) else if inlet1.m_flow < 0 and rev_inlet1 then inStream(inlet2.h_outflow) else (inStream(inlet1.h_outflow) * (inlet1.m_flow + wzero) + inStream(inlet2.h_outflow) * (inlet2.m_flow + wzero)) / (inlet1.m_flow + 2 * wzero + inlet2.m_flow), (inStream(inlet1.h_outflow) * (inlet1.m_flow + wzero) + inStream(inlet2.h_outflow) * (inlet2.m_flow + wzero)) / (inlet1.m_flow + 2 * wzero + inlet2.m_flow));
 
     inlet1.h_outflow = homotopy(
       if (inlet2.m_flow < 0 and rev_inlet2) then
@@ -1363,21 +1333,9 @@
         (inStream(outlet.h_outflow)*(outlet.m_flow + wzero) +
          inStream(inlet1.h_outflow)*(inlet1.m_flow + wzero))/
         (outlet.m_flow + 2*wzero + inlet1.m_flow),
-      inStream(outlet.h_outflow));
-
-    // Independent component mass balances
-    outlet.Xi_outflow = homotopy(
-      if (inlet2.m_flow < 0 and rev_inlet2) then
-        inStream(inlet1.Xi_outflow)
-      else if (inlet1.m_flow < 0 and rev_inlet1) then
-        inStream(inlet2.Xi_outflow)
-      else
-        (inStream(inlet1.Xi_outflow)*(inlet1.m_flow + wzero) +
-         inStream(inlet2.Xi_outflow)*(inlet2.m_flow + wzero))/
-        (inlet1.m_flow + 2*wzero + inlet2.m_flow),
-      (inStream(inlet1.Xi_outflow)*(inlet1.m_flow + wzero) +
-       inStream(inlet2.Xi_outflow)*(inlet2.m_flow + wzero))/
-      (inlet1.m_flow + 2*wzero + inlet2.m_flow));
+      inStream(outlet.h_outflow));
+// Independent component mass balances
+    outlet.Xi_outflow = homotopy(if inlet2.m_flow < 0 and rev_inlet2 then inStream(inlet1.Xi_outflow) else if inlet1.m_flow < 0 and rev_inlet1 then inStream(inlet2.Xi_outflow) else (inStream(inlet1.Xi_outflow) * (inlet1.m_flow + wzero) + inStream(inlet2.Xi_outflow) * (inlet2.m_flow + wzero)) / (inlet1.m_flow + 2 * wzero + inlet2.m_flow), (inStream(inlet1.Xi_outflow) * (inlet1.m_flow + wzero) + inStream(inlet2.Xi_outflow) * (inlet2.m_flow + wzero)) / (inlet1.m_flow + 2 * wzero + inlet2.m_flow));
 
     inlet1.Xi_outflow = homotopy(
       if (inlet2.m_flow < 0 and rev_inlet2) then
@@ -1399,14 +1357,9 @@
         (inStream(outlet.Xi_outflow)*(outlet.m_flow + wzero) +
          inStream(inlet1.Xi_outflow)*(inlet1.m_flow + wzero))/
         (outlet.m_flow + 2*wzero + inlet1.m_flow),
-      inStream(outlet.Xi_outflow));
-
-    //Check flow direction
-    assert(not checkFlowDirection or
-     ((rev_inlet1 or inlet1.m_flow >= 0) and
-      (rev_inlet2 or inlet2.m_flow >= 0) and
-      (rev_outlet or outlet.m_flow <= 0)),
-      "Flow reversal not supported");
+      inStream(outlet.Xi_outflow));
+//Check flow direction
+    assert(not checkFlowDirection or (rev_inlet1 or inlet1.m_flow >= 0) and (rev_inlet2 or inlet2.m_flow >= 0) and (rev_outlet or outlet.m_flow <= 0), "Flow reversal not supported");
     annotation (
       Icon(graphics),
       Documentation(info="<html>
@@ -1464,23 +1417,12 @@
        Placement(transformation(extent={{40,-60},{80,-20}}, rotation=0)));
 
   equation
-    inlet.m_flow + outlet1.m_flow + outlet2.m_flow = 0 "Mass balance";
-
-    // Momentum balance
+    inlet.m_flow + outlet1.m_flow + outlet2.m_flow = 0 "Mass balance";
+// Momentum balance
     outlet1.p = inlet.p;
-    outlet2.p = inlet.p;
-
-    // Energy balance
-    outlet1.h_outflow = homotopy(
-      if (inlet.m_flow < 0 and rev_inlet) then
-        inStream(outlet2.h_outflow)
-      else if (outlet2.m_flow < 0 or not rev_outlet2) then
-        inStream(inlet.h_outflow)
-      else
-        (inStream(inlet.h_outflow)*(inlet.m_flow + wzero) +
-         inStream(outlet2.h_outflow)*(outlet2.m_flow + wzero))/
-        (inlet.m_flow + 2*wzero + outlet2.m_flow),
-      inStream(inlet.h_outflow));
+    outlet2.p = inlet.p;
+// Energy balance
+    outlet1.h_outflow = homotopy(if inlet.m_flow < 0 and rev_inlet then inStream(outlet2.h_outflow) else if outlet2.m_flow < 0 or not rev_outlet2 then inStream(inlet.h_outflow) else (inStream(inlet.h_outflow) * (inlet.m_flow + wzero) + inStream(outlet2.h_outflow) * (outlet2.m_flow + wzero)) / (inlet.m_flow + 2 * wzero + outlet2.m_flow), inStream(inlet.h_outflow));
 
     outlet2.h_outflow = homotopy(
       if (inlet.m_flow < 0 and rev_inlet) then
@@ -1502,19 +1444,9 @@
         (inStream(outlet1.h_outflow)*(outlet1.m_flow + wzero) +
          inStream(outlet2.h_outflow)*(outlet2.m_flow + wzero))/
         (outlet1.m_flow + 2*wzero + outlet2.m_flow),
-      inStream(outlet1.h_outflow));
-
-    // Independent component mass balances
-    outlet1.Xi_outflow = homotopy(
-      if (inlet.m_flow < 0 and rev_inlet) then
-        inStream(outlet2.Xi_outflow)
-      else if (outlet2.m_flow < 0 or not rev_outlet2) then
-        inStream(inlet.Xi_outflow)
-      else
-        (inStream(inlet.Xi_outflow)*(inlet.m_flow + wzero) +
-         inStream(outlet2.Xi_outflow)*(outlet2.m_flow + wzero))/
-        (inlet.m_flow + 2*wzero + outlet2.m_flow),
-      inStream(inlet.Xi_outflow));
+      inStream(outlet1.h_outflow));
+// Independent component mass balances
+    outlet1.Xi_outflow = homotopy(if inlet.m_flow < 0 and rev_inlet then inStream(outlet2.Xi_outflow) else if outlet2.m_flow < 0 or not rev_outlet2 then inStream(inlet.Xi_outflow) else (inStream(inlet.Xi_outflow) * (inlet.m_flow + wzero) + inStream(outlet2.Xi_outflow) * (outlet2.m_flow + wzero)) / (inlet.m_flow + 2 * wzero + outlet2.m_flow), inStream(inlet.Xi_outflow));
 
     outlet2.Xi_outflow = homotopy(
       if (inlet.m_flow < 0 and rev_inlet) then
@@ -1536,13 +1468,9 @@
         (inStream(outlet1.Xi_outflow)*(outlet1.m_flow + wzero) +
          inStream(outlet2.Xi_outflow)*(outlet2.m_flow + wzero))/
         (outlet1.m_flow + 2*wzero + outlet2.m_flow),
-      inStream(outlet1.Xi_outflow));
-
-    //Check flow direction
-    assert(not checkFlowDirection or
-     ((rev_inlet or inlet.m_flow >= 0) and
-      (rev_outlet1 or outlet1.m_flow <= 0) and
-      (rev_outlet2 or outlet2.m_flow <= 0)), "Flow reversal not supported");
+      inStream(outlet1.Xi_outflow));
+//Check flow direction
+    assert(not checkFlowDirection or (rev_inlet or inlet.m_flow >= 0) and (rev_outlet1 or outlet1.m_flow <= 0) and (rev_outlet2 or outlet2.m_flow <= 0), "Flow reversal not supported");
     annotation (
       Icon(graphics),
       Documentation(info="<html>
@@ -1590,8 +1518,7 @@
   equation
     inlet.m_flow + outlet.m_flow = 0 "Mass balance";
     inlet.p - outlet.p = R*inlet.m_flow "Flow characteristics";
-
-    // Boundary conditions
+// Boundary conditions
     inlet.h_outflow = inStream(outlet.h_outflow);
     inStream(inlet.h_outflow) = outlet.h_outflow;
     inlet.Xi_outflow = inStream(outlet.Xi_outflow);
@@ -1677,32 +1604,27 @@
     end if;
   equation
     assert(dpnom > 0, "Please set a positive value for dpnom");
-    assert(rhonom > 0 or FFtype <> FFtypes.OpPoint, "Please set a positive value for rhonom");
-    // Set fluid properties
-    gas.p = homotopy(if not allowFlowReversal then pin else if inlet.m_flow >=
-      0 then pin else pout, pin);
+    assert(rhonom > 0 or FFtype <> FFtypes.OpPoint, "Please set a positive value for rhonom");
+// Set fluid properties
+    gas.p = homotopy(if not allowFlowReversal then pin else if inlet.m_flow >= 0 then pin else pout, pin);
     gas.h = homotopy(if not allowFlowReversal then inStream(inlet.h_outflow)
        else actualStream(inlet.h_outflow), inStream(inlet.h_outflow));
     gas.Xi = homotopy(if not allowFlowReversal then inStream(inlet.Xi_outflow)
        else actualStream(inlet.Xi_outflow), inStream(inlet.Xi_outflow));
 
     pin - pout = homotopy(smooth(1, Kf_a*squareReg(w, wnom*wnf))/gas.d, dpnom/
-      wnom*w) "Flow characteristics";
-
-    //Boundary conditions
+      wnom*w) "Flow characteristics";
+//Boundary conditions
     w = inlet.m_flow;
     pin = inlet.p;
     pout = outlet.p;
-    dp = pin - pout;
-
-    // Mass balance
-    inlet.m_flow + outlet.m_flow = 0;
-
-    // Energy balance
+    dp = pin - pout;
+// Mass balance
+    inlet.m_flow + outlet.m_flow = 0;
+// Energy balance
     inlet.h_outflow = inStream(outlet.h_outflow);
-    inStream(inlet.h_outflow) = outlet.h_outflow;
-
-    // Independent component mass balances
+    inStream(inlet.h_outflow) = outlet.h_outflow;
+// Independent component mass balances
     inlet.Xi_outflow = inStream(outlet.Xi_outflow);
     inStream(inlet.Xi_outflow) = outlet.Xi_outflow;
     annotation (
@@ -1750,17 +1672,14 @@
           transformation(extent={{60,50},{80,70}}, rotation=0)));
   equation
     inlet.m_flow + outlet.m_flow = 0 "Mass balance";
-    inlet.p = outlet.p "Momentum balance";
-
-    // Energy balance
+    inlet.p = outlet.p "Momentum balance";
+// Energy balance
     inlet.h_outflow = inStream(outlet.h_outflow);
-    inStream(inlet.h_outflow) = outlet.h_outflow;
-
-    // Independent composition mass balances
+    inStream(inlet.h_outflow) = outlet.h_outflow;
+// Independent composition mass balances
     inlet.Xi_outflow = inStream(outlet.Xi_outflow);
-    inStream(inlet.Xi_outflow) = outlet.Xi_outflow;
-
-    // Set gas properties
+    inStream(inlet.Xi_outflow) = outlet.Xi_outflow;
+// Set gas properties
     inlet.p = gas.p;
     gas.h = homotopy(if not allowFlowReversal then inStream(inlet.h_outflow)
        else inStream(inlet.h_outflow), inStream(inlet.h_outflow));
@@ -1849,13 +1768,11 @@
 
   equation
     inlet.m_flow + outlet.m_flow = 0 "Mass balance";
-    inlet.p = outlet.p "Momentum balance";
-
-    // Energy balance
+    inlet.p = outlet.p "Momentum balance";
+// Energy balance
     inlet.h_outflow = inStream(outlet.h_outflow);
-    inStream(inlet.h_outflow) = outlet.h_outflow;
-
-    // Independent composition mass balances
+    inStream(inlet.h_outflow) = outlet.h_outflow;
+// Independent composition mass balances
     inlet.Xi_outflow = inStream(outlet.Xi_outflow);
     inStream(inlet.Xi_outflow) = outlet.Xi_outflow;
 
@@ -1937,17 +1854,14 @@
   equation
     inlet.m_flow + outlet.m_flow = 0 "Mass balance";
     inlet.p = outlet.p "Momentum balance";
-    w = inlet.m_flow;
-
-    // Energy balance
+    w = inlet.m_flow;
+// Energy balance
     inlet.h_outflow = inStream(outlet.h_outflow);
-    inStream(inlet.h_outflow) = outlet.h_outflow;
-
-    // Independent composition mass balances
+    inStream(inlet.h_outflow) = outlet.h_outflow;
+// Independent composition mass balances
     inlet.Xi_outflow = inStream(outlet.Xi_outflow);
-    inStream(inlet.Xi_outflow) = outlet.Xi_outflow;
-
-    // Gas properties
+    inStream(inlet.Xi_outflow) = outlet.Xi_outflow;
+// Gas properties
     gas.p = inlet.p;
     gas.h = homotopy(if not allowFlowReversal then inStream(inlet.h_outflow)
        else inStream(inlet.h_outflow), inStream(inlet.h_outflow));
@@ -1997,13 +1911,11 @@
   equation
     inlet.m_flow + outlet.m_flow = 0 "Mass balance";
     inlet.m_flow = w;
-    w = Kv*cmd*(inlet.p - outlet.p) "Flow characteristics";
-
-    // Energy balance
+    w = Kv*cmd*(inlet.p - outlet.p) "Flow characteristics";
+// Energy balance
     inlet.h_outflow = inStream(outlet.h_outflow);
-    inStream(inlet.h_outflow) = outlet.h_outflow;
-
-    // Independent composition mass balances
+    inStream(inlet.h_outflow) = outlet.h_outflow;
+// Independent composition mass balances
     inlet.Xi_outflow = inStream(outlet.Xi_outflow);
     inStream(inlet.Xi_outflow) = outlet.Xi_outflow;
     annotation (
@@ -2133,17 +2045,16 @@
     elseif CvData == ThermoPower.Choices.Valve.CvTypes.Cv then
       Av = 2.4027e-5*Cv;
     end if;
-    // assert(CvData>=0 and CvData<=3, "Invalid CvData");
-
-    if CvData == ThermoPower.Choices.Valve.CvTypes.OpPoint then
-      // Determination of Av by the nominal operating point conditions
-      Fxt_nom = Fxt_full*xtfun(thetanom);
+// assert(CvData>=0 and CvData<=3, "Invalid CvData");
+    if CvData == ThermoPower.Choices.Valve.CvTypes.OpPoint then
+// Determination of Av by the nominal operating point conditions
+      Fxt_nom = Fxt_full * xtfun(thetanom);
       x_nom = dpnom/pnom;
       xs_nom = smooth(0, if x_nom > Fxt_nom then Fxt_nom else x_nom);
       Y_nom = 1 - abs(xs_nom)/(3*Fxt_nom);
       wnom = FlowChar(thetanom)*Av*Y_nom*sqrt(rhonom)*sqrtR(pnom*xs_nom);
-    else
-      // Dummy values
+    else
+// Dummy values
       Fxt_nom = 0;
       x_nom = 0;
       xs_nom = 0;
@@ -2151,9 +2062,8 @@
     end if;
   equation
     inlet.m_flow + outlet.m_flow = 0 "Mass balance";
-    w = inlet.m_flow;
-
-    // Fluid properties
+    w = inlet.m_flow;
+// Fluid properties
     gas.p = inlet.p;
     gas.h = inStream(inlet.h_outflow);
     gas.Xi = inStream(inlet.Xi_outflow);
@@ -2171,20 +2081,19 @@
     else
       w = homotopy(FlowChar(theta_act)*Av*Y*sqrt(gas.d)*sqrtR(p*xs), theta_act/thetanom
         *dpnom/wnom*dp);
-    end if;
-
-    // Energy balance
+    end if;
+// Energy balance
     inlet.h_outflow = inStream(outlet.h_outflow);
-    inStream(inlet.h_outflow) = outlet.h_outflow;
-
-    // Mass balances of independent components
+    inStream(inlet.h_outflow) = outlet.h_outflow;
+// Mass balances of independent components
     inlet.Xi_outflow = inStream(outlet.Xi_outflow);
-    inStream(inlet.Xi_outflow) = outlet.Xi_outflow;
-
-    // Valve opening
-    connect(theta, theta_int); // automatically removed if theta is disabled
-    if not useThetaInput then
-      theta_int = theta_fix;   // provide actual opening value from parameter
+    inStream(inlet.Xi_outflow) = outlet.Xi_outflow;
+// Valve opening
+    connect(theta, theta_int);
+// automatically removed if theta is disabled
+    if not useThetaInput then
+      theta_int = theta_fix;
+// provide actual opening value from parameter
     end if;
     theta_act = theta_int;
     annotation (
@@ -2311,21 +2220,21 @@
     parameter String fileName="noName" "File where matrix is stored";
     parameter TableTypes Table = TableTypes.matrix
       "Selection of the way of definition of table matrix";
-    Modelica.Blocks.Tables.CombiTable2D Eta(
+    Modelica.Blocks.Tables.CombiTable2Ds Eta(
       tableOnFile=if (Table == TableTypes.matrix) then false else true,
       table=tableEta,
       tableName=if (Table == TableTypes.matrix) then "NoName" else "tabEta",
       fileName=if (Table == TableTypes.matrix) then "NoName" else fileName,
       smoothness=Modelica.Blocks.Types.Smoothness.ContinuousDerivative)
       annotation (Placement(transformation(extent={{-12,60},{8,80}}, rotation=0)));
-    Modelica.Blocks.Tables.CombiTable2D PressRatio(
+    Modelica.Blocks.Tables.CombiTable2Ds PressRatio(
       tableOnFile=if (Table == TableTypes.matrix) then false else true,
       table=tablePR,
       tableName=if (Table == TableTypes.matrix) then "NoName" else "tabPR",
       fileName=if (Table == TableTypes.matrix) then "NoName" else fileName,
       smoothness=Modelica.Blocks.Types.Smoothness.ContinuousDerivative)
       annotation (Placement(transformation(extent={{-12,0},{8,20}}, rotation=0)));
-    Modelica.Blocks.Tables.CombiTable2D Phic(
+    Modelica.Blocks.Tables.CombiTable2Ds Phic(
       tableOnFile=if (Table == TableTypes.matrix) then false else true,
       table=tablePhic,
       tableName=if (Table == TableTypes.matrix) then "NoName" else "tabPhic",
@@ -2341,19 +2250,16 @@
     N_T_design = Ndesign/sqrt(Tdes_in) "Referred design velocity";
     N_T = 100*omega/(sqrt(gas_in.T)*N_T_design)
       "Referred speed definition, as percentage of design velocity";
-    phic = w*sqrt(gas_in.T)/(gas_in.p) "Flow number definition";
-
-    // phic = Phic(beta, N_T)
+    phic = w*sqrt(gas_in.T)/(gas_in.p) "Flow number definition";
+// phic = Phic(beta, N_T)
     Phic.u1 = beta;
     Phic.u2 = N_T;
-    phic = Phic.y;
-
-    // eta = Eta(beta, N_T)
+    phic = Phic.y;
+// eta = Eta(beta, N_T)
     Eta.u1 = beta;
     Eta.u2 = N_T;
-    eta = Eta.y;
-
-    // PR = PressRatio(beta, N_T)
+    eta = Eta.y;
+// PR = PressRatio(beta, N_T)
     PressRatio.u1 = beta;
     PressRatio.u2 = N_T;
     PR = PressRatio.y;
@@ -2409,7 +2315,7 @@
     Real N_T "Referred speed";
     Real N_T_design "Referred design speed";
     Real phic "Flow number";
-    Modelica.Blocks.Tables.CombiTable2D Phic(
+    Modelica.Blocks.Tables.CombiTable2Ds Phic(
       tableOnFile=if (Table == TableTypes.matrix) then false else true,
       table=tablePhic,
       tableName=if (Table == TableTypes.matrix) then "NoName" else "tabPhic",
@@ -2417,7 +2323,7 @@
       smoothness=Modelica.Blocks.Types.Smoothness.ContinuousDerivative)
       annotation (Placement(transformation(extent={{-10,10},{10,30}}, rotation=
               0)));
-    Modelica.Blocks.Tables.CombiTable2D Eta(
+    Modelica.Blocks.Tables.CombiTable2Ds Eta(
       tableOnFile=if (Table == TableTypes.matrix) then false else true,
       table=tableEta,
       tableName=if (Table == TableTypes.matrix) then "NoName" else "tabEta",
@@ -2429,14 +2335,12 @@
     N_T_design = Ndesign/sqrt(Tdes_in) "Referred design velocity";
     N_T = 100*omega/(sqrt(gas_in.T)*N_T_design)
       "Referred speed definition as percentage of design velocity";
-    phic = w*sqrt(gas_in.T)/(gas_in.p) "Flow number definition";
-
-    // phic = Phic(PR, N_T)
+    phic = w*sqrt(gas_in.T)/(gas_in.p) "Flow number definition";
+// phic = Phic(PR, N_T)
     Phic.u1 = PR;
     Phic.u2 = N_T;
-    phic = (Phic.y);
-
-    // eta = Eta(PR, N_T)
+    phic = (Phic.y);
+// eta = Eta(PR, N_T)
     Eta.u1 = PR;
     Eta.u2 = N_T;
     eta = Eta.y;
@@ -2498,7 +2402,7 @@
     Real N_T_design "Referred design speed";
     Real phic "Flow number";
 
-    Modelica.Blocks.Tables.CombiTable2D Eta(
+    Modelica.Blocks.Tables.CombiTable2Ds Eta(
       tableOnFile=if (Table == TableTypes.matrix) then false else true,
       table=tableEta,
       tableName=if (Table == TableTypes.matrix) then "NoName" else "tabEta",
@@ -2507,7 +2411,7 @@
       annotation (Placement(transformation(extent={{-16,38},{4,58}}, rotation=0)));
 
   initial equation
-    // set K if NominalCondition is true
+// set K if NominalCondition is true
     if NominalCondition then
       wnom*sqrt(Tstart_in)/pstart_in = K*sqrt(1 - (pstart_out/pstart_in)^2)
         "Stodola's constant evaluated from design operation";
@@ -2517,12 +2421,10 @@
     N_T_design = Ndesign/sqrt(Tdes_in) "Referred design velocity";
     N_T = 100*omega/(sqrt(gas_in.T)*N_T_design)
       "Referred speed definition as percentage of design velocity";
-    phic = w*sqrt(gas_in.T)/(gas_in.p) "Flow number definition";
-
-    // phic = function(PR, K)
-    phic = K*sqrt(1 - (1/PR)^2);
-
-    // eta = Eta(PR, N_T)
+    phic = w*sqrt(gas_in.T)/(gas_in.p) "Flow number definition";
+// phic = function(PR, K)
+    phic = K * sqrt(1 - (1 / PR) ^ 2);
+// eta = Eta(PR, N_T)
     Eta.u1 = PR;
     Eta.u2 = N_T;
 
@@ -2578,15 +2480,13 @@
       annotation (Placement(transformation(extent={{-10,28},{10,48}}, rotation=
               0)));
 
-  equation
-    // HI_ISO = f(ZLPout_ISO)
+  equation
+// HI_ISO = f(ZLPout_ISO)
     OperatingPoint.u = ZLPout_ISO;
-    OperatingPoint.y[1] = HI_ISO;
-
-    // PR = g(ZLP_ISO)
-    OperatingPoint.y[2] = PR;
-
-    // wia_iso = h(ZLP_ISO)
+    OperatingPoint.y[1] = HI_ISO;
+// PR = g(ZLP_ISO)
+    OperatingPoint.y[2] = PR;
+// wia_iso = h(ZLP_ISO)
     OperatingPoint.y[3] = wia_ISO;
     annotation (
       Icon(graphics),
@@ -2642,21 +2542,21 @@
     parameter String fileName="noName" "File where matrix is stored";
     parameter TableTypes Table = TableTypes.matrix
       "Selection of the way of definition of table matrix";
-    Modelica.Blocks.Tables.CombiTable2D PowerOut(
+    Modelica.Blocks.Tables.CombiTable2Ds PowerOut(
       tableOnFile=if (Table == TableTypes.matrix) then false else true,
       table=tableHI,
       tableName=if (Table == TableTypes.matrix) then "NoName" else "tabHI",
       fileName=if (Table == TableTypes.matrix) then "NoName" else fileName,
       smoothness=Modelica.Blocks.Types.Smoothness.ContinuousDerivative)
       annotation (Placement(transformation(extent={{-12,36},{8,56}}, rotation=0)));
-    Modelica.Blocks.Tables.CombiTable2D PressRatio(
+    Modelica.Blocks.Tables.CombiTable2Ds PressRatio(
       tableOnFile=if (Table == TableTypes.matrix) then false else true,
       table=tablePR,
       tableName=if (Table == TableTypes.matrix) then "NoName" else "tabPR",
       fileName=if (Table == TableTypes.matrix) then "NoName" else fileName,
       smoothness=Modelica.Blocks.Types.Smoothness.ContinuousDerivative)
       annotation (Placement(transformation(extent={{-12,6},{8,26}}, rotation=0)));
-    Modelica.Blocks.Tables.CombiTable2D MassFlowRate(
+    Modelica.Blocks.Tables.CombiTable2Ds MassFlowRate(
       tableOnFile=if (Table == TableTypes.matrix) then false else true,
       table=tableW,
       tableName=if (Table == TableTypes.matrix) then "NoName" else "tabW",
@@ -2667,18 +2567,16 @@
     SI.Temperature Tsync
       "temperature corresponding to omega referred in synchronous conditions";
   equation
-    Tsync = (omega_sync/omega)^2*gas.T;
-    // HI_ISO = f(ZLPout_ISO, Tsync)
+    Tsync = (omega_sync/omega)^2*gas.T;
+// HI_ISO = f(ZLPout_ISO, Tsync)
     PowerOut.u1 = ZLPout_ISO;
     PowerOut.u2 = Tsync;
-    PowerOut.y = HI_ISO;
-
-    // PR = g(ZLPout_ISO, Tsync)
+    PowerOut.y = HI_ISO;
+// PR = g(ZLPout_ISO, Tsync)
     PressRatio.u1 = ZLPout_ISO;
     PressRatio.u2 = Tsync;
-    PressRatio.y = PR;
-
-    // wia_ISO = h(ZLPout_ISO, Tsync)
+    PressRatio.y = PR;
+// wia_ISO = h(ZLPout_ISO, Tsync)
     MassFlowRate.u1 = ZLPout_ISO;
     MassFlowRate.u2 = Tsync;
     MassFlowRate.y = wia_ISO;
@@ -2726,10 +2624,9 @@
     SI.AngularVelocity omega "Shaft angular velocity";
     Modelica.Mechanics.Rotational.Interfaces.Flange_a MechPort annotation (
         Placement(transformation(extent={{78,6},{108,36}}, rotation=0)));
-  equation
-    n = Modelica.SIunits.Conversions.to_rpm(omega) "Rotational speed";
-
-    // Mechanical boundary condition
+  equation
+  n = Modelica.Units.Conversions.to_rpm(omega) "Rotational speed";
+// Mechanical boundary condition
     phi = MechPort.phi;
     omega = der(phi);
     W_single = omega*MechPort.tau;
@@ -3017,14 +2914,12 @@
         Cm*der(Tm) = gamma*S*(fluegas.T - Tm) "Metal wall energy balance";
       else
         Tm = fluegas.T;
-      end if;
-
-      // Set gas properties
+      end if;
+// Set gas properties
       out.p = fluegas.p;
       out.h_outflow = fluegas.h;
-      out.Xi_outflow = fluegas.Xi;
-
-      // Boundary conditions
+      out.Xi_outflow = fluegas.Xi;
+// Boundary conditions
       ina.p = fluegas.p;
       ina.h_outflow = 0;
       ina.Xi_outflow = Air.reference_X[1:Air.nXi];
@@ -3040,9 +2935,9 @@
 
       Tr = noEvent(M/max(abs(out.m_flow), Modelica.Constants.eps));
     initial equation
-      // Initial conditions
+// Initial conditions
       if initOpt == Choices.Init.Options.noInit then
-        // do nothing
+// do nothing
       elseif initOpt == Choices.Init.Options.fixedState then
         if not noInitialPressure then
           fluegas.p = pstart;
@@ -3147,47 +3042,40 @@
     equation
       w = inlet.m_flow;
       assert(w >= 0, "The compressor model does not support flow reversal");
-      inlet.m_flow + outlet.m_flow = 0 "Mass balance";
-
-      // Set inlet gas properties
+      inlet.m_flow + outlet.m_flow = 0 "Mass balance";
+// Set inlet gas properties
       gas_in.p = inlet.p;
       gas_in.h = inStream(inlet.h_outflow);
-      gas_in.Xi = inStream(inlet.Xi_outflow);
-
-      // Set outlet gas properties
+      gas_in.Xi = inStream(inlet.Xi_outflow);
+// Set outlet gas properties
       outlet.p = pout;
       outlet.h_outflow = hout;
-      outlet.Xi_outflow = gas_in.Xi;
-
-      // Equations for reverse flow (not used)
+      outlet.Xi_outflow = gas_in.Xi;
+// Equations for reverse flow (not used)
       inlet.h_outflow = inStream(outlet.h_outflow);
-      inlet.Xi_outflow = inStream(outlet.Xi_outflow);
-
-      // Component mass balances
-      gas_iso.Xi = gas_in.Xi;
-
-      if explicitIsentropicEnthalpy then
-        hout_iso = Medium.isentropicEnthalpy(outlet.p, gas_in.state)
-          "Approximated isentropic enthalpy";
-        hout - gas_in.h = 1/eta*(hout_iso - gas_in.h);
-        // dummy assignments
-        s_in = 0;
-        gas_iso.p = 1e5;
-        gas_iso.T = 300;
-      else
-        // Properties of the gas after isentropic transformation
-        gas_iso.p = pout;
-        s_in = Medium.specificEntropy(gas_in.state);
-        s_in = Medium.specificEntropy(gas_iso.state);
-        hout - gas_in.h = 1/eta*(gas_iso.h - gas_in.h);
-        // dummy assignment
-        hout_iso = 0;
+      inlet.Xi_outflow = inStream(outlet.Xi_outflow);
+// Component mass balances
+      gas_iso.Xi = gas_in.Xi;
+  if explicitIsentropicEnthalpy then
+        hout_iso = Medium.isentropicEnthalpy(outlet.p, gas_in.state) "Approximated isentropic enthalpy";
+        hout - gas_in.h = 1 / eta * (hout_iso - gas_in.h);
+// dummy assignments
+        s_in = 0;
+        gas_iso.p = 1e5;
+        gas_iso.T = 300;
+      else
+// Properties of the gas after isentropic transformation
+        gas_iso.p = pout;
+        s_in = Medium.specificEntropy(gas_in.state);
+        s_in = Medium.specificEntropy(gas_iso.state);
+        hout - gas_in.h = 1 / eta * (gas_iso.h - gas_in.h);
+// dummy assignment
+        hout_iso = 0;
       end if;
 
       w*(hout - gas_in.h) = tau*omega*eta_mech "Energy balance";
-      PR = pout/gas_in.p "Pressure ratio";
-
-      // Mechanical boundary conditions
+      PR = pout/gas_in.p "Pressure ratio";
+// Mechanical boundary conditions
       shaft_a.phi = phi;
       shaft_b.phi = phi;
       shaft_a.tau + shaft_b.tau = tau;
@@ -3280,47 +3168,40 @@
     equation
       w = inlet.m_flow;
       assert(w >= 0, "The turbine model does not support flow reversal");
-      inlet.m_flow + outlet.m_flow = 0 "Mass balance";
-
-      // Set inlet gas properties
+      inlet.m_flow + outlet.m_flow = 0 "Mass balance";
+// Set inlet gas properties
       gas_in.p = inlet.p;
       gas_in.h = inStream(inlet.h_outflow);
-      gas_in.Xi = inStream(inlet.Xi_outflow);
-
-      // Set outlet gas properties
+      gas_in.Xi = inStream(inlet.Xi_outflow);
+// Set outlet gas properties
       outlet.p = pout;
       outlet.h_outflow = hout;
-      outlet.Xi_outflow = gas_in.Xi;
-
-      // Equations for reverse flow (not used)
+      outlet.Xi_outflow = gas_in.Xi;
+// Equations for reverse flow (not used)
       inlet.h_outflow = inStream(outlet.h_outflow);
-      inlet.Xi_outflow = inStream(outlet.Xi_outflow);
-
-      // Component mass balances
-      gas_iso.Xi = gas_in.Xi;
-
-      if explicitIsentropicEnthalpy then
-        hout_iso = Medium.isentropicEnthalpy(outlet.p, gas_in.state)
-          "Approximated isentropic enthalpy";
-        hout - gas_in.h = eta*(hout_iso - gas_in.h) "Enthalpy change";
-        //dummy assignments
-        s_in = 0;
-        gas_iso.p = 1e5;
-        gas_iso.T = 300;
-      else
-        // Properties of the gas after isentropic transformation
-        gas_iso.p = pout;
-        s_in = Medium.specificEntropy(gas_in.state);
-        s_in = Medium.specificEntropy(gas_iso.state);
-        hout - gas_in.h = eta*(gas_iso.h - gas_in.h) "Enthalpy change";
-        //dummy assignment
-        hout_iso = 0;
+      inlet.Xi_outflow = inStream(outlet.Xi_outflow);
+// Component mass balances
+      gas_iso.Xi = gas_in.Xi;
+  if explicitIsentropicEnthalpy then
+        hout_iso = Medium.isentropicEnthalpy(outlet.p, gas_in.state) "Approximated isentropic enthalpy";
+        hout - gas_in.h = eta * (hout_iso - gas_in.h) "Enthalpy change";
+//dummy assignments
+        s_in = 0;
+        gas_iso.p = 1e5;
+        gas_iso.T = 300;
+      else
+// Properties of the gas after isentropic transformation
+        gas_iso.p = pout;
+        s_in = Medium.specificEntropy(gas_in.state);
+        s_in = Medium.specificEntropy(gas_iso.state);
+        hout - gas_in.h = eta * (gas_iso.h - gas_in.h) "Enthalpy change";
+//dummy assignment
+        hout_iso = 0;
       end if;
 
       w*(hout - gas_in.h)*eta_mech = tau*omega "Energy balance";
-      PR = gas_in.p/pout "Pressure ratio";
-
-      // Mechanical boundary conditions
+      PR = gas_in.p/pout "Pressure ratio";
+// Mechanical boundary conditions
       shaft_a.phi = phi;
       shaft_b.phi = phi;
       shaft_a.tau + shaft_b.tau = tau;
@@ -3362,11 +3243,11 @@
       replaceable package Air = Modelica.Media.Interfaces.PartialMedium;
       replaceable package Fuel = Modelica.Media.Interfaces.PartialMedium;
       replaceable package Exhaust = Modelica.Media.Interfaces.PartialMedium;
-      parameter Modelica.SIunits.Pressure pstart "start pressure value"
+      parameter Modelica.Units.SI.Pressure pstart "start pressure value"
         annotation (Dialog(tab="Initialisation"));
       parameter Exhaust.Temperature Tstart "start temperature value"
         annotation (Dialog(tab="Initialisation"));
-      parameter Modelica.SIunits.MassFraction Xstart[Air.nX]=Air.reference_X
+      parameter Modelica.Units.SI.MassFraction Xstart[Air.nX]=Air.reference_X
         "start gas composition" annotation (Dialog(tab="Initialisation"));
       constant Exhaust.AbsolutePressure pnom=1.013e5 "ISO reference pressure";
       constant Air.Temperature Tnom=288.15 "ISO reference temperature";
@@ -3427,14 +3308,12 @@
       Pout = ZLPout*eta_mech "Net power output";
       Pout = tau*omega "Mechanical boundary condition";
       wia_ISO = wia*sqrt(gas.T/Tnom)/(gas.p/pnom)
-        "Air mass flow, referred to ISO conditions";
-
-      // Set inlet gas properties
+        "Air mass flow, referred to ISO conditions";
+// Set inlet gas properties
       gas.p = Air_in.p;
       gas.h = inStream(Air_in.h_outflow);
-      gas.Xi = inStream(Air_in.Xi_outflow);
-
-      // Boundary conditions
+      gas.Xi = inStream(Air_in.Xi_outflow);
+// Boundary conditions
       assert(Air_in.m_flow >= 0, "The model does not support flow reversal");
       wia = Air_in.m_flow;
       hia = inStream(Air_in.h_outflow);
@@ -3449,10 +3328,9 @@
       Fuel_in.Xi_outflow = Fuel.reference_X[1:Fuel.nXi];
       assert(FlueGas_out.m_flow <= 0, "The model does not support flow reversal");
       wout = FlueGas_out.m_flow;
-      hout = FlueGas_out.h_outflow;
-      // Flue gas composition FlueGas_out.XBA to be determined by extended model
-
-      // Mechanical boundaries
+      hout = FlueGas_out.h_outflow;
+// Flue gas composition FlueGas_out.XBA to be determined by extended model
+// Mechanical boundaries
       shaft_b.phi = phi;
       shaft_b.tau = -tau;
       der(phi) = omega;
@@ -3506,7 +3384,7 @@
         FlueGas_out.Xi_outflow[1:Exhaust.nXi] = Exhaust.reference_X[1:Exhaust.nXi]
           "Reference value for exhaust compostion";
       else
-        // True mass balances
+// True mass balances
         0 = wia*Air_in_X[1] + wout*FlueGas_out.Xi_outflow[1] - 2*wcomb*Exhaust.data[
           1].MM "oxygen";
         0 = wia*Air_in_X[3] + wout*FlueGas_out.Xi_outflow[2] "argon";
@@ -3538,7 +3416,7 @@
         annotation(choicesAllMatching = true);
       Medium.BaseProperties inletFluid(h(start=hstart))
         "Fluid properties at the inlet";
-      // Flow Characteristic curves
+      // Flow Characteristic curves
       parameter Boolean useFlowModel = false "Use function from replaceable model for flow characteristic"
         annotation(Evaluate = true, choices(CheckBox = true),Dialog(group="Characteristic curves"));
       replaceable function flowCharacteristic =
@@ -3550,7 +3428,7 @@
       replaceable model FlowCharacteristicModel =
           Functions.FanCharacteristics.Models.BaseFlow annotation (
          Dialog(group="Characteristic curves"), choicesAllMatching=true, enable = not useFlowCharacteristicModel);
-      // Power characteristic curves
+      // Power characteristic curves
       parameter Boolean usePowerCharacteristic=false
         "Use powerCharacteristic (vs. efficiencyCharacteristic)"
         annotation (Dialog(group="Characteristic curves"));
@@ -3560,7 +3438,7 @@
         "Power consumption vs. q_flow at nominal speed and density" annotation (
           Dialog(group="Characteristic curves", enable=usePowerCharacteristic),
           choicesAllMatching=true);
-      // Efficiency characteristic curves
+      // Efficiency characteristic curves
       replaceable function efficiencyCharacteristic =
           Functions.FanCharacteristics.constantEfficiency (eta_nom=0.8)
         constrainedby Functions.PumpCharacteristics.baseEfficiency
@@ -3670,88 +3548,64 @@
       annotation(Inline = true);
       end dH_dq;
 
-    equation
-      // Number of fans in parallel
+    equation
+// Number of fans in parallel
       Np = in_Np;
       if cardinality(in_Np) == 0 then
         in_Np = Np0 "Number of fans selected by parameter";
-      end if;
-
-      // Blade position
+      end if;
+// Blade position
       bladePos = in_bladePos;
       if cardinality(in_bladePos) == 0 then
         in_bladePos = bladePos0 "Blade position selected by parameter";
-      end if;
-
-      // Fluid properties (always uses the properties upstream of the inlet flange)
+      end if;
+// Fluid properties (always uses the properties upstream of the inlet flange)
       inletFluid.p = infl.p;
       inletFluid.h = inStream(infl.h_outflow);
       rho = inletFluid.d;
-      Tin = inletFluid.T;
-
-      // Flow equations
-      q_single = w_single/homotopy(rho, rho0);
-      H = dp/(homotopy(rho, rho0));
-      if noEvent(s > 0 or (not CheckValve)) then
-        // Flow characteristics when check valve is open
-        q_single = s;
-        H = homotopy(
-              if useFlowModel then
-                  (n/n0)^2*flowModel.flowCharacteristic(q_single*n0/(n + n_eps), bladePos)
-              else
-                  (n/n0)^2*flowCharacteristic(q_single*n0/(n + n_eps), bladePos),
-              H_start + dH_dq_start*(q_single - q_single_start) + dH_dn_start*(n - n_start));
-        else
-        // Flow characteristics when check valve is closed
-        q_single = 0;
-        H = homotopy(
-              if useFlowModel then
-                  (n/n0)^2*flowModel.flowCharacteristic(0, bladePos) - s
-              else
-                  (n/n0)^2*flowCharacteristic(0, bladePos - s),
-              H_start + dH_dn_start*(n - n_start) - s);
-      end if;
-
-      // Power consumption
-      if usePowerCharacteristic then
-        W_single = (n/n0)^3*(rho/rho0)*powerCharacteristic(q_single*n0/(n + n_eps),
-          bladePos) "Power consumption (single fan)";
-        eta = (dp*q_single)/(W_single + W_eps) "Hydraulic efficiency";
-      else
-        eta = efficiencyCharacteristic(q_single*n0/(n + n_eps), bladePos);
-        W_single = dp*q_single/eta;
-      end if;
-
-      // Boundary conditions
+      Tin = inletFluid.T;
+// Flow equations
+      q_single = w_single / homotopy(rho, rho0);
+      H = dp/(homotopy(rho, rho0));
+  if noEvent(s > 0 or not CheckValve) then
+// Flow characteristics when check valve is open
+        q_single = s;
+        H = homotopy(if useFlowModel then (n / n0) ^ 2 * flowModel.flowCharacteristic(q_single * n0 / (n + n_eps), bladePos) else (n / n0) ^ 2 * flowCharacteristic(q_single * n0 / (n + n_eps), bladePos), H_start + dH_dq_start * (q_single - q_single_start) + dH_dn_start * (n - n_start));
+      else
+// Flow characteristics when check valve is closed
+        q_single = 0;
+        H = homotopy(if useFlowModel then (n / n0) ^ 2 * flowModel.flowCharacteristic(0, bladePos) - s else (n / n0) ^ 2 * flowCharacteristic(0, bladePos - s), H_start + dH_dn_start * (n - n_start) - s);
+      end if;
+// Power consumption
+      if usePowerCharacteristic then
+        W_single = (n / n0) ^ 3 * (rho / rho0) * powerCharacteristic(q_single * n0 / (n + n_eps), bladePos) "Power consumption (single fan)";
+        eta = dp * q_single / (W_single + W_eps) "Hydraulic efficiency";
+      else
+        eta = efficiencyCharacteristic(q_single * n0 / (n + n_eps), bladePos);
+        W_single = dp * q_single / eta;
+      end if;
+// Boundary conditions
       dp = outfl.p - infl.p;
       w = infl.m_flow "Fan total flow rate";
       hin = homotopy(if not allowFlowReversal then inStream(infl.h_outflow) else
         if w >= 0 then inStream(infl.h_outflow) else h, inStream(infl.h_outflow));
       hout = homotopy(if not allowFlowReversal then h else if w >= 0 then h else
-        inStream(outfl.h_outflow), h);
-
-      // Mass balance
-      infl.m_flow + outfl.m_flow = 0 "Mass balance";
-
-      // Energy balance
-      if V > 0 then
-        (rho*V*der(h)) = (outfl.m_flow/Np)*hout + (infl.m_flow/Np)*hin + W_single
-          "Dynamic energy balance (single fan)";
-        outfl.h_outflow = h;
-        infl.h_outflow = h;
-      else
-        outfl.h_outflow = inStream(infl.h_outflow) + W_single/w
-          "Energy balance for w > 0";
-        infl.h_outflow = inStream(outfl.h_outflow) + W_single/w
-          "Energy balance for w < 0";
-        h = homotopy(if not allowFlowReversal then outfl.h_outflow else if w >= 0
-           then outfl.h_outflow else infl.h_outflow, outfl.h_outflow)
-          "Definition of h";
+        inStream(outfl.h_outflow), h);
+// Mass balance
+      infl.m_flow + outfl.m_flow = 0 "Mass balance";
+// Energy balance
+      if V > 0 then
+        rho * V * der(h) = outfl.m_flow / Np * hout + infl.m_flow / Np * hin + W_single "Dynamic energy balance (single fan)";
+        outfl.h_outflow = h;
+        infl.h_outflow = h;
+      else
+        outfl.h_outflow = inStream(infl.h_outflow) + W_single / w "Energy balance for w > 0";
+        infl.h_outflow = inStream(outfl.h_outflow) + W_single / w "Energy balance for w < 0";
+        h = homotopy(if not allowFlowReversal then outfl.h_outflow else if w >= 0 then outfl.h_outflow else infl.h_outflow, outfl.h_outflow) "Definition of h";
       end if;
-
     initial equation
       if initOpt == Choices.Init.Options.noInit then
-        // do nothing
+// do nothing
      elseif initOpt == Choices.Init.Options.fixedState then
        if V > 0 then
          h = hstart;
@@ -4163,8 +4017,7 @@
     if cardinality(in_w0) == 0 then
       in_w0 = w0 "Flow rate set by parameter";
     end if;
-
-    // Energy and partial mass balance
+// Energy and partial mass balance
     inlet.h_outflow = inStream(outlet.h_outflow);
     inStream(inlet.h_outflow) = outlet.h_outflow;
     inlet.Xi_outflow = inStream(outlet.Xi_outflow);
@@ -4265,8 +4118,8 @@
         Placement(transformation(extent={{-60,40},{60,60}}, rotation=0)));
   public
     Medium.BaseProperties gas[N] "Gas nodal properties";
-    // Xi(start=fill(Xstart[1:nXi],N)),
-    // X(start=fill(Xstart,N)),
+    // Xi(start=fill(Xstart[1:nXi],N)),
+    // X(start=fill(Xstart,N)),
     SI.Pressure Dpfric "Pressure drop due to friction";
     SI.Length omega_hyd "Wet perimeter (single tube)";
     Real Kf "Friction factor";
@@ -4312,10 +4165,10 @@
     Real dddX[N, nX](each unit="kg/m3") "Derivative of density by composition";
   equation
     assert(FFtype == FFtypes.NoFriction or dpnom > 0,
-      "dpnom=0 not supported, it is also used in the homotopy trasformation during the inizialization");
-    //All equations are referred to a single tube
-    // Friction factor selection
-    omega_hyd = 4*A/Dhyd;
+      "dpnom=0 not supported, it is also used in the homotopy trasformation during the inizialization");
+//All equations are referred to a single tube
+// Friction factor selection
+    omega_hyd = 4 * A / Dhyd;
     if FFtype == FFtypes.Kfnom then
       Kf = Kfnom*Kfc;
       Cf = 2*Kf*A^3/(omega_hyd*L);
@@ -4337,66 +4190,61 @@
       Kf = 0;
     end if;
     assert(Kf >= 0, "Negative friction coefficient");
-    Kfl = wnom/Nt*wnf*Kf "Linear friction factor";
-
-    // Dynamic momentum term
+    Kfl = wnom/Nt*wnf*Kf "Linear friction factor";
+// Dynamic momentum term
     dwdt = if DynamicMomentum and not QuasiStatic then der(w) else 0;
 
     sum(dMdt) = (infl.m_flow + outfl.m_flow)/Nt "Mass balance";
     L/A*dwdt + (outfl.p - infl.p) + Dpfric = 0 "Momentum balance";
     Dpfric = (if FFtype == FFtypes.NoFriction then 0 else homotopy((smooth(1,
       Kf*squareReg(w, wnom/Nt*wnf))*sum(vbar)/(N - 1)), dpnom/(wnom/Nt)*w))
-      "Pressure drop due to friction";
-    for j in 1:N - 1 loop
-      if not QuasiStatic then
-        // Dynamic mass and energy balances
-        A*l*rhobar[j]*cvbar[j]*der(Ttilde[j]) + wbar[j]*(gas[j + 1].h - gas[j].h)
-          = l*omega*phibar[j] "Energy balance";
-        dMdt[j] = A*l*(drbdp[j]*der(p) + drbdT1[j]*der(gas[j].T) + drbdT2[j]*
-          der(gas[j + 1].T) + vector(drbdX1[j, :])*vector(der(gas[j].X)) +
-          vector(drbdX2[j, :])*vector(der(gas[j + 1].X))) "Mass balance";
-        /*
+      "Pressure drop due to friction";
+  for j in 1:N - 1 loop
+      if not QuasiStatic then
+// Dynamic mass and energy balances
+        A * l * rhobar[j] * cvbar[j] * der(Ttilde[j]) + wbar[j] * (gas[j + 1].h - gas[j].h) = l * omega * phibar[j] "Energy balance";
+        dMdt[j] = A * l * (drbdp[j] * der(p) + drbdT1[j] * der(gas[j].T) + drbdT2[j] * der(gas[j + 1].T) + vector(drbdX1[j, :]) * vector(der(gas[j].X)) + vector(drbdX2[j, :]) * vector(der(gas[j + 1].X))) "Mass balance";
+/*
       dMdt[j] = A*l*(drbdT[j]*der(Ttilde[j]) + drbdp[j]*der(p) + vector(drbdX[j, :])*
       vector(der(Xtilde[if UniformComposition then 1 else j, :])))
       "Mass balance";
-*/
-        // Average volume quantities
-        if avoidInletEnthalpyDerivative and j == 1 then
-          // first volume properties computed by the volume outlet properties
-          rhobar[j] = gas[j + 1].d;
-          drbdp[j] = dddp[j + 1];
-          drbdT1[j] = 0;
-          drbdT2[j] = dddT[j + 1];
-          drbdX1[j, :] = zeros(size(Xtilde, 2));
-          drbdX2[j, :] = dddX[j + 1, :];
-        else
-          // volume properties computed by averaging
-          rhobar[j] = (gas[j].d + gas[j + 1].d)/2;
-          drbdp[j] = (dddp[j] + dddp[j + 1])/2;
-          drbdT1[j] = dddT[j]/2;
-          drbdT2[j] = dddT[j + 1]/2;
-          drbdX1[j, :] = dddX[j, :]/2;
-          drbdX2[j, :] = dddX[j + 1, :]/2;
-        end if;
-        vbar[j] = 1/rhobar[j];
-        wbar[j] = homotopy(infl.m_flow/Nt - sum(dMdt[1:j - 1]) - dMdt[j]/2,
-          wnom/Nt);
-        cvbar[j] = (cv[j] + cv[j + 1])/2;
-      else
-        // Static mass and energy balances
-        wbar[j]*(gas[j + 1].h - gas[j].h) = l*omega*phibar[j] "Energy balance";
-        dMdt[j] = 0 "Mass balance";
-        // Dummy values for unused average quantities
-        rhobar[j] = 0;
-        drbdp[j] = 0;
-        drbdT1[j] = 0;
-        drbdT2[j] = 0;
-        drbdX1[j, :] = zeros(nX);
-        drbdX2[j, :] = zeros(nX);
-        vbar[j] = 0;
-        wbar[j] = infl.m_flow/Nt;
-        cvbar[j] = 0;
-      end if;
+*/
+// Average volume quantities
+        if avoidInletEnthalpyDerivative and j == 1 then
+// first volume properties computed by the volume outlet properties
+          rhobar[j] = gas[j + 1].d;
+          drbdp[j] = dddp[j + 1];
+          drbdT1[j] = 0;
+          drbdT2[j] = dddT[j + 1];
+          drbdX1[j, :] = zeros(size(Xtilde, 2));
+          drbdX2[j, :] = dddX[j + 1, :];
+        else
+// volume properties computed by averaging
+          rhobar[j] = (gas[j].d + gas[j + 1].d) / 2;
+          drbdp[j] = (dddp[j] + dddp[j + 1]) / 2;
+          drbdT1[j] = dddT[j] / 2;
+          drbdT2[j] = dddT[j + 1] / 2;
+          drbdX1[j, :] = dddX[j, :] / 2;
+          drbdX2[j, :] = dddX[j + 1, :] / 2;
+        end if;
+        vbar[j] = 1 / rhobar[j];
+        wbar[j] = homotopy(infl.m_flow / Nt - sum(dMdt[1:j - 1]) - dMdt[j] / 2, wnom / Nt);
+        cvbar[j] = (cv[j] + cv[j + 1]) / 2;
+      else
+// Static mass and energy balances
+        wbar[j] * (gas[j + 1].h - gas[j].h) = l * omega * phibar[j] "Energy balance";
+        dMdt[j] = 0 "Mass balance";
+// Dummy values for unused average quantities
+        rhobar[j] = 0;
+        drbdp[j] = 0;
+        drbdT1[j] = 0;
+        drbdT2[j] = 0;
+        drbdX1[j, :] = zeros(nX);
+        drbdX2[j, :] = zeros(nX);
+        vbar[j] = 0;
+        wbar[j] = infl.m_flow / Nt;
+        cvbar[j] = 0;
+      end if;
     end for;
     Q = Nt*l*omega*sum(phibar) "Total heat flow through the lateral boundary";
     if Medium.fixedX then
@@ -4417,35 +4265,33 @@
     for j in 1:N loop
       u[j] = w/(gas[j].d*A) "Gas velocity";
       gas[j].p = p;
-    end for;
-    // Fluid property computations
-    for j in 1:N loop
-      if not QuasiStatic then
-        cv[j] = Medium.heatCapacity_cv(gas[j].state);
-        dddT[j] = Medium.density_derT_p(gas[j].state);
-        dddp[j] = Medium.density_derp_T(gas[j].state);
-        if nX > 0 then
-          dddX[j, :] = Medium.density_derX(gas[j].state);
-        end if;
-      else
-        // Dummy values (not needed by dynamic equations)
-        cv[j] = 0;
-        dddT[j] = 0;
-        dddp[j] = 0;
-        dddX[j, :] = zeros(nX);
-      end if;
-    end for;
-
-    // Selection of representative pressure and flow rate variables
-    if HydraulicCapacitance == HCtypes.Upstream then
-      p = infl.p;
-      w = -outfl.m_flow/Nt;
-    else
-      p = outfl.p;
-      w = infl.m_flow/Nt;
-    end if;
-
-    // Boundary conditions
+    end for;
+// Fluid property computations
+    for j in 1:N loop
+      if not QuasiStatic then
+        cv[j] = Medium.heatCapacity_cv(gas[j].state);
+        dddT[j] = Medium.density_derT_p(gas[j].state);
+        dddp[j] = Medium.density_derp_T(gas[j].state);
+        if nX > 0 then
+          dddX[j, :] = Medium.density_derX(gas[j].state);
+        end if;
+      else
+// Dummy values (not needed by dynamic equations)
+        cv[j] = 0;
+        dddT[j] = 0;
+        dddp[j] = 0;
+        dddX[j, :] = zeros(nX);
+      end if;
+    end for;
+// Selection of representative pressure and flow rate variables
+    if HydraulicCapacitance == HCtypes.Upstream then
+      p = infl.p;
+      w = -outfl.m_flow / Nt;
+    else
+      p = outfl.p;
+      w = infl.m_flow / Nt;
+    end if;
+// Boundary conditions
     infl.h_outflow = gas[1].h;
     outfl.h_outflow = gas[N].h;
     infl.Xi_outflow = gas[1].Xi;
@@ -4484,7 +4330,7 @@
       "Residence time";
   initial equation
     if initOpt == Choices.Init.Options.noInit or QuasiStatic then
-      // do nothing
+// do nothing
     elseif initOpt == Choices.Init.Options.steadyState then
       if (not Medium.singleState) then
         der(p) = 0;
diff -ur "/home/hudson/saved_omc/libraries/.openmodelica/libraries/ThermoPower 3.1.0-master/Media.mo" "converted-libraries/.openmodelica/libraries/ThermoPower 3.1.0-master/Media.mo"
--- "/home/hudson/saved_omc/libraries/.openmodelica/libraries/ThermoPower 3.1.0-master/Media.mo"	2022-03-10 09:57:37.952144121 +0000
+++ "converted-libraries/.openmodelica/libraries/ThermoPower 3.1.0-master/Media.mo"	2022-03-10 09:59:03.428154946 +0000
@@ -7,7 +7,7 @@
     redeclare record extends ThermodynamicState
       AbsolutePressure p;
       Temperature T;
-      // MassFraction X[nXi];
+      // MassFraction X[nXi];
     end ThermodynamicState;
   end GenericGas;
 
diff -ur "/home/hudson/saved_omc/libraries/.openmodelica/libraries/ThermoPower 3.1.0-master/PowerPlants.mo" "converted-libraries/.openmodelica/libraries/ThermoPower 3.1.0-master/PowerPlants.mo"
--- "/home/hudson/saved_omc/libraries/.openmodelica/libraries/ThermoPower 3.1.0-master/PowerPlants.mo"	2022-03-10 09:57:37.952144121 +0000
+++ "converted-libraries/.openmodelica/libraries/ThermoPower 3.1.0-master/PowerPlants.mo"	2022-03-10 09:59:03.408154944 +0000
@@ -137,40 +137,40 @@
       model GasTurbineSimplified
         extends
           ThermoPower.PowerPlants.GasTurbine.Interfaces.GasTurbineSimplified;
-        parameter Modelica.SIunits.Power maxPower=235e6;
-        parameter Modelica.SIunits.MassFlowRate flueGasNomFlowRate=614
+        parameter Modelica.Units.SI.Power maxPower=235e6;
+        parameter Modelica.Units.SI.MassFlowRate flueGasNomFlowRate=614
           "Nominal flue gas flow rate";
-        parameter Modelica.SIunits.MassFlowRate flueGasMinFlowRate=454
+        parameter Modelica.Units.SI.MassFlowRate flueGasMinFlowRate=454
           "Minimum flue gas flow rate";
-        parameter Modelica.SIunits.MassFlowRate flueGasOffFlowRate=
+        parameter Modelica.Units.SI.MassFlowRate flueGasOffFlowRate=
             flueGasMinFlowRate/100 "Flue gas flow rate with GT switched off";
-        parameter Modelica.SIunits.MassFlowRate fuelNomFlowRate=12.1
+        parameter Modelica.Units.SI.MassFlowRate fuelNomFlowRate=12.1
           "Nominal fuel flow rate";
-        parameter Modelica.SIunits.MassFlowRate fuelIntFlowRate=7.08
+        parameter Modelica.Units.SI.MassFlowRate fuelIntFlowRate=7.08
           "Intermediate fuel flow rate";
-        parameter Modelica.SIunits.MassFlowRate fuelMinFlowRate=4.58
+        parameter Modelica.Units.SI.MassFlowRate fuelMinFlowRate=4.58
           "Minimum fuel flow rate";
-        parameter Modelica.SIunits.MassFlowRate fuelOffFlowRate=0.1
+        parameter Modelica.Units.SI.MassFlowRate fuelOffFlowRate=0.1
           "Flue gas flow rate with GT switched off";
         parameter Real constTempLoad=0.60
           "Fraction of load from which the temperature is kept constant";
         parameter Real intLoad=0.42
           "Intermediate load for fuel consumption computations";
-        parameter Modelica.SIunits.Temperature flueGasNomTemp=843
+        parameter Modelica.Units.SI.Temperature flueGasNomTemp=843
           "Maximum flue gas temperature";
-        parameter Modelica.SIunits.Temperature flueGasMinTemp=548
+        parameter Modelica.Units.SI.Temperature flueGasMinTemp=548
           "Minimum flue gas temperature (zero electrical load)";
-        parameter Modelica.SIunits.Temperature flueGasOffTemp=363.15
+        parameter Modelica.Units.SI.Temperature flueGasOffTemp=363.15
           "Flue gas temperature with GT switched off";
-        parameter Modelica.SIunits.SpecificEnthalpy fuel_LHV=49e6
+        parameter Modelica.Units.SI.SpecificEnthalpy fuel_LHV=49e6
           "Fuel Lower Heating Value";
-        parameter Modelica.SIunits.SpecificEnthalpy fuel_HHV=55e6
+        parameter Modelica.Units.SI.SpecificEnthalpy fuel_HHV=55e6
           "Fuel Higher Heating Value";
         FlueGasMedium.BaseProperties gas;
-        Modelica.SIunits.MassFlowRate w;
-        Modelica.SIunits.Power P_el=noEvent(if GTLoad > 0 then GTLoad*maxPower
+        Modelica.Units.SI.MassFlowRate w;
+        Modelica.Units.SI.Power P_el=noEvent(if GTLoad > 0 then GTLoad*maxPower
              else 0) "Electrical power output";
-        Modelica.SIunits.MassFlowRate fuelFlowRate "Fuel flow rate";
+        Modelica.Units.SI.MassFlowRate fuelFlowRate "Fuel flow rate";
       equation
         gas.p = flueGasOut.p;
         gas.Xi = FlueGasMedium.reference_X[1:FlueGasMedium.nXi];
@@ -256,7 +256,7 @@
           "Number of volumes of the fluid side wall";
         parameter Integer Nt = 1 "Number of tubes in parallel";
 
-        //Nominal parameter
+//Nominal parameter
         parameter SI.MassFlowRate gasNomFlowRate
           "Nominal flow rate through the gas side";
         parameter SI.MassFlowRate fluidNomFlowRate
@@ -266,7 +266,7 @@
         parameter SI.Pressure fluidNomPressure
           "Nominal pressure in the fluid side inlet";
 
-        //Physical Parameter
+//Physical Parameter
         parameter SI.Area exchSurface_G
           "Exchange surface between gas - metal tube";
         parameter SI.Area exchSurface_F
@@ -279,7 +279,7 @@
         parameter SI.ThermalConductivity lambda
           "Thermal conductivity of the metal (density by specific heat capacity)";
 
-        //Start value
+//Start value
         parameter SI.Temperature Tstartbar_G
           "Start value of the average gas temperature"
           annotation (Dialog(tab="Initialization"));
@@ -356,7 +356,7 @@
         parameter Integer Nw_F_B=N_F_B - 1
           "Number of volumes of the fluid side wall"
           annotation (Dialog(group="side B"));
-        //Nominal parameter
+        //Nominal parameter
         parameter SI.MassFlowRate gasNomFlowRate
           "Nominal flow rate through the gas side";
         parameter SI.MassFlowRate fluidNomFlowRate_A
@@ -374,7 +374,7 @@
           "Nominal pressure in the fluid side inlet"
           annotation (Dialog(group="side B"));
 
-        //Physical Parameter
+//Physical Parameter
         parameter SI.Area exchSurface_G_A
           "Exchange surface between gas - metal tube,"
           annotation (Dialog(group="side A"));
@@ -407,20 +407,20 @@
         parameter SI.ThermalConductivity lambda
           "Thermal conductivity of the metal (density by specific heat capacity)";
 
-        //Initialization
+//Initialization
         parameter SI.Temperature Tstartbar_G
           "Start value of the average gas temperature"
           annotation (Dialog(tab="Initialization"));
         parameter SI.Pressure pstart_G=gasNomPressure
           "Pressure start value, gas side"
           annotation (Dialog(tab="Initialization"));
-        //A
+        //A
         parameter SI.Temperature Tstartbar_M_A=Tstartbar_G - 50
           "Start value of the average metal temperature"
           annotation (Dialog(tab="Initialization", group="side A"));
         parameter SI.Pressure pstart_F_A=50e5 "Pressure start value"
           annotation (Dialog(tab="Initialization", group="side A"));
-        //B
+        //B
         parameter SI.Temperature Tstartbar_M_B=Tstartbar_G - 50
           "Start value of the average metal temperature"
           annotation (Dialog(tab="Initialization", group="side B"));
@@ -485,7 +485,7 @@
         replaceable package FluidMedium = ThermoPower.Water.StandardWater
           constrainedby Modelica.Media.Interfaces.PartialPureSubstance;
 
-        //Nominal parameter
+//Nominal parameter
         parameter SI.MassFlowRate gasNomFlowRate
           "Nominal flow rate through the gas side";
         parameter SI.MassFlowRate fluidNomFlowRate_A
@@ -503,11 +503,11 @@
           "Nominal pressure in the fluid side inlet"
           annotation (Dialog(group="side B"));
 
-        //Other common parameter
+//Other common parameter
         parameter SI.ThermalConductivity lambda
           "Thermal conductivity of the metal (density by specific heat capacity)";
 
-        //Parameter for first parallel heat exchangers
+//Parameter for first parallel heat exchangers
         parameter Integer N_G_p1=2 "Number of node of the gas side"
           annotation (Dialog(tab="pHE-1"));
         parameter Integer Nw_G_p1=N_G_p1 - 1
@@ -523,7 +523,7 @@
         parameter Integer Nw_F_B_p1=N_F_B_p1 - 1
           "Number of volumes of the fluid side wall"
           annotation (Dialog(tab="pHE-1"));
-        //Physical Parameter
+        //Physical Parameter
         parameter SI.Area exchSurface_G_A_p1
           "Exchange surface between gas - metal tube,"
           annotation (Dialog(tab="pHE-1", group="side A"));
@@ -561,7 +561,7 @@
           "Metal heat capacity per unit volume [J/m^3.K]"
           annotation (Dialog(tab="pHE-1", group="side B"));
 
-        //Parameter for second parallel heat exchangers
+//Parameter for second parallel heat exchangers
         parameter Integer N_G_p2=2 "Number of node of the gas side"
           annotation (Dialog(tab="pHE-2"));
         parameter Integer Nw_G_p2=N_G_p2 - 1
@@ -577,7 +577,7 @@
         parameter Integer Nw_F_B_p2=N_F_B_p2 - 1
           "Number of volumes of the fluid side wall"
           annotation (Dialog(tab="pHE-2"));
-        //Physical Parameter
+        //Physical Parameter
         parameter SI.Area exchSurface_G_A_p2
           "Exchange surface between gas - metal tube,"
           annotation (Dialog(tab="pHE-2", group="side A"));
@@ -615,44 +615,44 @@
           "Metal heat capacity per unit volume [J/m^3.K]"
           annotation (Dialog(tab="pHE-2", group="side B"));
 
-        //Initialization
+//Initialization
         parameter Boolean SSInit=false "Steady-state initialization"
           annotation (Dialog(tab="Initialization"));
 
-        //Start value pHE1
+//Start value pHE1
         parameter SI.Temperature Tstartbar_G_p1
           "Start value of the averaget gas temperature"
           annotation (Dialog(tab="Initialization (pHE-1)"));
         parameter SI.Pressure pstart_G_p1=gasNomPressure
           "Pressure start value, gas side"
           annotation (Dialog(tab="Initialization (pHE-1)"));
-        //A
+        //A
         parameter SI.Temperature Tstartbar_M_A_p1=Tstartbar_G_p1 - 50
           "Start value of the averaget metal temperature"
           annotation (Dialog(tab="Initialization (pHE-1)", group="side A"));
         parameter SI.Pressure pstart_F_A_p1=1e5 "Pressure start value"
           annotation (Dialog(tab="Initialization (pHE-1)", group="side A"));
-        //B
+        //B
         parameter SI.Temperature Tstartbar_M_B_p1=Tstartbar_G_p1 - 50
           "Start value of the averaget metal temperature"
           annotation (Dialog(tab="Initialization (pHE-1)", group="side B"));
         parameter SI.Pressure pstart_F_B_p1=1e5 "Pressure start value"
           annotation (Dialog(tab="Initialization (pHE-1)", group="side B"));
 
-        //Start value pHE2
+//Start value pHE2
         parameter SI.Temperature Tstartbar_G_p2
           "Start value of the averaget gas temperature"
           annotation (Dialog(tab="Initialization (pHE-2)"));
         parameter SI.Pressure pstart_G_p2=gasNomPressure
           "Pressure start value, gas side"
           annotation (Dialog(tab="Initialization (pHE-2)"));
-        //A
+        //A
         parameter SI.Temperature Tstartbar_M_A_p2=Tstartbar_G_p2 - 50
           "Start value of the averaget metal temperature"
           annotation (Dialog(tab="Initialization (pHE-2)", group="side A"));
         parameter SI.Pressure pstart_F_A_p2=1e5 "Pressure start value"
           annotation (Dialog(tab="Initialization (pHE-2)", group="side A"));
-        //B
+        //B
         parameter SI.Temperature Tstartbar_M_B_p2=Tstartbar_G_p2 - 50
           "Start value of the averaget metal temperature"
           annotation (Dialog(tab="Initialization (pHE-2)", group="side B"));
@@ -700,13 +700,13 @@
         replaceable package FluidMedium = ThermoPower.Water.StandardWater
           constrainedby Modelica.Media.Interfaces.PartialPureSubstance;
 
-        //Common Parameter
+//Common Parameter
         parameter SI.MassFlowRate gasNomFlowRate
           "Nominal flow rate through the gas side";
         parameter SI.Pressure gasNomPressure
           "Nominal pressure in the gas side inlet";
 
-        //Nominal parameter
+//Nominal parameter
         parameter SI.MassFlowRate fluidHPNomFlowRate_Sh "Nominal mass flowrate"
           annotation (Dialog(tab="HP", group="Sh"));
         parameter SI.Pressure fluidHPNomPressure_Sh "Nominal pressure"
@@ -732,8 +732,8 @@
         parameter SI.Pressure fluidLPNomPressure_Ec "Nominal pressure"
           annotation (Dialog(tab="LP", group="Ec"));
 
-        //Physical Parameter
-        //Sh2_HP
+//Physical Parameter
+        //Sh2_HP
         parameter Integer Sh2_HP_N_G=2 "Number of node of the gas side, Sh2"
           annotation (Dialog(tab="HP", group="Sh"));
         parameter Integer Sh2_HP_N_F=2 "Number of node of the fluid side, Sh2"
@@ -754,7 +754,7 @@
         parameter SI.Volume Sh2_HP_metalVol
           "Volume of the metal part in the tube, Sh2"
           annotation (Dialog(tab="HP", group="Sh"));
-        //Sh1_HP
+        //Sh1_HP
         parameter Integer Sh1_HP_N_G=2 "Number of node of the gas side, Sh1"
           annotation (Dialog(tab="HP", group="Sh"));
         parameter Integer Sh1_HP_N_F=2 "Number of node of the fluid side, Sh1"
@@ -775,7 +775,7 @@
         parameter SI.Volume Sh1_HP_metalVol
           "Volume of the metal part in the tube, Sh1"
           annotation (Dialog(tab="HP", group="Sh"));
-        //Ev_HP
+        //Ev_HP
         parameter Integer Ev_HP_N_G=2 "Number of node of the gas side"
           annotation (Dialog(tab="HP", group="Ev"));
         parameter Integer Ev_HP_N_F=2 "Number of node of the fluid side"
@@ -796,7 +796,7 @@
         parameter SI.Volume Ev_HP_metalVol
           "Volume of the metal part in the tube"
           annotation (Dialog(tab="HP", group="Ev"));
-        //Ec_HP
+        //Ec_HP
         parameter Integer Ec_HP_N_G=2 "Number of node of the gas side"
           annotation (Dialog(tab="HP", group="Ec"));
         parameter Integer Ec_HP_N_F=2 "Number of node of the fluid side"
@@ -817,7 +817,7 @@
         parameter SI.Volume Ec_HP_metalVol
           "Volume of the metal part in the tube"
           annotation (Dialog(tab="HP", group="Ec"));
-        //Sh_LP
+        //Sh_LP
         parameter Integer Sh_LP_N_G=2 "Number of node of the gas side"
           annotation (Dialog(tab="LP", group="Sh"));
         parameter Integer Sh_LP_N_F=2 "Number of node of the fluid side"
@@ -838,7 +838,7 @@
         parameter SI.Volume Sh_LP_metalVol
           "Volume of the metal part in the tube"
           annotation (Dialog(tab="LP", group="Sh"));
-        //Ev_LP
+        //Ev_LP
         parameter Integer Ev_LP_N_G=2 "Number of node of the gas side"
           annotation (Dialog(tab="LP", group="Ev"));
         parameter Integer Ev_LP_N_F=2 "Number of node of the fluid side"
@@ -859,7 +859,7 @@
         parameter SI.Volume Ev_LP_metalVol
           "Volume of the metal part in the tube"
           annotation (Dialog(tab="LP", group="Ev"));
-        //Ec_LP
+        //Ec_LP
         parameter Integer Ec_LP_N_G=2 "Number of node of the gas side"
           annotation (Dialog(tab="LP", group="Ec"));
         parameter Integer Ec_LP_N_F=2 "Number of node of the fluid side"
@@ -881,42 +881,42 @@
           "Volume of the metal part in the tube"
           annotation (Dialog(tab="LP", group="Ec"));
 
-        //Initialization conditions
+//Initialization conditions
         parameter Boolean SSInit=false "Steady-state initialization"
           annotation (Dialog(tab="Initialization Conditions"));
 
-        //Start values
-        //Sh2_HP
+//Start values
+        //Sh2_HP
         parameter SI.Temperature Sh2_HP_Tstartbar
           "Start value of the average gas temperature - Sh2"
           annotation (Dialog(tab="Initialization (HP)", group="Sh"));
 
-        //Sh1_HP
+//Sh1_HP
         parameter SI.Temperature Sh1_HP_Tstartbar
           "Start value of the average gas temperature - Sh1"
           annotation (Dialog(tab="Initialization (HP)", group="Sh"));
 
-        //Ev_HP
+//Ev_HP
         parameter SI.Temperature Ev_HP_Tstartbar
           "Start value of the average gas temperature"
           annotation (Dialog(tab="Initialization (HP)", group="Ev"));
 
-        //Ec_HP
+//Ec_HP
         parameter SI.Temperature Ec_HP_Tstartbar
           "Start value of the average gas temperature"
           annotation (Dialog(tab="Initialization (HP)", group="Ec"));
 
-        //Sh_LP
+//Sh_LP
         parameter SI.Temperature Sh_LP_Tstartbar
           "Start value of the average gas temperature"
           annotation (Dialog(tab="Initialization (LP)", group="Sh"));
 
-        //Ev_LP
+//Ev_LP
         parameter SI.Temperature Ev_LP_Tstartbar
           "Start value of the average gas temperature"
           annotation (Dialog(tab="Initialization (LP)", group="Ev"));
 
-        //Ec_LP
+//Ec_LP
         parameter SI.Temperature Ec_LP_Tstartbar
           "Start value of the average gas temperature"
           annotation (Dialog(tab="Initialization (LP)", group="Ec"));
@@ -1060,13 +1060,13 @@
         replaceable package FluidMedium = ThermoPower.Water.StandardWater
           constrainedby Modelica.Media.Interfaces.PartialPureSubstance;
 
-        //Common Parameter
+//Common Parameter
         parameter SI.MassFlowRate gasNomFlowRate
           "Nominal flow rate through the gas side";
         parameter SI.Pressure gasNomPressure
           "Nominal pressure in the gas side inlet";
 
-        //Nominal parameter
+//Nominal parameter
         parameter SI.MassFlowRate fluidHPNomFlowRate_Sh "Nominal mass flowrate"
           annotation (Dialog(tab="HP", group="Sh"));
         parameter SI.Pressure fluidHPNomPressure_Sh "Nominal pressure"
@@ -1092,8 +1092,8 @@
         parameter SI.Pressure fluidLPNomPressure_Ec "Nominal pressure"
           annotation (Dialog(tab="LP", group="Ec"));
 
-        //Physical Parameter
-        //Sh2_HP
+//Physical Parameter
+        //Sh2_HP
         parameter Integer Sh2_HP_N_G=2 "Number of node of the gas side, Sh2"
           annotation (Dialog(tab="HP", group="Sh"));
         parameter Integer Sh2_HP_N_F=2 "Number of node of the fluid side, Sh2"
@@ -1114,7 +1114,7 @@
         parameter SI.Volume Sh2_HP_metalVol
           "Volume of the metal part in the tube, Sh2"
           annotation (Dialog(tab="HP", group="Sh"));
-        //Sh1_HP
+        //Sh1_HP
         parameter Integer Sh1_HP_N_G=2 "Number of node of the gas side, Sh1"
           annotation (Dialog(tab="HP", group="Sh"));
         parameter Integer Sh1_HP_N_F=2 "Number of node of the fluid side, Sh1"
@@ -1135,7 +1135,7 @@
         parameter SI.Volume Sh1_HP_metalVol
           "Volume of the metal part in the tube, Sh1"
           annotation (Dialog(tab="HP", group="Sh"));
-        //Ev_HP
+        //Ev_HP
         parameter Integer Ev_HP_N_G=2 "Number of node of the gas side"
           annotation (Dialog(tab="HP", group="Ev"));
         parameter Integer Ev_HP_N_F=2 "Number of node of the fluid side"
@@ -1156,7 +1156,7 @@
         parameter SI.Volume Ev_HP_metalVol
           "Volume of the metal part in the tube"
           annotation (Dialog(tab="HP", group="Ev"));
-        //Ec_HP
+        //Ec_HP
         parameter Integer Ec_HP_N_G=2 "Number of node of the gas side"
           annotation (Dialog(tab="HP", group="Ec"));
         parameter Integer Ec_HP_N_F=2 "Number of node of the fluid side"
@@ -1177,7 +1177,7 @@
         parameter SI.Volume Ec_HP_metalVol
           "Volume of the metal part in the tube"
           annotation (Dialog(tab="HP", group="Ec"));
-        //Rh2_IP
+        //Rh2_IP
         parameter Integer Rh2_IP_N_G=2 "Number of node of the gas side, Rh2"
           annotation (Dialog(tab="IP", group="Rh"));
         parameter Integer Rh2_IP_N_F=2 "Number of node of the fluid side, Rh2"
@@ -1198,7 +1198,7 @@
         parameter SI.Volume Rh2_IP_metalVol
           "Volume of the metal part in the tube, Rh2"
           annotation (Dialog(tab="IP", group="Rh"));
-        //Rh1_IP
+        //Rh1_IP
         parameter Integer Rh1_IP_N_G=2 "Number of node of the gas side, Rh1"
           annotation (Dialog(tab="IP", group="Rh"));
         parameter Integer Rh1_IP_N_F=2 "Number of node of the fluid side, Rh1"
@@ -1219,7 +1219,7 @@
         parameter SI.Volume Rh1_IP_metalVol
           "Volume of the metal part in the tube, Rh1"
           annotation (Dialog(tab="IP", group="Rh"));
-        //Sh_LP
+        //Sh_LP
         parameter Integer Sh_LP_N_G=2 "Number of node of the gas side"
           annotation (Dialog(tab="LP", group="Sh"));
         parameter Integer Sh_LP_N_F=2 "Number of node of the fluid side"
@@ -1240,7 +1240,7 @@
         parameter SI.Volume Sh_LP_metalVol
           "Volume of the metal part in the tube"
           annotation (Dialog(tab="LP", group="Sh"));
-        //Ev_LP
+        //Ev_LP
         parameter Integer Ev_LP_N_G=2 "Number of node of the gas side"
           annotation (Dialog(tab="LP", group="Ev"));
         parameter Integer Ev_LP_N_F=2 "Number of node of the fluid side"
@@ -1261,7 +1261,7 @@
         parameter SI.Volume Ev_LP_metalVol
           "Volume of the metal part in the tube"
           annotation (Dialog(tab="LP", group="Ev"));
-        //Ec_LP
+        //Ec_LP
         parameter Integer Ec_LP_N_G=2 "Number of node of the gas side"
           annotation (Dialog(tab="LP", group="Ec"));
         parameter Integer Ec_LP_N_F=2 "Number of node of the fluid side"
@@ -1283,52 +1283,52 @@
           "Volume of the metal part in the tube"
           annotation (Dialog(tab="LP", group="Ec"));
 
-        //Initialization conditions
+//Initialization conditions
         parameter Boolean SSInit=false "Steady-state initialization"
           annotation (Dialog(tab="Initialization Conditions"));
 
-        //Start values
-        //Sh2_HP
+//Start values
+        //Sh2_HP
         parameter SI.Temperature Sh2_HP_Tstartbar
           "Start value of the average gas temperature - Sh2"
           annotation (Dialog(tab="Initialization (HP)", group="Sh"));
 
-        //Sh1_HP
+//Sh1_HP
         parameter SI.Temperature Sh1_HP_Tstartbar
           "Start value of the average gas temperature - Sh1"
           annotation (Dialog(tab="Initialization (HP)", group="Sh"));
 
-        //Ev_HP
+//Ev_HP
         parameter SI.Temperature Ev_HP_Tstartbar
           "Start value of the average gas temperature"
           annotation (Dialog(tab="Initialization (HP)", group="Ev"));
 
-        //Ec_HP
+//Ec_HP
         parameter SI.Temperature Ec_HP_Tstartbar
           "Start value of the average gas temperature"
           annotation (Dialog(tab="Initialization (HP)", group="Ec"));
 
-        //Rh2_IP
+//Rh2_IP
         parameter SI.Temperature Rh2_IP_Tstartbar
           "Start value of the average gas temperature - Rh2"
           annotation (Dialog(tab="Initialization (IP)", group="Rh"));
 
-        //Rh1_HP
+//Rh1_HP
         parameter SI.Temperature Rh1_IP_Tstartbar
           "Start value of the average gas temperature - Rh1"
           annotation (Dialog(tab="Initialization (IP)", group="Rh"));
 
-        //Sh_LP
+//Sh_LP
         parameter SI.Temperature Sh_LP_Tstartbar
           "Start value of the average gas temperature"
           annotation (Dialog(tab="Initialization (LP)", group="Sh"));
 
-        //Ev_LP
+//Ev_LP
         parameter SI.Temperature Ev_LP_Tstartbar
           "Start value of the average gas temperature"
           annotation (Dialog(tab="Initialization (LP)", group="Ev"));
 
-        //Ec_LP
+//Ec_LP
         parameter SI.Temperature Ec_LP_Tstartbar
           "Start value of the average gas temperature"
           annotation (Dialog(tab="Initialization (LP)", group="Ec"));
@@ -1553,13 +1553,13 @@
         replaceable package FluidMedium = ThermoPower.Water.StandardWater
           constrainedby Modelica.Media.Interfaces.PartialPureSubstance;
 
-        //Common Parameter
+//Common Parameter
         parameter SI.MassFlowRate gasNomFlowRate
           "Nominal flow rate through the gas side";
         parameter SI.Pressure gasNomPressure
           "Nominal pressure in the gas side inlet";
 
-        //Nominal parameter
+//Nominal parameter
         parameter SI.MassFlowRate fluidHPNomFlowRate_Sh "Nominal mass flowrate"
           annotation (Dialog(tab="HP", group="Sh"));
         parameter SI.Pressure fluidHPNomPressure_Sh "Nominal pressure"
@@ -1601,8 +1601,8 @@
         parameter SI.Pressure fluidLPNomPressure_Ec "Nominal pressure"
           annotation (Dialog(tab="LP", group="Ec"));
 
-        //Physical Parameter
-        //Sh2_HP
+//Physical Parameter
+        //Sh2_HP
         parameter Integer Sh2_HP_N_G=2 "Number of node of the gas side, Sh2"
           annotation (Dialog(tab="HP", group="Sh"));
         parameter Integer Sh2_HP_Nw_G=Sh2_HP_N_G - 1
@@ -1629,7 +1629,7 @@
         parameter SI.Volume Sh2_HP_metalVol
           "Volume of the metal part in the tube, Sh2"
           annotation (Dialog(tab="HP", group="Sh"));
-        //Sh1_HP
+        //Sh1_HP
         parameter Integer Sh1_HP_N_G=2 "Number of node of the gas side, Sh1"
           annotation (Dialog(tab="HP", group="Sh"));
         parameter Integer Sh1_HP_Nw_G=Sh1_HP_N_G - 1
@@ -1656,7 +1656,7 @@
         parameter SI.Volume Sh1_HP_metalVol
           "Volume of the metal part in the tube, Sh1"
           annotation (Dialog(tab="HP", group="Sh"));
-        //Ev_HP
+        //Ev_HP
         parameter Integer Ev_HP_N_G=2 "Number of node of the gas side"
           annotation (Dialog(tab="HP", group="Ev"));
         parameter Integer Ev_HP_Nw_G=Ev_HP_N_G - 1
@@ -1683,7 +1683,7 @@
         parameter SI.Volume Ev_HP_metalVol
           "Volume of the metal part in the tube"
           annotation (Dialog(tab="HP", group="Ev"));
-        //Ec2_HP
+        //Ec2_HP
         parameter Integer Ec2_HP_N_G=2 "Number of node of the gas side, Ec2"
           annotation (Dialog(tab="HP", group="Ec"));
         parameter Integer Ec2_HP_Nw_G=Ec2_HP_N_G - 1
@@ -1710,7 +1710,7 @@
         parameter SI.Volume Ec2_HP_metalVol
           "Volume of the metal part in the tube, Ec2"
           annotation (Dialog(tab="HP", group="Ec"));
-        //Ec1_HP
+        //Ec1_HP
         parameter Integer Ec1_HP_N_G=2 "Number of node of the gas side, Ec1"
           annotation (Dialog(tab="HP", group="Ec"));
         parameter Integer Ec1_HP_Nw_G=Ec1_HP_N_G - 1
@@ -1737,7 +1737,7 @@
         parameter SI.Volume Ec1_HP_metalVol
           "Volume of the metal part in the tube, Ec1"
           annotation (Dialog(tab="HP", group="Ec"));
-        //Rh2_IP
+        //Rh2_IP
         parameter Integer Rh2_IP_N_G=2 "Number of node of the gas side, Rh2"
           annotation (Dialog(tab="IP", group="Rh"));
         parameter Integer Rh2_IP_Nw_G=Rh2_IP_N_G - 1
@@ -1764,7 +1764,7 @@
         parameter SI.Volume Rh2_IP_metalVol
           "Volume of the metal part in the tube, Rh2"
           annotation (Dialog(tab="IP", group="Rh"));
-        //Rh1_IP
+        //Rh1_IP
         parameter Integer Rh1_IP_N_G=2 "Number of node of the gas side, Rh1"
           annotation (Dialog(tab="IP", group="Rh"));
         parameter Integer Rh1_IP_Nw_G=Rh1_IP_N_G - 1
@@ -1791,7 +1791,7 @@
         parameter SI.Volume Rh1_IP_metalVol
           "Volume of the metal part in the tube, Rh1"
           annotation (Dialog(tab="IP", group="Rh"));
-        //Sh_IP
+        //Sh_IP
         parameter Integer Sh_IP_N_G=2 "Number of node of the gas side"
           annotation (Dialog(tab="IP", group="Sh"));
         parameter Integer Sh_IP_Nw_G=Sh_IP_N_G - 1
@@ -1818,7 +1818,7 @@
         parameter SI.Volume Sh_IP_metalVol
           "Volume of the metal part in the tube"
           annotation (Dialog(tab="IP", group="Sh"));
-        //Ev_IP
+        //Ev_IP
         parameter Integer Ev_IP_N_G=2 "Number of node of the gas side"
           annotation (Dialog(tab="IP", group="Ev"));
         parameter Integer Ev_IP_Nw_G=Ev_IP_N_G - 1
@@ -1845,7 +1845,7 @@
         parameter SI.Volume Ev_IP_metalVol
           "Volume of the metal part in the tube"
           annotation (Dialog(tab="IP", group="Ev"));
-        //Ec_IP
+        //Ec_IP
         parameter Integer Ec_IP_N_G=2 "Number of node of the gas side"
           annotation (Dialog(tab="IP", group="Ec"));
         parameter Integer Ec_IP_Nw_G=Ec_IP_N_G - 1
@@ -1872,7 +1872,7 @@
         parameter SI.Volume Ec_IP_metalVol
           "Volume of the metal part in the tube"
           annotation (Dialog(tab="IP", group="Ec"));
-        //Sh_LP
+        //Sh_LP
         parameter Integer Sh_LP_N_G=2 "Number of node of the gas side"
           annotation (Dialog(tab="LP", group="Sh"));
         parameter Integer Sh_LP_Nw_G=Sh_LP_N_G - 1
@@ -1899,7 +1899,7 @@
         parameter SI.Volume Sh_LP_metalVol
           "Volume of the metal part in the tube"
           annotation (Dialog(tab="LP", group="Sh"));
-        //Ev_LP
+        //Ev_LP
         parameter Integer Ev_LP_N_G=2 "Number of node of the gas side"
           annotation (Dialog(tab="LP", group="Ev"));
         parameter Integer Ev_LP_Nw_G=Ev_LP_N_G - 1
@@ -1926,7 +1926,7 @@
         parameter SI.Volume Ev_LP_metalVol
           "Volume of the metal part in the tube"
           annotation (Dialog(tab="LP", group="Ev"));
-        //Ec_LP
+        //Ec_LP
         parameter Integer Ec_LP_N_G=2 "Number of node of the gas side"
           annotation (Dialog(tab="LP", group="Ec"));
         parameter Integer Ec_LP_Nw_G=Ec_LP_N_G - 1
@@ -1954,76 +1954,76 @@
           "Volume of the metal part in the tube"
           annotation (Dialog(tab="LP", group="Ec"));
 
-        //Initialization conditions
+
+//Initialization conditions
         parameter Boolean SSInit=false "Steady-state initialization"
           annotation (Dialog(tab="Initialization Conditions"));
 
-        //Start values
-        //Sh2_HP
+//Start values
+        //Sh2_HP
         parameter SI.Temperature Sh2_HP_Tstartbar
           "Start value of the average gas temperature - Sh2"
           annotation (Dialog(tab="Initialization (HP)", group="Sh"));
 
-        //Sh1_HP
+//Sh1_HP
         parameter SI.Temperature Sh1_HP_Tstartbar
           "Start value of the average gas temperature - Sh1"
           annotation (Dialog(tab="Initialization (HP)", group="Sh"));
 
-        //Ev_HP
+//Ev_HP
         parameter SI.Temperature Ev_HP_Tstartbar
           "Start value of the average gas temperature"
           annotation (Dialog(tab="Initialization (HP)", group="Ev"));
 
-        //Ec2_HP
+//Ec2_HP
         parameter SI.Temperature Ec2_HP_Tstartbar
           "Start value of the average gas temperature - Ec2"
           annotation (Dialog(tab="Initialization (HP)", group="Ec"));
 
-        //Ec1_HP
+//Ec1_HP
         parameter SI.Temperature Ec1_HP_Tstartbar
           "Start value of the average gas temperature - Ec1"
           annotation (Dialog(tab="Initialization (HP)", group="Ec"));
 
-        //Rh2_IP
+//Rh2_IP
         parameter SI.Temperature Rh2_IP_Tstartbar
           "Start value of the average gas temperature - Rh2"
           annotation (Dialog(tab="Initialization (IP)", group="Rh"));
 
-        //Rh1_HP
+//Rh1_HP
         parameter SI.Temperature Rh1_IP_Tstartbar
           "Start value of the average gas temperature - Rh1"
           annotation (Dialog(tab="Initialization (IP)", group="Rh"));
 
-        //Sh_IP
+//Sh_IP
         parameter SI.Temperature Sh_IP_Tstartbar
           "Start value of the average gas temperature"
           annotation (Dialog(tab="Initialization (IP)", group="Sh"));
 
-        //Ev_IP
+//Ev_IP
         parameter SI.Temperature Ev_IP_Tstartbar
           "Start value of the average gas temperature"
           annotation (Dialog(tab="Initialization (IP)", group="Ev"));
 
-        //Ec_IP
+//Ec_IP
         parameter SI.Temperature Ec_IP_Tstartbar
           "Start value of the average gas temperature"
           annotation (Dialog(tab="Initialization (IP)", group="Ec"));
 
-        //Sh_LP
+//Sh_LP
         parameter SI.Temperature Sh_LP_Tstartbar
           "Start value of the average gas temperature"
           annotation (Dialog(tab="Initialization (LP)", group="Sh"));
 
-        //Ev_LP
+//Ev_LP
         parameter SI.Temperature Ev_LP_Tstartbar
           "Start value of the average gas temperature"
           annotation (Dialog(tab="Initialization (LP)", group="Ev"));
 
-        //Ec_LP
+//Ec_LP
         parameter SI.Temperature Ec_LP_Tstartbar
           "Start value of the average gas temperature"
           annotation (Dialog(tab="Initialization (LP)", group="Ec"));
-
         annotation (Icon(coordinateSystem(
               preserveAspectRatio=false,
               extent={{-500,-200},{500,200}},
@@ -2148,8 +2148,8 @@
         replaceable package FluidMedium = ThermoPower.Water.StandardWater
           constrainedby Modelica.Media.Interfaces.PartialPureSubstance;
 
-        //Charateristics
-        //HP drum
+//Charateristics
+        //HP drum
         parameter SI.Pressure fluidHPNomPressure "Nominal internal pressure"
           annotation (Dialog(group="HP drum"));
         parameter SI.Length HPd_rint "Internal radius"
@@ -2160,7 +2160,7 @@
         parameter SI.HeatCapacity HPd_Cm
           "Total Heat Capacity of the metal wall"
           annotation (Dialog(group="HP drum"));
-        //LP drum
+        //LP drum
         parameter SI.Pressure fluidLPNomPressure "Nominal internal pressure"
           annotation (Dialog(group="LP drum"));
         parameter SI.Length LPd_rint "Internal radius"
@@ -2172,17 +2172,17 @@
           "Total Heat Capacity of the metal wall"
           annotation (Dialog(group="LP drum"));
 
-        //Initialization
+//Initialization
         parameter Boolean SSInit=false "Steady-state initialisation"
           annotation (Dialog(tab="Initialisation"));
-        //HP drum
+        //HP drum
         parameter SI.Pressure HPd_pstart=fluidHPNomPressure
           "Pressure start value"
           annotation (Dialog(tab="Initialisation", group="HP drum"));
         parameter SI.Temperature HPd_Tmstart=300
           "Metal wall temperature start value"
           annotation (Dialog(tab="Initialisation", group="HP drum"));
-        //LP drum
+        //LP drum
         parameter SI.Pressure LPd_pstart=fluidLPNomPressure
           "Pressure start value"
           annotation (Dialog(tab="Initialisation", group="LP drum"));
@@ -2293,8 +2293,8 @@
         replaceable package FluidMedium = ThermoPower.Water.StandardWater
           constrainedby Modelica.Media.Interfaces.PartialPureSubstance;
 
-        //Charateristics
-        //HP drum
+//Charateristics
+        //HP drum
         parameter SI.Pressure fluidHPNomPressure "Nominal internal pressure"
           annotation (Dialog(group="HP drum"));
         parameter SI.Length HPd_rint "Internal radius"
@@ -2305,7 +2305,7 @@
         parameter SI.HeatCapacity HPd_Cm
           "Total Heat Capacity of the metal wall"
           annotation (Dialog(group="HP drum"));
-        //IP drum
+        //IP drum
         parameter SI.Pressure fluidIPNomPressure "Nominal internal pressure"
           annotation (Dialog(group="IP drum"));
         parameter SI.Length IPd_rint "Internal radius"
@@ -2316,7 +2316,7 @@
         parameter SI.HeatCapacity IPd_Cm
           "Total Heat Capacity of the metal wall"
           annotation (Dialog(group="IP drum"));
-        //LP drum
+        //LP drum
         parameter SI.Pressure fluidLPNomPressure "Nominal internal pressure"
           annotation (Dialog(group="LP drum"));
         parameter SI.Length LPd_rint "Internal radius"
@@ -2328,24 +2328,24 @@
           "Total Heat Capacity of the metal wall"
           annotation (Dialog(group="LP drum"));
 
-        //Initialization
+//Initialization
         parameter Boolean SSInit=false "Steady-state initialisation"
           annotation (Dialog(tab="Initialisation"));
-        //HP drum
+        //HP drum
         parameter SI.Pressure HPd_pstart=fluidHPNomPressure
           "Pressure start value"
           annotation (Dialog(tab="Initialisation", group="HP drum"));
         parameter SI.Temperature HPd_Tmstart=300
           "Metal wall temperature start value"
           annotation (Dialog(tab="Initialisation", group="HP drum"));
-        //IP drum
+        //IP drum
         parameter SI.Pressure IPd_pstart=fluidIPNomPressure
           "Pressure start value"
           annotation (Dialog(tab="Initialisation", group="IP drum"));
         parameter SI.Temperature IPd_Tmstart=300
           "Metal wall temperature start value"
           annotation (Dialog(tab="Initialisation", group="IP drum"));
-        //LP drum
+        //LP drum
         parameter SI.Pressure LPd_pstart=fluidLPNomPressure
           "Pressure start value"
           annotation (Dialog(tab="Initialisation", group="LP drum"));
@@ -2503,8 +2503,8 @@
         replaceable package FluidMedium = ThermoPower.Water.StandardWater
           constrainedby Modelica.Media.Interfaces.PartialPureSubstance;
 
-        //Charateristics
-        //HP drum
+//Charateristics
+        //HP drum
         parameter SI.Pressure fluidHPNomPressure "Nominal internal pressure"
           annotation (Dialog(group="HP drum"));
         parameter SI.Length HPd_rint "Internal radius"
@@ -2515,7 +2515,7 @@
         parameter SI.HeatCapacity HPd_Cm
           "Total Heat Capacity of the metal wall"
           annotation (Dialog(group="HP drum"));
-        //IP drum
+        //IP drum
         parameter SI.Pressure fluidIPNomPressure "Nominal internal pressure"
           annotation (Dialog(group="IP drum"));
         parameter SI.Length IPd_rint "Internal radius"
@@ -2526,7 +2526,7 @@
         parameter SI.HeatCapacity IPd_Cm
           "Total Heat Capacity of the metal wall"
           annotation (Dialog(group="IP drum"));
-        //LP drum
+        //LP drum
         parameter SI.Pressure fluidLPNomPressure "Nominal internal pressure"
           annotation (Dialog(group="LP drum"));
         parameter SI.Length LPd_rint "Internal radius"
@@ -2538,20 +2538,20 @@
           "Total Heat Capacity of the metal wall"
           annotation (Dialog(group="LP drum"));
 
-        //Initialization
+//Initialization
         parameter Boolean SSInit=false "Steady-state initialisation"
           annotation (Dialog(tab="Initialisation"));
-        //HP drum
+        //HP drum
         parameter SI.Pressure HPd_pstart=fluidHPNomPressure
           "Pressure start value"
           annotation (Dialog(tab="Initialisation", group="HP drum"));
 
-        //IP drum
+//IP drum
         parameter SI.Pressure IPd_pstart=fluidIPNomPressure
           "Pressure start value"
           annotation (Dialog(tab="Initialisation", group="IP drum"));
 
-        //LP drum
+//LP drum
         parameter SI.Pressure LPd_pstart=fluidLPNomPressure
           "Pressure start value"
           annotation (Dialog(tab="Initialisation", group="LP drum"));
@@ -3535,7 +3535,7 @@
           "Quasi-static model of the flue gas (mass, energy and momentum static balances";
         constant Real pi=Modelica.Constants.pi;
 
-        //Valves parameters
+//Valves parameters
         parameter Real Cv_valA "Cv (US) flow coefficient, valve A"
           annotation (Dialog(group="Desuperheater A"));
         parameter SI.Pressure pnom_valA "Nominal inlet pressure, valve A"
@@ -3817,8 +3817,7 @@
       equation
         inlet.m_flow + outlet.m_flow = 0 "Mass balance";
         inlet.p = outlet.p "No pressure drop";
-
-        // Boundary conditions
+// Boundary conditions
         inlet.h_outflow = inStream(outlet.h_outflow);
         inStream(inlet.h_outflow) = outlet.h_outflow;
         annotation (
@@ -3860,7 +3859,7 @@
         SI.MassFlowRate w "Mass flow rate";
         Medium.ThermodynamicState fluidState "Thermodynamic state of the fluid";
       equation
-        // Set fluid state
+// Set fluid state
         p = inlet.p;
         h = homotopy(if not allowFlowReversal then inStream(inlet.h_outflow)
            else actualStream(inlet.h_outflow), inStream(inlet.h_outflow));
@@ -3885,11 +3884,11 @@
                 rotation=0)));
       equation
         inlet.m_flow + outlet.m_flow = 0 "Mass balance";
-        inlet.p = outlet.p "Momentum balance";
-        // Energy balance
+        inlet.p = outlet.p "Momentum balance";
+// Energy balance
         inlet.h_outflow = inStream(outlet.h_outflow);
-        inStream(inlet.h_outflow) = outlet.h_outflow;
-        // Independent composition mass balances
+        inStream(inlet.h_outflow) = outlet.h_outflow;
+// Independent composition mass balances
         inlet.Xi_outflow = inStream(outlet.Xi_outflow);
         inStream(inlet.Xi_outflow) = outlet.Xi_outflow;
         annotation (Diagram(graphics), Icon(graphics={Polygon(
@@ -3914,7 +3913,7 @@
         SI.MassFlowRate w "Mass flow rate";
 
       equation
-        // Set gas properties
+// Set gas properties
         inlet.p = gas.p;
 
         gas.h = homotopy(if not allowFlowReversal then inStream(inlet.h_outflow)
@@ -3936,7 +3935,7 @@
         parameter Integer Np0=1 "Nominal number of pumps in parallel";
         parameter SI.Volume V=0 "Pump Internal Volume";
         parameter SI.Density rho0 "Nominal density";
-        parameter SI.Conversions.NonSIunits.AngularVelocity_rpm n0
+        parameter Modelica.Units.NonSI.AngularVelocity_rpm n0
           "Nominal rpm";
         parameter SI.Pressure nominalOutletPressure "Nominal outlet pressure";
         parameter SI.Pressure nominalInletPressure "Nominal inlet pressure";
@@ -4007,7 +4006,7 @@
         parameter Integer Np0=1 "Nominal number of pumps in parallel";
         parameter SI.Volume V=0 "Pump Internal Volume";
         parameter SI.Density rho0 "Nominal density";
-        parameter SI.Conversions.NonSIunits.AngularVelocity_rpm n0
+        parameter Modelica.Units.NonSI.AngularVelocity_rpm n0
           "Nominal rpm";
         parameter SI.Pressure nominalOutletPressure "Nominal outlet pressure";
         parameter SI.Pressure nominalInletPressure "Nominal inlet pressure";
@@ -4018,7 +4017,7 @@
         parameter Boolean SSInit=false "Steady-state initialization"
           annotation (Dialog(tab="Initialization"));
 
-        //PID for flow rate control
+//PID for flow rate control
         parameter Real Kp=4 "Proportional gain (normalised units)"
           annotation (Dialog(tab="PID"));
         parameter SI.Time Ti=200 "Integral time" annotation (Dialog(tab="PID"));
@@ -4165,7 +4164,7 @@
         parameter Integer Np0=1 "Nominal number of pumps in parallel";
         parameter SI.Volume V=0 "Pump Internal Volume";
         parameter SI.Density rho0 "Nominal density";
-        parameter SI.Conversions.NonSIunits.AngularVelocity_rpm n0
+        parameter Modelica.Units.NonSI.AngularVelocity_rpm n0
           "Nominal rpm";
         parameter SI.Pressure nominalOutletPressure "Nominal outlet pressure";
         parameter SI.Pressure nominalInletPressure "Nominal inlet pressure";
@@ -4630,7 +4629,7 @@
 
       model ConvParallel
         "Convective heat transfer between one source and two objects in parallel"
-        import Modelica.SIunits.*;
+        import Modelica.Units.SI.*;
         extends Modelica.Icons.ObsoleteModel;
         parameter Integer N=2 "Number of Nodes";
         parameter Area As=Aa + Ab "Area of source" annotation (Evaluate=true);
@@ -5325,7 +5324,7 @@
       model levelsControl "PID controllers for levels control"
         extends InterfacesControl;
 
-        //PID for level HP control
+//PID for level HP control
         parameter Real Kp_levelHP=3 "Proportional gain (normalised units)"
           annotation (Dialog(tab="PID - level HP"));
         parameter SI.Time Ti_levelHP=400 "Integral time"
@@ -5350,7 +5349,7 @@
           annotation (Dialog(tab="PID - level HP"));
         parameter SI.Length setPoint_levelHP=0 "Set point level of HP drum";
 
-        //PID for level IP control
+//PID for level IP control
         parameter Real Kp_levelIP=3 "Proportional gain (normalised units)"
           annotation (Dialog(tab="PID - level IP"));
         parameter SI.Time Ti_levelIP=600 "Integral time"
@@ -5375,7 +5374,7 @@
           annotation (Dialog(tab="PID - level IP"));
         parameter SI.Length setPoint_levelIP=0 "Set point level of IP drum";
 
-        //PID for level LP control
+//PID for level LP control
         parameter Real Kp_levelLP=3 "Proportional gain (normalised units)"
           annotation (Dialog(tab="PID - level LP"));
         parameter SI.Time Ti_levelLP=800 "Integral time"
@@ -5488,7 +5487,7 @@
           "Thermal conductivity of the metal";
         constant Real pi=Modelica.Constants.pi;
 
-        //Valve parameter
+//Valve parameter
         parameter Real Cv_attShHP
           "Cv (US) flow coefficient, valve for Sh_HP attemperation"
           annotation (Dialog(group="Attemperation"));
@@ -5969,7 +5968,7 @@
           "Thermal conductivity of the metal";
         constant Real pi=Modelica.Constants.pi;
 
-        //Valves parameters
+//Valves parameters
         parameter Real Cv_attShHP
           "Cv (US) flow coefficient, valve for Sh_HP attemperation"
           annotation (dialog(group="Attemperation Sh"));
@@ -7150,7 +7149,7 @@
           "Thermal conductivity of the metal";
         constant Real pi=Modelica.Constants.pi;
 
-        //Valves parameters
+//Valves parameters
         parameter Real Cv_attShHP
           "Cv (US) flow coefficient, valve for Sh_HP attemperation"
           annotation (dialog(group="Attemperation Sh"));
@@ -8699,7 +8698,7 @@
         package FlueGasMedium = ThermoPower.Media.FlueGas;
         package FluidMedium = ThermoPower.Water.StandardWater;
 
-        //gas
+//gas
         parameter SI.MassFlowRate gasNomFlowRate=585.5
           "Nominal flow rate through the gas side";
         parameter SI.Temperature Tstart_G_In=884.65
@@ -8707,7 +8706,7 @@
         parameter SI.Temperature Tstart_G_Out=823.15
           "Outlet gas temperature start value";
 
-        //fluid A
+//fluid A
         parameter SI.MassFlowRate fluidNomFlowRate_A=70.59
           "Nominal flow rate through the fluid side";
         parameter SI.Pressure fluidNomPressure_A=130.5e5
@@ -8731,7 +8730,7 @@
             FluidMedium.specificEnthalpy_pT(fluidNomPressure_A, Tstart_F_A_Out)
           "Nominal specific enthalpy";
 
-        //fluid B
+//fluid B
         parameter SI.MassFlowRate fluidNomFlowRate_B=81.1
           "Nominal flow rate through the fluid side";
         parameter SI.Pressure fluidNomPressure_B=28.2e5
@@ -8807,7 +8806,7 @@
           annotation (Placement(transformation(extent={{-20,-20},{20,20}},
                 rotation=0)));
 
-        //Start value
+//Start value
         parameter SI.Temperature Tstart_G=(Tstart_G_In + Tstart_G_Out)/2;
         parameter SI.Temperature Tstart_M_A=(Tstart_M_A_In + Tstart_M_A_Out)/2;
         parameter SI.Temperature Tstart_M_B=(Tstart_M_B_In + Tstart_M_B_Out)/2;
@@ -8882,9 +8881,8 @@
           annotation (Placement(transformation(extent={{30,-6},{50,14}},
                 rotation=0)));
       initial equation
-        //  hstart_F_A_Out = hE.waterOutA.h_outflow;
-        //  hstart_F_B_Out = hE.waterOutB.h_outflow;
-
+//  hstart_F_A_Out = hE.waterOutA.h_outflow;
+//  hstart_F_B_Out = hE.waterOutB.h_outflow;
       equation
         connect(T_gasOut.inlet, hE.gasOut) annotation (Line(
             points={{34,0},{34,0},{20,0}},
@@ -8938,7 +8936,7 @@
         package FlueGasMedium = ThermoPower.Media.FlueGas;
         package FluidMedium = ThermoPower.Water.StandardWater;
 
-        //gas
+//gas
         parameter SI.MassFlowRate gasNomFlowRate=585.5
           "Nominal flow rate through the gas side";
         parameter SI.Temperature Tstart_G_In=837.15
@@ -8946,7 +8944,7 @@
         parameter SI.Temperature Tstart_G_Out=748.6
           "Outlet gas temperature start value";
 
-        //fluid A
+//fluid A
         parameter SI.MassFlowRate fluidNomFlowRate_A=70.59
           "Nominal flow rate through the fluid side";
         parameter SI.Pressure fluidNomPressure_A=134.3e5
@@ -8970,7 +8968,7 @@
             FluidMedium.specificEnthalpy_pT(fluidNomPressure_A, Tstart_F_A_Out)
           "Nominal specific enthalpy";
 
-        //fluid B
+//fluid B
         parameter SI.MassFlowRate fluidNomFlowRate_B=81.1
           "Nominal flow rate through the fluid side";
         parameter SI.Pressure fluidNomPressure_B=28.4e5
@@ -9045,7 +9043,7 @@
               ThermoPower.Thermal.HeatExchangerTopologies.CounterCurrentFlow)
           annotation (Placement(transformation(extent={{-20,-20},{20,20}},
                 rotation=0)));
-        //Start value
+        //Start value
         parameter SI.Temperature Tstart_G=(Tstart_G_In + Tstart_G_Out)/2;
         parameter SI.Temperature Tstart_M_A=(Tstart_M_A_In + Tstart_M_A_Out)/2;
         parameter SI.Temperature Tstart_M_B=(Tstart_M_B_In + Tstart_M_B_Out)/2;
@@ -9176,14 +9174,14 @@
         package FlueGasMedium = ThermoPower.Media.FlueGas;
         package FluidMedium = ThermoPower.Water.StandardWater;
 
-        //gas
+//gas
         parameter SI.MassFlowRate gasNomFlowRate=585.5 "Nominal mass flowrate";
         parameter SI.Temperature Tstart_G_In=747.15
           "Inlet gas temperature start value";
         parameter SI.Temperature Tstart_G_Out=620.3
           "Outlet gas temperature start value";
 
-        //fluid
+//fluid
         parameter SI.MassFlowRate fluidNomFlowRate=175.5
           "Nominal flow rate through the fluid side";
         parameter SI.Pressure fluidNomPressure=137.1e5
@@ -9237,7 +9235,7 @@
               ThermoPower.Thermal.HeatExchangerTopologies.CounterCurrentFlow)
                          annotation (Placement(transformation(extent={{-20,-20},
                   {20,20}}, rotation=0)));
-        //Start value
+        //Start value
         parameter SI.Temperature Tstart_G=(Tstart_G_In + Tstart_G_Out)/2;
         parameter SI.Temperature Tstart_M=(Tstart_M_In + Tstart_M_Out)/2;
         parameter Boolean SSInit=true "Steady-state initialization";
@@ -9316,14 +9314,14 @@
         package FlueGasMedium = ThermoPower.Media.FlueGas;
         package FluidMedium = ThermoPower.Water.StandardWater;
 
-        //gas
+//gas
         parameter SI.MassFlowRate gasNomFlowRate=585.5 "Nominal mass flowrate";
         parameter SI.Temperature Tstart_G_In=614.15
           "Inlet gas temperature start value";
         parameter SI.Temperature Tstart_G_Out=558.98
           "Outlet gas temperature start value";
 
-        //fluid
+//fluid
         parameter SI.MassFlowRate fluidNomFlowRate=70.1
           "Nominal flow rate through the fluid side";
         parameter SI.Pressure fluidNomPressure=138.6e5
@@ -9378,7 +9376,7 @@
               (gamma=gamma_G))
                          annotation (Placement(transformation(extent={{-20,-20},
                   {20,20}}, rotation=0)));
-        //Start value
+        //Start value
         parameter SI.Temperature Tstart_G=(Tstart_G_In + Tstart_G_Out)/2;
         parameter SI.Temperature Tstart_M=(Tstart_M_In + Tstart_M_Out)/2;
         parameter Boolean SSInit=true "Steady-state initialization";
@@ -9457,14 +9455,14 @@
         package FlueGasMedium = ThermoPower.Media.FlueGas;
         package FluidMedium = ThermoPower.Water.StandardWater;
 
-        //gas
+//gas
         parameter SI.MassFlowRate gasNomFlowRate=585.5 "Nominal mass flowrate";
         parameter SI.Temperature Tstart_G_In=620.14
           "Inlet gas temperature start value";
         parameter SI.Temperature Tstart_G_Out=614.5
           "Outlet gas temperature start value";
 
-        //fluid
+//fluid
         parameter SI.MassFlowRate fluidNomFlowRate=13.5
           "Nominal flow rate through the fluid side";
         parameter SI.Pressure fluidNomPressure=29.5e5
@@ -9521,7 +9519,7 @@
               ThermoPower.Thermal.HeatExchangerTopologies.CounterCurrentFlow)
           annotation (Placement(transformation(extent={{-20,-20},{20,20}},
                 rotation=0)));
-        //Start value
+        //Start value
         parameter SI.Temperature Tstart_G=(Tstart_G_In + Tstart_G_Out)/2;
         parameter SI.Temperature Tstart_M=(Tstart_M_In + Tstart_M_Out)/2;
         parameter Boolean SSInit=true "Steady-state initialization";
@@ -9600,14 +9598,14 @@
         package FlueGasMedium = ThermoPower.Media.FlueGas;
         package FluidMedium = ThermoPower.Water.StandardWater;
 
-        //gas
+//gas
         parameter SI.MassFlowRate gasNomFlowRate=585.5 "Nominal mass flowrate";
         parameter SI.Temperature Tstart_G_In=558.15
           "Inlet gas temperature start value";
         parameter SI.Temperature Tstart_G_Out=518.51
           "Outlet gas temperature start value";
 
-        //fluid
+//fluid
         parameter SI.MassFlowRate fluidNomFlowRate=67.5
           "Nominal flow rate through the fluid side";
         parameter SI.Pressure fluidNomPressure=37.16e5
@@ -9661,7 +9659,7 @@
               ThermoPower.Thermal.HeatExchangerTopologies.CounterCurrentFlow)
                          annotation (Placement(transformation(extent={{-20,-20},
                   {20,20}}, rotation=0)));
-        //Start value
+        //Start value
         parameter SI.Temperature Tstart_G=(Tstart_G_In + Tstart_G_Out)/2;
         parameter SI.Temperature Tstart_M=(Tstart_M_In + Tstart_M_Out)/2;
         parameter Boolean SSInit=true "Steady-state initialization";
@@ -9740,7 +9738,7 @@
         package FlueGasMedium = ThermoPower.Media.FlueGas;
         package FluidMedium = ThermoPower.Water.StandardWater;
 
-        //gas
+//gas
         parameter SI.MassFlowRate gasNomFlowRate=585.5
           "Nominal flow rate through the gas side";
         parameter SI.Temperature Tstart_G_In=517.15
@@ -9748,7 +9746,7 @@
         parameter SI.Temperature Tstart_G_Out=480.11
           "Outlet gas temperature start value";
 
-        //fluid A
+//fluid A
         parameter SI.MassFlowRate fluidNomFlowRate_A=70.1
           "Nominal flow rate through the fluid side";
         parameter SI.Pressure fluidNomPressure_A=138.9e5
@@ -9772,7 +9770,7 @@
             FluidMedium.specificEnthalpy_pT(fluidNomPressure_A, Tstart_F_A_Out)
           "Nominal specific enthalpy";
 
-        //fluid B
+//fluid B
         parameter SI.MassFlowRate fluidNomFlowRate_B=21.8
           "Nominal flow rate through the fluid side";
         parameter SI.Pressure fluidNomPressure_B=48.6e5
@@ -9912,7 +9910,7 @@
           annotation (Placement(transformation(extent={{30,-6},{50,14}},
                 rotation=0)));
 
-        //Start value
+//Start value
         parameter SI.Temperature Tstart_G=(Tstart_G_In + Tstart_G_Out)/2;
         parameter SI.Temperature Tstart_M_A=(Tstart_M_A_In + Tstart_M_A_Out)/2;
         parameter SI.Temperature Tstart_M_B=(Tstart_M_B_In + Tstart_M_B_Out)/2;
@@ -9976,14 +9974,14 @@
         package FlueGasMedium = ThermoPower.Media.FlueGas;
         package FluidMedium = ThermoPower.Water.StandardWater;
 
-        //gas
+//gas
         parameter SI.MassFlowRate gasNomFlowRate=585.5 "Nominal mass flowrate";
         parameter SI.Temperature Tstart_G_In=519.15
           "Inlet gas temperature start value";
         parameter SI.Temperature Tstart_G_Out=517.44
           "Outlet gas temperature start value";
 
-        //fluid
+//fluid
         parameter SI.MassFlowRate fluidNomFlowRate=6.91
           "Nominal flow rate through the fluid side";
         parameter SI.Pressure fluidNomPressure=6.6e5
@@ -10039,7 +10037,7 @@
               ThermoPower.Thermal.HeatExchangerTopologies.CounterCurrentFlow)
                                 annotation (Placement(transformation(extent={{-20,
                   -20},{20,20}}, rotation=0)));
-        //Start value
+        //Start value
         parameter SI.Temperature Tstart_G=(Tstart_G_In + Tstart_G_Out)/2;
         parameter SI.Temperature Tstart_M=(Tstart_M_In + Tstart_M_Out)/2;
         parameter Boolean SSInit=true "Steady-state initialization";
@@ -10118,14 +10116,14 @@
         package FlueGasMedium = ThermoPower.Media.FlueGas;
         package FluidMedium = ThermoPower.Water.StandardWater;
 
-        //gas
+//gas
         parameter SI.MassFlowRate gasNomFlowRate=585.5 "Nominal mass flowrate";
         parameter SI.Temperature Tstart_G_In=480
           "Inlet gas temperature start value";
         parameter SI.Temperature Tstart_G_Out=453.47
           "Outlet gas temperature start value";
 
-        //fluid
+//fluid
         parameter SI.MassFlowRate fluidNomFlowRate=41.49
           "Nominal flow rate through the fluid side";
         parameter SI.Pressure fluidNomPressure=15.34e5
@@ -10214,7 +10212,7 @@
         Gas.SensT T_gasOut(redeclare package Medium = FlueGasMedium)
           annotation (Placement(transformation(extent={{30,-6},{50,14}},
                 rotation=0)));
-        //Start value
+        //Start value
         parameter SI.Temperature Tstart_G=(Tstart_G_In + Tstart_G_Out)/2;
         parameter SI.Temperature Tstart_M=(Tstart_M_In + Tstart_M_Out)/2;
         parameter Boolean SSInit=true "Steady-state initialization";
@@ -10258,14 +10256,14 @@
         package FlueGasMedium = ThermoPower.Media.FlueGas;
         package FluidMedium = ThermoPower.Water.StandardWater;
 
-        //gas
+//gas
         parameter SI.MassFlowRate gasNomFlowRate=585.5 "Nominal mass flowrate";
         parameter SI.Temperature Tstart_G_In=453.47
           "Inlet gas temperature start value";
         parameter SI.Temperature Tstart_G_Out=372.35
           "Outlet gas temperature start value";
 
-        //fluid
+//fluid
         parameter SI.MassFlowRate fluidNomFlowRate=89.82
           "Nominal flow rate through the fluid side";
         parameter SI.Pressure fluidNomPressure=6e5
@@ -10320,7 +10318,7 @@
               ThermoPower.Thermal.HeatExchangerTopologies.CounterCurrentFlow)
                                  annotation (Placement(transformation(extent={{
                   -20,-20},{20,20}}, rotation=0)));
-        //Start value
+        //Start value
         parameter SI.Temperature Tstart_G=(Tstart_G_In + Tstart_G_Out)/2;
         parameter SI.Temperature Tstart_M=(Tstart_M_In + Tstart_M_Out)/2;
         parameter Boolean SSInit=true "Steady-state initialization";
@@ -10398,7 +10396,7 @@
       model TestHEG_3LRh
         package FlueGasMedium = ThermoPower.Media.FlueGas;
         package FluidMedium = ThermoPower.Water.StandardWater;
-        //HP
+        //HP
         parameter SI.MassFlowRate fluidHPNomFlowRate_Sh=67.6
           "Nominal mass flowrate";
         parameter SI.Pressure fluidHPNomPressure_Sh=138.9e5 "Nominal pressure";
@@ -10419,7 +10417,7 @@
         parameter SI.SpecificEnthalpy Ec2_HP_hstart_F_Out=1.45077e6
           "Nominal specific enthalpy";
 
-        //IP
+//IP
         parameter SI.MassFlowRate fluidIPNomFlowRate_Rh=81.10
           "Nominal mass flowrate";
         parameter SI.Pressure fluidIPNomPressure_Rh=33.8e5 "Nominal pressure";
@@ -10447,7 +10445,7 @@
         parameter SI.SpecificEnthalpy Ec_IP_hstart_F_Out=9.70768e5
           "Nominal specific enthalpy";
 
-        //LP
+//LP
         parameter SI.MassFlowRate fluidLPNomFlowRate_Sh=8.72
           "Nominal mass flowrate";
         parameter SI.Pressure fluidLPNomPressure_Sh=7.19e5 "Nominal pressure";
@@ -11219,7 +11217,7 @@
         replaceable package FluidMedium = ThermoPower.Water.StandardWater
           constrainedby Modelica.Media.Interfaces.PartialPureSubstance;
 
-        //Turbines parameter
+//Turbines parameter
         parameter SI.MassFlowRate steamHPNomFlowRate
           "Nominal HP steam flow rate";
         parameter SI.MassFlowRate steamLPNomFlowRate
@@ -11239,10 +11237,10 @@
         parameter Real LPT_eta_iso_nom=0.92 "Nominal isentropic efficiency"
           annotation (Dialog(group="LP Turbine"));
 
-        //Start value
+//Start value
         parameter Boolean SSInit=false "Steady-state initialization"
           annotation (Dialog(tab="Initialization"));
-        //HPT
+        //HPT
         parameter SI.Pressure HPT_pstart_in=steamHPNomPressure
           "Inlet pressure start value"
           annotation (Dialog(tab="Initialization", group="HP Turbine"));
@@ -11252,7 +11250,7 @@
         parameter SI.MassFlowRate HPT_wstart=steamHPNomFlowRate
           "Mass flow rate start value"
           annotation (Dialog(tab="Initialization", group="HP Turbine"));
-        //LPT
+        //LPT
         parameter SI.Pressure LPT_pstart_in=steamLPNomPressure
           "Inlet pressure start value"
           annotation (Dialog(tab="Initialization", group="LP Turbine"));
@@ -11263,7 +11261,7 @@
             steamHPNomFlowRate "Mass flow rate start value"
           annotation (Dialog(tab="Initialization", group="LP Turbine"));
 
-        //other parameter
+//other parameter
         parameter SI.Pressure pcond "Condenser pressure";
 
         Water.FlangeA HPT_In(redeclare package Medium = FluidMedium)
@@ -11333,7 +11331,7 @@
         replaceable package FluidMedium = ThermoPower.Water.StandardWater
           constrainedby Modelica.Media.Interfaces.PartialPureSubstance;
 
-        //Turbines parameter
+//Turbines parameter
         parameter SI.MassFlowRate steamHPNomFlowRate
           "Nominal HP steam flow rate";
         parameter SI.MassFlowRate steamIPNomFlowRate
@@ -11362,10 +11360,10 @@
         parameter Real LPT_eta_iso_nom=0.92 "Nominal isentropic efficiency"
           annotation (Dialog(group="LP Turbine"));
 
-        //Start value
+//Start value
         parameter Boolean SSInit=false "Steady-state initialization"
           annotation (Dialog(tab="Initialization"));
-        //HPT
+        //HPT
         parameter SI.Pressure HPT_pstart_in=steamHPNomPressure
           "Inlet pressure start value"
           annotation (Dialog(tab="Initialization", group="HP Turbine"));
@@ -11376,7 +11374,7 @@
           "Mass flow rate start value"
           annotation (Dialog(tab="Initialization", group="HP Turbine"));
 
-        //IPT
+//IPT
         parameter SI.Pressure IPT_pstart_in=steamIPNomPressure
           "Inlet pressure start value"
           annotation (Dialog(tab="Initialization", group="IP Turbine"));
@@ -11387,7 +11385,7 @@
             steamHPNomFlowRate "Mass flow rate start value"
           annotation (Dialog(tab="Initialization", group="IP Turbine"));
 
-        //LPT
+//LPT
         parameter SI.Pressure LPT_pstart_in=steamLPNomPressure
           "Inlet pressure start value"
           annotation (Dialog(tab="Initialization", group="LP Turbine"));
@@ -11399,7 +11397,7 @@
           "Mass flow rate start value"
           annotation (Dialog(tab="Initialization", group="LP Turbine"));
 
-        //Other parameter
+//Other parameter
         parameter SI.Pressure pcond "Condenser pressure";
 
         Water.FlangeA HPT_In(redeclare package Medium = FluidMedium)
@@ -11503,7 +11501,7 @@
         replaceable package FluidMedium = ThermoPower.Water.StandardWater
           constrainedby Modelica.Media.Interfaces.PartialPureSubstance;
 
-        //Turbines parameter
+//Turbines parameter
         parameter SI.MassFlowRate steamHPNomFlowRate
           "Nominal HP steam flow rate";
         parameter SI.MassFlowRate steamLPNomFlowRate
@@ -11523,10 +11521,10 @@
         parameter Real LPT_eta_iso_nom=0.92 "Nominal isentropic efficiency"
           annotation (Dialog(group="LP Turbine"));
 
-        //Start value
+//Start value
         parameter Boolean SSInit=false "Steady-state initialization"
           annotation (Dialog(tab="Initialization"));
-        //HPT
+        //HPT
         parameter SI.Pressure HPT_pstart_in=steamHPNomPressure
           "Inlet pressure start value"
           annotation (Dialog(tab="Initialization", group="HP Turbine"));
@@ -11537,7 +11535,7 @@
           "Mass flow rate start value"
           annotation (Dialog(tab="Initialization", group="HP Turbine"));
 
-        //LPT
+//LPT
         parameter SI.Pressure LPT_pstart_in=steamLPNomPressure
           "Inlet pressure start value"
           annotation (Dialog(tab="Initialization", group="LP Turbine"));
@@ -11548,7 +11546,7 @@
           "Mass flow rate start value"
           annotation (Dialog(tab="Initialization", group="LP Turbine"));
 
-        //other parameter
+//other parameter
         parameter SI.Pressure pcond "Condenser pressure";
 
         Water.FlangeB SteamForHU(redeclare package Medium = FluidMedium)
@@ -11649,7 +11647,7 @@
         replaceable package FluidMedium = ThermoPower.Water.StandardWater
           constrainedby Modelica.Media.Interfaces.PartialPureSubstance;
 
-        //Turbines parameter
+//Turbines parameter
         parameter SI.MassFlowRate steamHPNomFlowRate
           "Nominal HP steam flow rate";
         parameter SI.MassFlowRate steamLPNomFlowRate
@@ -11675,10 +11673,10 @@
         parameter Real LPT_eta_iso_nom=0.92 "Nominal isentropic efficiency"
           annotation (Dialog(group="LP Turbine"));
 
-        //Start value
+//Start value
         parameter Boolean SSInit=false "Steady-state initialization"
           annotation (Dialog(tab="Initialization"));
-        //HPT
+        //HPT
         parameter SI.Pressure HPT_pstart_in=steamHPNomPressure
           "Inlet pressure start value"
           annotation (Dialog(tab="Initialization", group="HP Turbine"));
@@ -11689,7 +11687,7 @@
           "Mass flow rate start value"
           annotation (Dialog(tab="Initialization", group="HP Turbine"));
 
-        //LPT
+//LPT
         parameter SI.Pressure LPT_pstart_in=steamLPNomPressure
           "Inlet pressure start value"
           annotation (Dialog(tab="Initialization", group="LP Turbine"));
@@ -11700,7 +11698,7 @@
           "Mass flow rate start value"
           annotation (Dialog(tab="Initialization", group="LP Turbine"));
 
-        //other parameter
+//other parameter
         parameter SI.Pressure pcond "Condenser pressure";
 
         Water.FlangeB SteamForHU(redeclare package Medium = FluidMedium)
@@ -11807,7 +11805,7 @@
         replaceable package FluidMedium = ThermoPower.Water.StandardWater
           constrainedby Modelica.Media.Interfaces.PartialPureSubstance;
 
-        //Turbines parameter
+//Turbines parameter
         parameter SI.MassFlowRate steamHPNomFlowRate
           "Nominal HP steam flow rate";
         parameter SI.MassFlowRate steamIPNomFlowRate
@@ -11836,8 +11834,8 @@
         parameter Real LPT_eta_iso_nom=0.92 "Nominal isentropic efficiency"
           annotation (Dialog(group="LP Turbine"));
 
-        //Start value
-        //HPT
+//Start value
+        //HPT
         parameter SI.Pressure HPT_pstart_in=steamHPNomPressure
           "Inlet pressure start value"
           annotation (Dialog(tab="Initialization", group="HP Turbine"));
@@ -11848,7 +11846,7 @@
           "Mass flow rate start value"
           annotation (Dialog(tab="Initialization", group="HP Turbine"));
 
-        //IPT
+//IPT
         parameter SI.Pressure IPT_pstart_in=steamIPNomPressure
           "Inlet pressure start value"
           annotation (Dialog(tab="Initialization", group="IP Turbine"));
@@ -11859,7 +11857,7 @@
           "Mass flow rate start value"
           annotation (Dialog(tab="Initialization", group="IP Turbine"));
 
-        //LPT
+//LPT
         parameter SI.Pressure LPT_pstart_in=steamLPNomPressure
           "Inlet pressure start value"
           annotation (Dialog(tab="Initialization", group="LP Turbine"));
@@ -11870,7 +11868,7 @@
           "Mass flow rate start value"
           annotation (Dialog(tab="Initialization", group="LP Turbine"));
 
-        //other parameter
+//other parameter
         parameter SI.Pressure pcond "Condenser pressure";
 
         Water.FlangeB Tap1(redeclare package Medium = FluidMedium) annotation (
@@ -11974,7 +11972,7 @@
         replaceable package FluidMedium = ThermoPower.Water.StandardWater
           constrainedby Modelica.Media.Interfaces.PartialPureSubstance;
 
-        //Turbines parameter
+//Turbines parameter
         parameter SI.MassFlowRate steamHPNomFlowRate
           "Nominal HP steam flow rate";
         parameter SI.MassFlowRate steamIPNomFlowRate
@@ -12003,8 +12001,8 @@
         parameter Real LPT_eta_iso_nom=0.92 "Nominal isentropic efficiency"
           annotation (Dialog(group="LP Turbine"));
 
-        //Start value
-        //HPT
+//Start value
+        //HPT
         parameter SI.Pressure HPT_pstart_in=steamHPNomPressure
           "Inlet pressure start value"
           annotation (Dialog(tab="Initialization", group="HP Turbine"));
@@ -12015,7 +12013,7 @@
           "Mass flow rate start value"
           annotation (Dialog(tab="Initialization", group="HP Turbine"));
 
-        //IPT
+//IPT
         parameter SI.Pressure IPT_pstart_in=steamIPNomPressure
           "Inlet pressure start value"
           annotation (Dialog(tab="Initialization", group="IP Turbine"));
@@ -12026,7 +12024,7 @@
           "Mass flow rate start value"
           annotation (Dialog(tab="Initialization", group="IP Turbine"));
 
-        //LPT
+//LPT
         parameter SI.Pressure LPT_pstart_in=steamLPNomPressure
           "Inlet pressure start value"
           annotation (Dialog(tab="Initialization", group="LP Turbine"));
@@ -12037,7 +12035,7 @@
           "Mass flow rate start value"
           annotation (Dialog(tab="Initialization", group="LP Turbine"));
 
-        //other parameter
+//other parameter
         parameter SI.Pressure pcond "Condenser pressure";
 
         Water.FlangeB Tap1(redeclare package Medium = FluidMedium) annotation (
@@ -12177,7 +12175,7 @@
         replaceable package FluidMedium = ThermoPower.Water.StandardWater
           constrainedby Modelica.Media.Interfaces.PartialPureSubstance;
 
-        //Nominal parameter
+//Nominal parameter
         parameter SI.MassFlowRate condNomFlowRate
           "Nominal flow rate through the condensing fluid side";
         parameter SI.MassFlowRate coolNomFlowRate
@@ -12187,7 +12185,7 @@
         parameter SI.Pressure coolNomPressure
           "Nominal pressure in the cooling fluid side inlet";
 
-        //Physical Parameter
+//Physical Parameter
         parameter Integer N_cool=2 "Number of nodes of the cooling fluid side";
         parameter SI.Area condExchSurface
           "Exchange surface between condensing fluid - metal";
@@ -12199,7 +12197,7 @@
         parameter SI.SpecificHeatCapacity cm "Specific heat capacity of metal";
         parameter SI.Density rhoMetal "Density of metal";
 
-        //Initialization conditions
+//Initialization conditions
         parameter SI.Pressure pstart_cond=condNomPressure
           "Condensing fluid pressure start value"
           annotation (Dialog(tab="Initialization"));
@@ -12324,7 +12322,7 @@
         replaceable package FluidMedium = ThermoPower.Water.StandardWater
           constrainedby Modelica.Media.Interfaces.PartialPureSubstance;
 
-        //Nominal parameter
+//Nominal parameter
         parameter SI.MassFlowRate condNomFlowRate
           "Nominal flow rate through the condensing fluid side";
         parameter SI.MassFlowRate coolNomFlowRate
@@ -12334,7 +12332,7 @@
         parameter SI.Pressure coolNomPressure
           "Nominal pressure in the cooling fluid side inlet";
 
-        //Physical Parameter
+//Physical Parameter
         parameter Integer N_cool=2 "Number of node of the cooling fluid side";
         parameter SI.Area condExchSurface
           "Exchange surface between condensing fluid - metal";
@@ -12346,7 +12344,7 @@
         parameter SI.SpecificHeatCapacity cm "Specific heat capacity of metal";
         parameter SI.Density rhoMetal "Density of metal";
 
-        //Initialization
+//Initialization
         parameter SI.Pressure pstart_cond=condNomPressure
           "Condensing fluid pressure start value"
           annotation (Dialog(tab="Initialization"));
@@ -12388,7 +12386,7 @@
         replaceable package FluidMedium = ThermoPower.Water.StandardWater
           constrainedby Modelica.Media.Interfaces.PartialPureSubstance;
 
-        //Nominal parameter
+//Nominal parameter
         parameter SI.MassFlowRate condNomFlowRate
           "Nominal flow rate through the condensing fluid side";
         parameter SI.MassFlowRate coolNomFlowRate
@@ -12398,7 +12396,7 @@
         parameter SI.Pressure coolNomPressure
           "Nominal pressure in the cooling fluid side inlet";
 
-        //Physical Parameter
+//Physical Parameter
         parameter Integer N_cool=2 "Number of node of the cooling fluid side";
         parameter SI.Area condExchSurface
           "Exchange surface between condensing fluid - metal";
@@ -12410,7 +12408,7 @@
         parameter SI.SpecificHeatCapacity cm "Specific heat capacity of metal";
         parameter SI.Density rhoMetal "Density of metal";
 
-        //Initialization
+//Initialization
         parameter SI.Pressure pstart_cond=condNomPressure
           "Condensing fluid pressure start value"
           annotation (Dialog(tab="Initialization"));
@@ -13057,7 +13055,7 @@
           "Nominal pressure drop (friction term only!)";
         parameter Density rhonom_cool=0 "Nominal inlet density";
 
-        //other data
+//other data
         constant Real pi=Modelica.Constants.pi;
 
         Water.Flow1D flowCooling(
@@ -13131,7 +13129,7 @@
       model CondenserPreP "Ideal condenser with prescribed pressure"
         replaceable package Medium = Water.StandardWater constrainedby
           Modelica.Media.Interfaces.PartialMedium "Medium model";
-        //Parameters
+        //Parameters
         parameter SI.Pressure p "Nominal inlet pressure";
         parameter SI.Volume Vtot=10 "Total volume of the fluid side";
         parameter SI.Volume Vlstart=0.15*Vtot
@@ -13140,7 +13138,7 @@
           "= true to allow flow reversal, false restricts to design direction";
         outer ThermoPower.System system "System wide properties";
 
-        //Variable
+//Variable
         SI.Density rhol "Density of saturated liquid";
         SI.Density rhov "Density of saturated steam";
         Medium.SaturationProperties sat "Saturation properties";
@@ -13155,7 +13153,7 @@
         SI.Energy E(stateSelect=StateSelect.never) "Internal energy";
         SI.Power Q "Thermal power";
 
-        //Connectors
+//Connectors
         Water.FlangeA steamIn(redeclare package Medium = Medium, m_flow(min=if
                 allowFlowReversal then -Modelica.Constants.inf else 0))
           annotation (Placement(transformation(extent={{-20,80},{20,120}},
@@ -13191,14 +13189,12 @@
         Mv = Vv*rhov;
         Vtot = Vv + Vl;
         M = Ml + Mv;
-        E = Ml*hl + Mv*hv - p*Vtot;
-
-        //Energy and Mass Balances
+        E = Ml*hl + Mv*hv - p*Vtot;
+//Energy and Mass Balances
         der(M) = steamIn.m_flow + waterOut.m_flow;
-        der(E) = steamIn.m_flow*hv + waterOut.m_flow*hl - Q;
-
-        //Output signal
-        ratio_Vv_Vtot = Vv/Vtot;
+        der(E) = steamIn.m_flow*hv + waterOut.m_flow*hl - Q;
+//Output signal
+        ratio_Vv_Vtot = Vv / Vtot;
         Qcond = Q;
 
         annotation (Icon(graphics={Rectangle(
@@ -13226,7 +13222,7 @@
           "= true to allow flow reversal, false restricts to design direction";
         outer ThermoPower.System system "System wide properties";
 
-        //Variable
+//Variable
         SI.Density rhol "Density of saturated liquid";
         SI.Density rhov "Density of saturated steam";
         Medium.SaturationProperties sat "Saturation properties";
@@ -13281,14 +13277,12 @@
         Mv = Vv*rhov;
         Vtot = Vv + Vl;
         M = Ml + Mv;
-        E = Ml*hl + Mv*hv - p*Vtot;
-
-        //Energy and Mass Balances
-        der(M) = steamIn.m_flow + (waterOut.m_flow + tapWater.m_flow);
-        der(E) = steamIn.m_flow*hv + (waterOut.m_flow + tapWater.m_flow)*hl - Q;
-
-        //Output signal
-        ratio_Vv_Vtot = Vv/Vtot;
+        E = Ml*hl + Mv*hv - p*Vtot;
+//Energy and Mass Balances
+        der(M) = steamIn.m_flow + waterOut.m_flow + tapWater.m_flow;
+        der(E) = steamIn.m_flow*hv + (waterOut.m_flow + tapWater.m_flow)*hl - Q;
+//Output signal
+        ratio_Vv_Vtot = Vv / Vtot;
         Qcond = Q;
 
         annotation (Icon(graphics={Rectangle(
@@ -13378,9 +13372,8 @@
         der(M) = ws - wc "Mass balance";
         der(E) = ws*hs - wc*hl - Qcond "Energy balance (liquid+steam)";
         der(Em) = Qcond - Qcool "Energy balance (metal tubes)";
-        Qcond = hc*Ac*(Ts - Tm);
-
-        // Boundary conditions
+        Qcond = hc*Ac*(Ts - Tm);
+// Boundary conditions
         p = steam.p;
         p = condensate.p;
         ws = steam.m_flow;
@@ -13390,11 +13383,9 @@
         condensate.h_outflow = hl;
         Qcool = -Af/(Nc - 1)*sum(coolingFluid.phi[1:Nc - 1] + coolingFluid.phi[
           2:Nc])/2;
-        coolingFluid.T = ones(Nc)*Tm;
-
-        // Fluid properties
-        // sat = Medium.setSat_p(p);
-
+        coolingFluid.T = ones(Nc)*Tm;
+// Fluid properties
+// sat = Medium.setSat_p(p);
         sat.psat = p;
         sat.Tsat = Medium.saturationTemperature(p);
 
@@ -13406,7 +13397,7 @@
         ratio_VvVtot = Vv/V;
       initial equation
         if initOpt == ThermoPower.Choices.Init.Options.noInit then
-          // do nothing
+// do nothing
         elseif initOpt == ThermoPower.Choices.Init.Options.steadyState then
           der(M) = 0;
           der(E) = 0;
@@ -13441,7 +13432,7 @@
       model SteamTurbineVarEta "Steam turbine with variable efficiency"
         extends ThermoPower.Water.BaseClasses.SteamTurbineBase;
 
-        //Parameter
+//Parameter
         parameter SI.Area Kt "Kt coefficient of Stodola's law";
         replaceable function curveEta_iso = Functions.curveEfficiency
           "Characteristich curve of efficiency";
@@ -13450,7 +13441,7 @@
         parameter SI.Length Rm "Mean ray";
         parameter Integer n "Number of stages";
 
-        //Variable
+//Variable
         Real y "Ratio uf/wiso";
         Real uf "Mean peripheral velocity of the rotor";
         Real viso "Mean velocity of the fluid in isentropic conditions";
@@ -13474,14 +13465,14 @@
         replaceable package FluidMedium = ThermoPower.Water.StandardWater
           constrainedby Modelica.Media.Interfaces.PartialPureSubstance;
 
-        //Turbines parameters
+//Turbines parameters
         parameter SI.MassFlowRate wn "Inlet nominal flowrate";
         parameter SI.Area Kt "Coefficient of Stodola's law";
         parameter SI.Pressure pnom_in "Nominal inlet pressure";
         parameter SI.Pressure pnom_tap "Nominal tapping pressure";
         parameter SI.Pressure pnom_out "Nominal outlet pressure";
 
-        //Start Value
+//Start Value
         parameter SI.MassFlowRate wstart=wn "Mass flow rate start value"
           annotation (Dialog(tab="Initialization"));
 
@@ -13583,7 +13574,7 @@
 
       model PrescribedSpeed "Constant speed, not dependent on torque"
         extends Modelica.Mechanics.Rotational.Interfaces.PartialTorque;
-        Modelica.SIunits.AngularVelocity w
+        Modelica.Units.SI.AngularVelocity w
           "Angular velocity of flange with respect to support (= der(phi))";
         Modelica.Blocks.Interfaces.RealInput w_fixed annotation (Placement(
               transformation(extent={{-116,44},{-84,76}}, rotation=0)));
@@ -13638,8 +13629,7 @@
         sat.psat = p;
         sat.Tsat = FluidMedium.saturationTemperature(p);
         hl = FluidMedium.bubbleEnthalpy(sat);
-
-        //Output signal
+//Output signal
         h = hl;
         annotation (Icon(graphics={Rectangle(
                       extent={{-80,40},{80,-40}},
@@ -13669,8 +13659,7 @@
       equation
         inlet.m_flow + outlet.m_flow = 0 "Mass balance";
         inlet.p = outlet.p "No pressure drop";
-
-        // Boundary conditions
+// Boundary conditions
         inlet.h_outflow = inStream(outlet.h_outflow);
         inStream(inlet.h_outflow) = outlet.h_outflow;
         annotation (
@@ -13712,7 +13701,7 @@
         SI.MassFlowRate w "Mass flow rate";
         Medium.ThermodynamicState fluidState "Thermodynamic state of the fluid";
       equation
-        // Set fluid state
+// Set fluid state
         p = inlet.p;
         h = homotopy(if not allowFlowReversal then inStream(inlet.h_outflow)
            else actualStream(inlet.h_outflow), inStream(inlet.h_outflow));
@@ -13727,7 +13716,7 @@
       model ST3L_base "Steam turbine with three pressure levels"
         extends ThermoPower.PowerPlants.SteamTurbineGroup.Interfaces.ST_3L;
 
-        //Mixers Parameters
+//Mixers Parameters
         parameter SI.Volume mixLP_V "Internal volume of the LP mixer";
         parameter SI.Pressure mixLP_pstart=steamLPNomPressure
           "Pressure start value of the LP mixer"
@@ -13892,10 +13881,10 @@
       model ST3L_valve "Steam turbine with three pressure levels, inlet valves"
         extends ThermoPower.PowerPlants.SteamTurbineGroup.Interfaces.ST_3L;
 
-        //Mixers Parameters
+//Mixers Parameters
         parameter SI.Volume mixLP_V "Internal volume of the LP mixer";
 
-        //Valves Parameters
+//Valves Parameters
         parameter Real valveHP_Cv=0 "Cv (US) flow coefficient of the HP valve"
           annotation (Dialog(group="HP valve"));
         parameter SI.Pressure valveHP_dpnom
@@ -14055,16 +14044,16 @@
         "Steam turbine with three pressure levels, inlet and by-pass valves "
         extends ThermoPower.PowerPlants.SteamTurbineGroup.Interfaces.ST_3L;
 
-        //Mixers Parameters
+//Mixers Parameters
         parameter SI.Volume mixLP_V "Internal volume of the LP mixer";
         parameter SI.Pressure mixLP_pstart=steamLPNomPressure
           "Pressure start value of the LP mixer"
           annotation (Dialog(tab="Initialization", group="LP mixer"));
 
-        //Valves Parameters
+//Valves Parameters
         parameter Real valveHP_Cv=0 "Cv (US) flow coefficient of the HP valve"
           annotation (Dialog(group="HP valves"));
-        parameter Modelica.SIunits.Pressure valveHP_dpnom
+        parameter Modelica.Units.SI.Pressure valveHP_dpnom
           "Nominal pressure drop of the HP valve"
           annotation (Dialog(group="HP valves"));
         parameter Real bypassHP_Cv=0
@@ -14072,7 +14061,7 @@
           annotation (Dialog(group="HP valves"));
         parameter Real valveIP_Cv=0 "Cv (US) flow coefficient of the IP valve"
           annotation (Dialog(group="IP valves"));
-        parameter Modelica.SIunits.Pressure valveIP_dpnom
+        parameter Modelica.Units.SI.Pressure valveIP_dpnom
           "Nominal pressure drop of the IP valve"
           annotation (Dialog(group="IP valves"));
         parameter Real bypassIP_Cv=0
@@ -14083,7 +14072,7 @@
           annotation (Dialog(group="IP valves"));
         parameter Real valveLP_Cv=0 "Cv (US) flow coefficient of the LP valve"
           annotation (Dialog(group="LP valves"));
-        parameter Modelica.SIunits.Pressure valveLP_dpnom
+        parameter Modelica.Units.SI.Pressure valveLP_dpnom
           "Nominal pressure drop of the LP valve"
           annotation (Dialog(group="LP valves"));
         parameter Real bypassLP_Cv=0
@@ -14394,13 +14383,13 @@
         "Steam Turbine Group (two pressure levels) with coupling Heat Usage"
         extends Interfaces.ST_2LHU;
 
-        //Mixers Parameters
+//Mixers Parameters
         parameter SI.Volume mixLP_V "Internal volume of the LP mixer";
         parameter SI.Pressure mixLP_pstart
           "Pressure start value of the LP mixer"
           annotation (Dialog(tab="Initialization", group="LP mixer"));
 
-        //Valves Parameters
+//Valves Parameters
         parameter Real valveHP_Cv=0 "Cv (US) flow coefficient of the HP valve"
           annotation (Dialog(group="HP valves"));
         parameter SI.Pressure valveHP_dpnom
@@ -14596,13 +14585,13 @@
         "Steam Turbine Group (two pressure levels and reheat) with coupling Heat Usage"
         extends Interfaces.ST_2LRhHU;
 
-        //Mixers Parameters
+//Mixers Parameters
         parameter SI.Volume mixLP_V "Internal volume of the LP mixer";
         parameter SI.Pressure mixLP_pstart
           "Pressure start value of the LP mixer"
           annotation (Dialog(tab="Initialization", group="LP mixer"));
 
-        //Valves Parameters
+//Valves Parameters
         parameter Real valveHP_Cv=0 "Cv (US) flow coefficient of the HP valve"
           annotation (Dialog(group="HP valves"));
         parameter SI.Pressure valveHP_dpnom
@@ -16600,11 +16589,11 @@
       partial model DoubleShaft
         "Base Class for alternator group, configuration double-shaft (two generator)"
 
-        //grid
+//grid
         parameter SI.Frequency fn=50 "Nominal frequency of the grid";
         parameter SI.Power Pn "Nominal power installed on the grid";
 
-        //generators
+//generators
         parameter Real eta_A=1
           "Conversion efficiency of the electric generator"
           annotation (Dialog(group="Generator-Shaft A"));
@@ -16612,7 +16601,7 @@
           "Conversion efficiency of the electric generator"
           annotation (Dialog(group="Generator-Shaft B"));
 
-        //other parameter
+//other parameter
         parameter SI.MomentOfInertia J_shaft_A=0
           "Total inertia of the steam turbogenerator"
           annotation (Dialog(group="Generator-Shaft A"));
@@ -16763,11 +16752,11 @@
       partial model TripleShaft
         "Base Class for alternator group, configuration triple-shaft (three generator)"
 
-        //grid
+//grid
         parameter SI.Frequency fn=50 "Nominal frequency of the grid";
         parameter SI.Power Pn "Nominal power installed on the grid";
 
-        //generators
+//generators
         parameter Real eta_A=1
           "Conversion efficiency of the electric generator"
           annotation (Dialog(group="Generator-Shaft A"));
@@ -16778,7 +16767,7 @@
           "Conversion efficiency of the electric generator"
           annotation (Dialog(group="Generator-Shaft C"));
 
-        //other parameter
+//other parameter
         parameter SI.MomentOfInertia J_shaft_A=0
           "Total inertia of the steam turbogenerator"
           annotation (Dialog(group="Generator-Shaft A"));
@@ -17191,7 +17180,7 @@
       package OldElementsSwingEquation
         model Generator_SE
           "Electric generator inclusive of approximate swing equation"
-          //Parameter
+          //Parameter
           parameter Real eta=1 "Conversion efficiency";
           parameter Integer Np=2 "Number of couple of electrical poles";
           parameter SI.Power Pmax "Output maximum power";
@@ -17201,9 +17190,9 @@
             "Nominal angulary velocity of shaft";
           parameter SI.Angle delta_start "Loaded angle start value";
 
-          //Variable
+//Variable
           SI.AngularVelocity omega "Shaft angular velocity";
-          SI.Conversions.NonSIunits.AngularVelocity_rpm n "Rotational speed";
+          Modelica.Units.NonSI.AngularVelocity_rpm n "Rotational speed";
           SI.Angle delta(start=delta_start) "Loaded angle";
           SI.AngularVelocity d_delta "Variation of loaded angle";
           SI.AngularVelocity omegaGrid "Angulary velocity in the grid";
@@ -17212,7 +17201,7 @@
           Real M "Auxiliary variable";
           Real D "Auxiliary variable";
 
-          //Connector
+//Connector
           Electrical.PowerConnection powerConnection annotation (Placement(
                 transformation(extent={{58,-14},{86,14}}, rotation=0)));
           Modelica.Mechanics.Rotational.Interfaces.Flange_a shaft annotation (
@@ -17222,18 +17211,15 @@
           M = J/(Np^2)*omega_nom*Np;
           D = 2*r*sqrt(Pmax*J*omega_nom*Np/(Np^2));
           omega = der(shaft.phi);
-          Pm = omega*shaft.tau;
-          n = Modelica.SIunits.Conversions.to_rpm(omega)
-            "Rotational speed in rpm";
+          Pm = omega*shaft.tau;
+  n = Modelica.Units.Conversions.to_rpm(omega) "Rotational speed in rpm";
           omegaGrid = 2*Modelica.Constants.pi*powerConnection.f;
-          powerConnection.W = -Pe;
-
-          //Definition of loaded angle
-          d_delta = omega*Np - omegaGrid;
-          der(delta) = d_delta;
-
-          //Swing Equation
-          M*der(d_delta) + D*d_delta = Pm - Pe/eta;
+          powerConnection.W = -Pe;
+//Definition of loaded angle
+          d_delta = omega * Np - omegaGrid;
+          der(delta) = d_delta;
+//Swing Equation
+          M * der(d_delta) + D * d_delta = Pm - Pe / eta;
           Pe = Pmax*Modelica.Math.sin(delta);
 
           annotation (Icon(graphics={Rectangle(
@@ -17268,7 +17254,7 @@
           parameter SI.Angle delta_start "Start value of loaded angle";
 
           SI.AngularVelocity omega "Shaft angular velocity";
-          SI.Conversions.NonSIunits.AngularVelocity_rpm n "Rotational speed";
+          Modelica.Units.NonSI.AngularVelocity_rpm n "Rotational speed";
           SI.Angle delta(start=delta_start) "Loaded angle";
           SI.AngularVelocity d_delta "Variation of loaded angle";
           SI.AngularVelocity omegaGrid "Angulary velocity in the grid";
@@ -17286,18 +17272,15 @@
           M = J/(Np^2)*omega*Np;
           D = 2*r*sqrt(Pmax*J*omega*Np/(Np^2));
           omega = der(shaft.phi);
-          Pm = omega*shaft.tau;
-          n = Modelica.SIunits.Conversions.to_rpm(omega)
-            "Rotational speed in rpm";
+          Pm = omega*shaft.tau;
+  n = Modelica.Units.Conversions.to_rpm(omega) "Rotational speed in rpm";
           omegaGrid = 2*Modelica.Constants.pi*powerConnection.f;
-          powerConnection.W = -Pe;
-
-          //Definition of loaded angle
-          d_delta = omega*Np - omegaGrid;
-          der(delta) = d_delta;
-
-          //Swing Equation
-          M*der(d_delta) + D*d_delta = Pm - Pe;
+          powerConnection.W = -Pe;
+//Definition of loaded angle
+          d_delta = omega * Np - omegaGrid;
+          der(delta) = d_delta;
+//Swing Equation
+          M * der(d_delta) + D * d_delta = Pm - Pe;
           Pe = Pmax*Modelica.Math.sin(delta);
 
           annotation (Icon(graphics={Rectangle(
@@ -17324,7 +17307,7 @@
 
         model Generator_SE_Breaker
           "Electic generator inclusive of approximate swing equation and breaker for connection grid"
-          //Parameters
+          //Parameters
           parameter Real eta=1 "Conversion efficiency";
           parameter Integer Np=2 "Number of couple of electrical poles";
           parameter SI.Power Pmax "Maximum power of generator";
@@ -17337,7 +17320,7 @@
             "Angulaty velocity of shaft start value";
 
           SI.AngularVelocity omega(start=omega_start) "Shaft angular velocity";
-          SI.Conversions.NonSIunits.AngularVelocity_rpm n "Rotational speed";
+          Modelica.Units.NonSI.AngularVelocity_rpm n "Rotational speed";
           SI.Angle delta(start=delta_start) "Loaded angle";
           SI.AngularVelocity d_delta "Variation of loaded angle";
           SI.AngularVelocity omegaGrid "Angulary velocity in the grid";
@@ -17364,29 +17347,23 @@
           M = J/(Np^2)*omega_nom*Np;
           D = 2*r*sqrt(Pmax*J*omega_nom*Np/(Np^2));
           omega = der(shaft.phi);
-          Pm = omega*shaft.tau;
-          n = Modelica.SIunits.Conversions.to_rpm(omega)
-            "Rotational speed in rpm";
+          Pm = omega*shaft.tau;
+  n = Modelica.Units.Conversions.to_rpm(omega) "Rotational speed in rpm";
           omegaGrid = 2*Modelica.Constants.pi*powerConnection.f;
-          powerConnection.W = -Pe;
-
-          //Definition loaded angle
-          d_delta = omega*Np - omegaGrid;
-          der(delta) = d_delta;
-
-          //swing equation
-          M*der(d_delta) + D*d_delta = Pm - Pe/eta;
-          if closed then
-            Pe = Pmax*Modelica.Math.sin(delta);
-          else
-            //Free turbine and not connection a grid
-            Pe = 0;
-          end if;
-
-          //Output signal
-          delta_out = delta - integer(delta/(2*Modelica.Constants.pi))*2*
-            Modelica.Constants.pi;
-
+          powerConnection.W = -Pe;
+//Definition loaded angle
+          d_delta = omega * Np - omegaGrid;
+          der(delta) = d_delta;
+//swing equation
+          M * der(d_delta) + D * d_delta = Pm - Pe / eta;
+  if closed then
+            Pe = Pmax * Modelica.Math.sin(delta);
+          else
+//Free turbine and not connection a grid
+            Pe = 0;
+          end if;
+//Output signal
+          delta_out = delta - integer(delta / (2 * Modelica.Constants.pi)) * 2 * Modelica.Constants.pi;
           annotation (
             Icon(graphics={Rectangle(
                           extent={{-60,8},{-90,-8}},
@@ -18712,8 +18689,8 @@
 
     model PID "PID controller with anti-windup"
       parameter Real Kp "Proportional gain (normalised units)";
-      parameter Modelica.SIunits.Time Ti "Integral time";
-      parameter Modelica.SIunits.Time Td=0 "Derivative time";
+      parameter Modelica.Units.SI.Time Ti "Integral time";
+      parameter Modelica.Units.SI.Time Td=0 "Derivative time";
       parameter Real Nd=1 "Derivative action up to Nd / Td rad/s";
       parameter Real Ni=1
         "Ni*Ti is the time constant of anti-windup compensation";
@@ -18749,13 +18726,13 @@
           Placement(transformation(extent={{88,-12},{112,12}}, rotation=0)));
       Modelica.Blocks.Interfaces.RealInput SP "Set point signal" annotation (
           Placement(transformation(extent={{-112,28},{-88,52}}, rotation=0)));
-    equation
-      // Scaling
-      SPs = (SP - PVmin)/(PVmax - PVmin);
+    equation
+// Scaling
+      SPs = (SP - PVmin) / (PVmax - PVmin);
       PVs = (PV - PVmin)/(PVmax - PVmin);
-      CS = CSmin + CSs*(CSmax - CSmin);
-      // Controller actions
-      P = b*SPs - PVs;
+      CS = CSmin + CSs*(CSmax - CSmin);
+// Controller actions
+      P = b * SPs - PVs;
       if Ti > 0 then
         Ti*der(I) = SPs - PVs + track;
       else
@@ -18840,8 +18817,7 @@
   package Buses "Expandable signal buses definitions"
 
     expandable connector Sensors
-      // Empty connector, defined by expansion
-
+      // Empty connector, defined by expansion
       annotation (Icon(graphics={Polygon(
                   points={{-100,100},{100,100},{100,0},{100,-100},{-100,-100},{
                 -100,100}},
@@ -18856,7 +18832,7 @@
     end Sensors;
 
     expandable connector Actuators
-      // Empty connector, defined by expansion
+      // Empty connector, defined by expansion
       annotation (Icon(graphics={Polygon(
                   points={{-100,100},{100,100},{100,0},{100,-100},{-100,-100},{
                 -100,100}},
diff -ur "/home/hudson/saved_omc/libraries/.openmodelica/libraries/ThermoPower 3.1.0-master/Test.mo" "converted-libraries/.openmodelica/libraries/ThermoPower 3.1.0-master/Test.mo"
--- "/home/hudson/saved_omc/libraries/.openmodelica/libraries/ThermoPower 3.1.0-master/Test.mo"	2022-03-10 09:57:37.952144121 +0000
+++ "converted-libraries/.openmodelica/libraries/ThermoPower 3.1.0-master/Test.mo"	2022-03-10 09:58:49.536153187 +0000
@@ -2,6 +2,7 @@
 package Test "Test cases for the ThermoPower models"
   extends Modelica.Icons.ExamplesPackage;
 
+
   package WaterComponents
     "Tests for lumped-parameters Water package components"
     extends Modelica.Icons.ExamplesPackage;
@@ -198,7 +199,7 @@
     model TestMixerSlowFast
       extends Modelica.Icons.Example;
       package Medium=Modelica.Media.Water.StandardWater;
-      // package Medium = Modelica.Media.Incompressible.Examples.Glycol47;
+      // package Medium = Modelica.Media.Incompressible.Examples.Glycol47;
       Water.SourceMassFlow
                     SourceW1(
         w0=0.5,
@@ -300,7 +301,7 @@
     model TestMixerSlowFastSteam
       extends Modelica.Icons.Example;
       package Medium=Modelica.Media.Water.StandardWater;
-      // package Medium = Modelica.Media.Incompressible.Examples.Glycol47;
+      // package Medium = Modelica.Media.Incompressible.Examples.Glycol47;
       Water.SourceMassFlow
                     SourceW1(
         w0=0.5,
@@ -580,7 +581,7 @@
       Modelica.Blocks.Sources.Sine Cmd1(
         startTime=0,
         amplitude=5,
-        freqHz=1,
+f        =1,
         offset=0) annotation (Placement(transformation(extent={{-82,10},{-62,30}},
               rotation=0)));
       inner ThermoPower.System system
@@ -856,7 +857,7 @@
             transformation(extent={{-10,30},{10,50}}, rotation=0)));
       Modelica.Blocks.Sources.Sine Sine1(
         amplitude=2.5e5,
-        freqHz=0.5,
+f        =0.5,
         offset=3e5,
         phase=3.14159,
         startTime=1) annotation (Placement(transformation(extent={{10,60},{30,
@@ -880,7 +881,7 @@
             transformation(extent={{-10,-50},{10,-30}}, rotation=0)));
       Modelica.Blocks.Sources.Sine Sine2(
         amplitude=49.5e5,
-        freqHz=0.5,
+f        =0.5,
         offset=50e5,
         phase=3.14159,
         startTime=1) annotation (Placement(transformation(extent={{10,-20},{30,
@@ -1251,13 +1252,13 @@
               extent={{-90,-70},{-70,-50}}, rotation=0)));
       Modelica.Blocks.Sources.Sine Sine1(
         amplitude=1,
-        freqHz=1,
+f        =1,
         phase=pi/2,
         offset=0,
         startTime=0) annotation (Placement(transformation(extent={{-90,70},{-70,
                 90}}, rotation=0)));
       Modelica.Blocks.Sources.Sine Sine2(
-        freqHz=0.5,
+        f =0.5,
         amplitude=1,
         phase=pi/2,
         offset=0,
@@ -1276,14 +1277,14 @@
       ThermoPower.Water.SensT T6(redeclare package Medium = Medium) annotation (
          Placement(transformation(extent={{20,-92},{40,-72}}, rotation=0)));
       Modelica.Blocks.Sources.Sine Sine3(
-        freqHz=1,
+        f =1,
         amplitude=1,
         phase=pi/2,
         offset=0,
         startTime=0) annotation (Placement(transformation(extent={{34,-16},{54,
                 4}}, rotation=0)));
       Modelica.Blocks.Sources.Sine Sine4(
-        freqHz=0.5,
+        f =0.5,
         amplitude=1,
         phase=pi/2,
         offset=0,
@@ -2116,14 +2117,14 @@
 
     model SimpleMotor
       "A simple model of an electrical dc motor (based on DriveLib model)."
-      parameter Modelica.SIunits.Resistance Rm=10 "Motor Resistance";
-      parameter Modelica.SIunits.Inductance Lm=1 "Motor Inductance";
+      parameter Modelica.Units.SI.Resistance Rm=10 "Motor Resistance";
+      parameter Modelica.Units.SI.Inductance Lm=1 "Motor Inductance";
       parameter Real kT=1 "Torque Constant";
-      parameter Modelica.SIunits.Inertia Jm=10 "Motor Inertia";
+      parameter Modelica.Units.SI.Inertia Jm=10 "Motor Inertia";
       parameter Real dm(
         final unit="N.m.s/rad",
         final min=0) = 0 "Damping constant";
-      Modelica.SIunits.Conversions.NonSIunits.AngularVelocity_rpm n;
+      Modelica.Units.NonSI.AngularVelocity_rpm n;
       Modelica.Electrical.Analog.Sources.SignalVoltage Vs annotation (Placement(
             transformation(
             origin={-70,0},
@@ -2135,7 +2136,7 @@
             transformation(extent={{-60,30},{-40,50}}, rotation=0)));
       Modelica.Electrical.Analog.Basic.Inductor L(L=Lm) annotation (Placement(
             transformation(extent={{-20,30},{0,50}}, rotation=0)));
-      Modelica.Electrical.Analog.Basic.EMF emf(k=kT) annotation (Placement(
+      Modelica.Electrical.Analog.Basic.RotationalEMF emf(k=kT) annotation (Placement(
             transformation(extent={{0,-10},{20,10}}, rotation=0)));
       Modelica.Blocks.Interfaces.RealInput inPort annotation (Placement(
             transformation(extent={{-108,-10},{-90,10}}, rotation=0)));
@@ -2151,7 +2152,7 @@
             extent={{-10,-10},{10,10}},
             rotation=90)));
     equation
-      n = Modelica.SIunits.Conversions.to_rpm(J.w);
+      n = Modelica.Units.Conversions.to_rpm(J.w);
       connect(R.n, L.p) annotation (Line(points={{-40,40},{-20,40}}));
       connect(L.n, emf.p) annotation (Line(points={{0,40},{10,40},{10,10}}));
       connect(emf.flange, J.flange_a) annotation (Line(points={{20,0},{48,0}}));
@@ -3510,7 +3511,7 @@
         phase=0,
         offset=5e5,
         startTime=0.1,
-        freqHz=0.2,
+f        =0.2,
         amplitude=3e5) annotation (Placement(transformation(extent={{-94,40},{-74,
                 60}}, rotation=0)));
       Gas.SourcePressure
@@ -3555,13 +3556,12 @@
       Modelica.Blocks.Sources.Sine Sine2(
         phase=0,
         startTime=0.1,
-        freqHz=0.2,
+f        =0.2,
         amplitude=5e5,
         offset=7e5) annotation (Placement(transformation(extent={{-96,-32},{-76,
                 -12}}, rotation=0)));
-      //initial equation
-      //Valve2.w=1;
-
+      //initial equation
+      //Valve2.w=1;
       inner System system
         annotation (Placement(transformation(extent={{80,80},{100,100}})));
     equation
@@ -3642,7 +3642,7 @@
       Modelica.Blocks.Sources.Sine Sine1(
         amplitude=2e5,
         offset=3.5e5,
-        freqHz=0.4) annotation (Placement(transformation(extent={{40,40},{60,60}},
+f        =0.4) annotation (Placement(transformation(extent={{40,40},{60,60}},
               rotation=0)));
       Modelica.Blocks.Sources.Step Step1(
         offset=1,
@@ -3681,7 +3681,7 @@
       Modelica.Blocks.Sources.Sine Sine2(
         amplitude=2e5,
         offset=3.5e5,
-        freqHz=0.4) annotation (Placement(transformation(extent={{40,-30},{60,-10}},
+f        =0.4) annotation (Placement(transformation(extent={{40,-30},{60,-10}},
               rotation=0)));
       Modelica.Blocks.Sources.Step Step3(
         offset=1,
@@ -3808,7 +3808,7 @@
         height=-0.6) annotation (Placement(transformation(extent={{10,70},{30,
                 90}}, rotation=0)));
       Modelica.Blocks.Sources.Sine Sine2(
-        freqHz=0.5,
+        f =0.5,
         offset=4e5,
         amplitude=2e5) annotation (Placement(transformation(extent={{46,70},{66,
                 90}}, rotation=0)));
@@ -3873,7 +3873,7 @@
         Tstart=500)                                  annotation (Placement(
             transformation(extent={{30,-30},{50,-10}}, rotation=0)));
       Modelica.Blocks.Sources.Sine Sine1(
-        freqHz=0.5,
+        f =0.5,
         amplitude=2e5,
         offset=4e5) annotation (Placement(transformation(extent={{46,0},{66,20}},
               rotation=0)));
@@ -4794,7 +4794,7 @@
             Modelica.Media.Air.SimpleAir) annotation (Placement(transformation(
               extent={{-98,-10},{-78,10}}, rotation=0)));
       Modelica.Mechanics.Rotational.Sources.ConstantSpeed ConstantSpeed1(
-          w_fixed=Modelica.SIunits.Conversions.from_rpm(590), useSupport=false)
+          w_fixed=Modelica.Units.Conversions.from_rpm(590), useSupport=false)
         annotation (Placement(transformation(extent={{90,-10},{70,10}},
               rotation=0)));
       function flowChar = Functions.FanCharacteristics.quadraticFlowBlades (
@@ -4819,7 +4819,7 @@
         offset=1) annotation (Placement(transformation(extent={{-30,54},{-10,74}},
               rotation=0)));
       Modelica.Mechanics.Rotational.Components.Inertia Inertia1(w(start=
-              Modelica.SIunits.Conversions.from_rpm(590)), J=10000,
+              Modelica.Units.Conversions.from_rpm(590)), J=10000,
         phi(fixed=true, start=0))                                   annotation (
          Placement(transformation(extent={{-20,-10},{0,10}}, rotation=0)));
       Gas.PressDrop PressDrop1(
@@ -4881,24 +4881,24 @@
       replaceable package Medium = Modelica.Media.Water.WaterIF97_ph
         constrainedby Modelica.Media.Interfaces.PartialMedium;
       parameter Integer Nnodes=20 "Number of nodes";
-      parameter Modelica.SIunits.Length Lhex=10 "Total length";
-      parameter Modelica.SIunits.Diameter Dihex=0.02 "Internal diameter";
-      final parameter Modelica.SIunits.Radius rhex=Dihex/2 "Internal radius";
-      final parameter Modelica.SIunits.Length omegahex=Modelica.Constants.pi*Dihex
+      parameter Modelica.Units.SI.Length Lhex=10 "Total length";
+      parameter Modelica.Units.SI.Diameter Dihex=0.02 "Internal diameter";
+      final parameter Modelica.Units.SI.Radius rhex=Dihex/2 "Internal radius";
+      final parameter Modelica.Units.SI.Length omegahex=Modelica.Constants.pi*Dihex
         "Internal perimeter";
-      final parameter Modelica.SIunits.Area Ahex=Modelica.Constants.pi*rhex^2
+      final parameter Modelica.Units.SI.Area Ahex=Modelica.Constants.pi*rhex^2
         "Internal cross section";
       parameter Real Cfhex=0.005 "Friction coefficient";
-      parameter Modelica.SIunits.MassFlowRate whex=0.31
+      parameter Modelica.Units.SI.MassFlowRate whex=0.31
         "Nominal mass flow rate";
-      parameter Modelica.SIunits.Pressure phex=2e5 "Initial pressure";
-      parameter Modelica.SIunits.SpecificEnthalpy hinhex=1e5
+      parameter Modelica.Units.SI.Pressure phex=2e5 "Initial pressure";
+      parameter Modelica.Units.SI.SpecificEnthalpy hinhex=1e5
         "Initial inlet specific enthalpy";
-      parameter Modelica.SIunits.SpecificEnthalpy houthex=1e5
+      parameter Modelica.Units.SI.SpecificEnthalpy houthex=1e5
         "Initial outlet specific enthalpy";
-      parameter Modelica.SIunits.SpecificEnthalpy deltah=41800
+      parameter Modelica.Units.SI.SpecificEnthalpy deltah=41800
         "Height of enthalpy step";
-      parameter Modelica.SIunits.EnergyFlowRate W=41800*whex
+      parameter Modelica.Units.SI.EnergyFlowRate W=41800*whex
         "Height of power step";
 
       SI.Time tau "Transport time delay";
@@ -5023,20 +5023,20 @@
         constrainedby Modelica.Media.Interfaces.PartialMedium;
       parameter Integer Nnodes=10 "Number of nodes";
       parameter Integer Nt = 5 "Number of tubes";
-      parameter Modelica.SIunits.Length Lhex=2 "Total length";
-      parameter Modelica.SIunits.Diameter Dihex=0.02 "Internal diameter";
-      final parameter Modelica.SIunits.Radius rhex=Dihex/2 "Internal radius";
-      final parameter Modelica.SIunits.Length omegahex=Modelica.Constants.pi*Dihex
+      parameter Modelica.Units.SI.Length Lhex=2 "Total length";
+      parameter Modelica.Units.SI.Diameter Dihex=0.02 "Internal diameter";
+      final parameter Modelica.Units.SI.Radius rhex=Dihex/2 "Internal radius";
+      final parameter Modelica.Units.SI.Length omegahex=Modelica.Constants.pi*Dihex
         "Internal perimeter";
-      final parameter Modelica.SIunits.Area Ahex=Modelica.Constants.pi*rhex^2
+      final parameter Modelica.Units.SI.Area Ahex=Modelica.Constants.pi*rhex^2
         "Internal cross section";
       parameter Real Cfhex=0.005 "Friction coefficient";
-      parameter Modelica.SIunits.MassFlowRate whex=0.31
+      parameter Modelica.Units.SI.MassFlowRate whex=0.31
         "Nominal mass flow rate";
-      parameter Modelica.SIunits.Pressure phex=3e5 "Initial pressure";
-      parameter Modelica.SIunits.SpecificEnthalpy hs=1e5
+      parameter Modelica.Units.SI.Pressure phex=3e5 "Initial pressure";
+      parameter Modelica.Units.SI.SpecificEnthalpy hs=1e5
         "Initial inlet specific enthalpy";
-      parameter Modelica.SIunits.CoefficientOfHeatTransfer gamma = 1500
+      parameter Modelica.Units.SI.CoefficientOfHeatTransfer gamma = 1500
         "Fixed heat transfer coefficient";
       Real cp = Medium.specificHeatCapacityCp(hex.fluidState[1]);
       Real NTU = (Nt*Lhex*Dihex*3.1415*gamma)/(whex*Medium.specificHeatCapacityCp(hex.fluidState[1]))
@@ -5147,18 +5147,18 @@
         constrainedby Modelica.Media.Interfaces.PartialMedium;
       parameter Integer Nnodes=5 "number of Nodes";
       parameter Integer Nt = 10 "number of tubes in parallel";
-      parameter Modelica.SIunits.Length Lhex=10 "total length";
-      parameter Modelica.SIunits.Diameter Dihex=0.02 "internal diameter";
-      parameter Modelica.SIunits.Radius rhex=Dihex/2 "internal radius";
-      parameter Modelica.SIunits.Length omegahex=Modelica.Constants.pi*Dihex
+      parameter Modelica.Units.SI.Length Lhex=10 "total length";
+      parameter Modelica.Units.SI.Diameter Dihex=0.02 "internal diameter";
+      parameter Modelica.Units.SI.Radius rhex=Dihex/2 "internal radius";
+      parameter Modelica.Units.SI.Length omegahex=Modelica.Constants.pi*Dihex
         "internal perimeter";
-      parameter Modelica.SIunits.Area Ahex=Modelica.Constants.pi*rhex^2
+      parameter Modelica.Units.SI.Area Ahex=Modelica.Constants.pi*rhex^2
         "internal cross section";
       parameter Real Cfhex=0.005 "friction coefficient";
-      parameter Modelica.SIunits.MassFlowRate whex=1e-2
+      parameter Modelica.Units.SI.MassFlowRate whex=1e-2
         "nominal mass flow rate";
-      parameter Modelica.SIunits.Pressure phex=0.2e5 "initial pressure";
-      parameter Modelica.SIunits.SpecificEnthalpy hs=2.971e6
+      parameter Modelica.Units.SI.Pressure phex=0.2e5 "initial pressure";
+      parameter Modelica.Units.SI.SpecificEnthalpy hs=2.971e6
         "initial specific enthalpy";
       Real gamma = Medium.specificHeatCapacityCp(hex.fluidState[1])/Medium.specificHeatCapacityCv(hex.fluidState[1]) "cp/cv";
       Real dMtot_dp = hex.Mtot/(hex.p*gamma) "compressibility";
@@ -5258,24 +5258,24 @@
       replaceable package Medium = Modelica.Media.Water.WaterIF97OnePhase_ph
         constrainedby Modelica.Media.Interfaces.PartialMedium;
       parameter Integer Nnodes=20 "number of nodes";
-      parameter Modelica.SIunits.Length Lhex=200 "total length";
-      parameter Modelica.SIunits.Diameter Dihex=0.02
+      parameter Modelica.Units.SI.Length Lhex=200 "total length";
+      parameter Modelica.Units.SI.Diameter Dihex=0.02
         "diameter of internal tube";
-      parameter Modelica.SIunits.Diameter Dehex=0.04
+      parameter Modelica.Units.SI.Diameter Dehex=0.04
         "diameter of external tube";
-      parameter Modelica.SIunits.Length omegahex=Modelica.Constants.pi*Dihex
+      parameter Modelica.Units.SI.Length omegahex=Modelica.Constants.pi*Dihex
         "wet perimeter of the tube interface";
-      parameter Modelica.SIunits.Area Aint=Modelica.Constants.pi*Dihex^2/4
+      parameter Modelica.Units.SI.Area Aint=Modelica.Constants.pi*Dihex^2/4
         "cross section of internal tube";
-      parameter Modelica.SIunits.Area Aext=Modelica.Constants.pi*Dehex^2/4 - Aint
+      parameter Modelica.Units.SI.Area Aext=Modelica.Constants.pi*Dehex^2/4 - Aint
         "cross section of external tube";
       parameter Real Cfhex=0.005 "friction coefficient";
-      parameter Modelica.SIunits.MassFlowRate whex=0.31
+      parameter Modelica.Units.SI.MassFlowRate whex=0.31
         "nominal (and initial) mass flow rate";
-      parameter Modelica.SIunits.Pressure phex=3e5 "initial pressure";
-      parameter Modelica.SIunits.SpecificEnthalpy hinhex=1e5
+      parameter Modelica.Units.SI.Pressure phex=3e5 "initial pressure";
+      parameter Modelica.Units.SI.SpecificEnthalpy hinhex=1e5
         "initial inlet specific enthalpy";
-      parameter Modelica.SIunits.SpecificEnthalpy houthex=1e5
+      parameter Modelica.Units.SI.SpecificEnthalpy houthex=1e5
         "initial outlet specific enthalpy";
 
       Water.SinkPressure      SideA_FluidSink annotation (Placement(
@@ -5439,30 +5439,30 @@
       replaceable package Medium = Modelica.Media.Water.WaterIF97OnePhase_ph
         constrainedby Modelica.Media.Interfaces.PartialMedium;
       parameter Integer Nnodes=20 "number of nodes";
-      parameter Modelica.SIunits.Length Lhex=200 "total length";
-      parameter Modelica.SIunits.Diameter Dihex=0.02
+      parameter Modelica.Units.SI.Length Lhex=200 "total length";
+      parameter Modelica.Units.SI.Diameter Dihex=0.02
         "diameter of internal tube";
-      parameter Modelica.SIunits.Diameter Dehex= 0.04
+      parameter Modelica.Units.SI.Diameter Dehex= 0.04
         "diameter of external tube";
-      parameter Modelica.SIunits.Length th = 0.002 "tube wall thickness";
-      parameter Modelica.SIunits.Radius rint=Dihex/2
+      parameter Modelica.Units.SI.Length th = 0.002 "tube wall thickness";
+      parameter Modelica.Units.SI.Radius rint=Dihex/2
         "internal radius tube walls";
-      parameter Modelica.SIunits.Radius rext=rint+th
+      parameter Modelica.Units.SI.Radius rext=rint+th
         "internal radius tube walls";
-      parameter Modelica.SIunits.Length omegaint=Modelica.Constants.pi*Dihex
+      parameter Modelica.Units.SI.Length omegaint=Modelica.Constants.pi*Dihex
         "wet perimeter internal tube";
-      parameter Modelica.SIunits.Length omegaext=Modelica.Constants.pi*(Dihex+2*th)
+      parameter Modelica.Units.SI.Length omegaext=Modelica.Constants.pi*(Dihex+2*th)
         "wet perimeter internal tube";
-      parameter Modelica.SIunits.Area Aint=Modelica.Constants.pi*rint^2;
-      parameter Modelica.SIunits.Area Aext=Modelica.Constants.pi*Dehex^2/4 -
+      parameter Modelica.Units.SI.Area Aint=Modelica.Constants.pi*rint^2;
+      parameter Modelica.Units.SI.Area Aext=Modelica.Constants.pi*Dehex^2/4 -
                                            Modelica.Constants.pi*rext^2;
       parameter Real Cfhex=0.005 "friction coefficient";
-      parameter Modelica.SIunits.MassFlowRate whex=0.31
+      parameter Modelica.Units.SI.MassFlowRate whex=0.31
         "nominal (and initial) mass flow rate";
-      parameter Modelica.SIunits.Pressure phex=3e5 "initial pressure";
-      parameter Modelica.SIunits.SpecificEnthalpy hinhex=1e5
+      parameter Modelica.Units.SI.Pressure phex=3e5 "initial pressure";
+      parameter Modelica.Units.SI.SpecificEnthalpy hinhex=1e5
         "initial inlet specific enthalpy";
-      parameter Modelica.SIunits.SpecificEnthalpy houthex=1e5
+      parameter Modelica.Units.SI.SpecificEnthalpy houthex=1e5
         "initial outlet specific enthalpy";
 
       Water.SinkPressure      SideA_FluidSink annotation (Placement(
@@ -5640,18 +5640,18 @@
       replaceable package Medium = Modelica.Media.Water.WaterIF97OnePhase_ph
         constrainedby Modelica.Media.Interfaces.PartialMedium;
       parameter Integer Nnodes=10 "number of Nodes";
-      parameter Modelica.SIunits.Length Lhex=10 "total length";
-      parameter Modelica.SIunits.Diameter Dihex=0.02 "internal diameter";
-      parameter Modelica.SIunits.Radius rhex=Dihex/2 "internal radius";
-      parameter Modelica.SIunits.Length omegahex=Modelica.Constants.pi*Dihex
+      parameter Modelica.Units.SI.Length Lhex=10 "total length";
+      parameter Modelica.Units.SI.Diameter Dihex=0.02 "internal diameter";
+      parameter Modelica.Units.SI.Radius rhex=Dihex/2 "internal radius";
+      parameter Modelica.Units.SI.Length omegahex=Modelica.Constants.pi*Dihex
         "internal perimeter";
-      parameter Modelica.SIunits.Area Ahex=Modelica.Constants.pi*rhex^2
+      parameter Modelica.Units.SI.Area Ahex=Modelica.Constants.pi*rhex^2
         "internal cross-section";
       parameter Real Cfhex=0.005 "friction coefficient";
-      parameter Modelica.SIunits.MassFlowRate whex=0.31
+      parameter Modelica.Units.SI.MassFlowRate whex=0.31
         "nominal mass flow rate";
-      parameter Modelica.SIunits.Pressure phex=3e5 "initial pressure";
-      parameter Modelica.SIunits.SpecificEnthalpy hs=1e5
+      parameter Modelica.Units.SI.Pressure phex=3e5 "initial pressure";
+      parameter Modelica.Units.SI.SpecificEnthalpy hs=1e5
         "initial inlet specific enthalpy";
 
       Water.Flow1DFV hexFV(
@@ -5746,7 +5746,7 @@
        extends TestWaterFlow1DFV_A(
          redeclare package Medium =
             Modelica.Media.CompressibleLiquids.LinearWater_pT_Ambient);
-      // package Medium = Media.LiquidWaterConstant;
+      // package Medium = Media.LiquidWaterConstant;
     annotation (
         Diagram(graphics),
         experiment(StopTime=80, Tolerance=1e-006),
@@ -5777,7 +5777,7 @@
       parameter SI.Pressure phex=3e5 "initial pressure";
       parameter SI.Temperature Tinhex=300 "initial inlet temperature";
       parameter SI.Temperature Touthex=300 "initial outlet temperature";
-      // parameter Temperature deltaT=10 "height of temperature step";
+      // parameter Temperature deltaT=10 "height of temperature step";
       parameter SI.EnergyFlowRate W=500 "height of power step";
       Real gamma = Medium.specificHeatCapacityCp(hex.gas[1].state)/Medium.specificHeatCapacityCv(hex.gas[1].state) "cp/cv";
       Real dMtot_dp = hex.Mtot/(hex.p*gamma) "compressibility";
@@ -5939,34 +5939,34 @@
       extends Modelica.Icons.Example;
       replaceable package Medium = Modelica.Media.Water.WaterIF97OnePhase_ph
         constrainedby Modelica.Media.Interfaces.PartialMedium;
-      // number of Nodes
+      // number of Nodes
       parameter Integer Nnodes=12;
       // total length
-      parameter Modelica.SIunits.Length Lhex=10;
+      parameter Modelica.Units.SI.Length Lhex=10;
       // internal diameter
-      parameter Modelica.SIunits.Diameter Dihex=0.02;
+      parameter Modelica.Units.SI.Diameter Dihex=0.02;
       // internal radius
-      parameter Modelica.SIunits.Radius rhex=Dihex/2;
+      parameter Modelica.Units.SI.Radius rhex=Dihex/2;
       // internal perimeter
-      parameter Modelica.SIunits.Length omegahex=Modelica.Constants.pi*Dihex;
+      parameter Modelica.Units.SI.Length omegahex=Modelica.Constants.pi*Dihex;
       // internal cross section
-      parameter Modelica.SIunits.Area Ahex=Modelica.Constants.pi*rhex^2;
-      // friction coefficient
+      parameter Modelica.Units.SI.Area Ahex=Modelica.Constants.pi*rhex^2;
+      // friction coefficient
       parameter Real Cfhex=0.005;
       // nominal (and initial) mass flow rate
-      parameter Modelica.SIunits.MassFlowRate whex=0.3;
+      parameter Modelica.Units.SI.MassFlowRate whex=0.3;
       // initial pressure
-      parameter Modelica.SIunits.Pressure phex=2e5;
+      parameter Modelica.Units.SI.Pressure phex=2e5;
       // initial inlet specific enthalpy
-      parameter Modelica.SIunits.SpecificEnthalpy hinhex=1e5;
+      parameter Modelica.Units.SI.SpecificEnthalpy hinhex=1e5;
       // initial outlet specific enthalpy
-      parameter Modelica.SIunits.SpecificEnthalpy houthex=1e5;
+      parameter Modelica.Units.SI.SpecificEnthalpy houthex=1e5;
 
       //height of enthalpy step
-      parameter Modelica.SIunits.SpecificEnthalpy deltah=41800;
+      parameter Modelica.Units.SI.SpecificEnthalpy deltah=41800;
 
       //height of power step
-      parameter Modelica.SIunits.EnergyFlowRate W=41800*whex;
+      parameter Modelica.Units.SI.EnergyFlowRate W=41800*whex;
 
       ThermoPower.Water.SourceMassFlow Fluid_Source(
         redeclare package Medium = Medium,
@@ -6093,26 +6093,26 @@
       extends Modelica.Icons.Example;
       replaceable package Medium = Modelica.Media.Water.WaterIF97OnePhase_ph
         constrainedby Modelica.Media.Interfaces.PartialMedium;
-      // number of Nodes
+      // number of Nodes
       parameter Integer Nnodes=12;
       // total length
-      parameter Modelica.SIunits.Length Lhex=200;
+      parameter Modelica.Units.SI.Length Lhex=200;
       // internal diameter
-      parameter Modelica.SIunits.Diameter Dihex=0.02;
+      parameter Modelica.Units.SI.Diameter Dihex=0.02;
       // internal radius
-      parameter Modelica.SIunits.Radius rhex=Dihex/2;
+      parameter Modelica.Units.SI.Radius rhex=Dihex/2;
       // internal perimeter
-      parameter Modelica.SIunits.Length omegahex=Modelica.Constants.pi*Dihex;
+      parameter Modelica.Units.SI.Length omegahex=Modelica.Constants.pi*Dihex;
       // internal cross section
-      parameter Modelica.SIunits.Area Ahex=Modelica.Constants.pi*rhex^2;
-      // friction coefficient
+      parameter Modelica.Units.SI.Area Ahex=Modelica.Constants.pi*rhex^2;
+      // friction coefficient
       parameter Real Cfhex=0.005;
       // nominal (and initial) mass flow rate
-      parameter Modelica.SIunits.MassFlowRate whex=0.31;
+      parameter Modelica.Units.SI.MassFlowRate whex=0.31;
       // initial pressure
-      parameter Modelica.SIunits.Pressure phex=3e5;
+      parameter Modelica.Units.SI.Pressure phex=3e5;
       // initial inlet specific enthalpy
-      parameter Modelica.SIunits.SpecificEnthalpy hs=1e5;
+      parameter Modelica.Units.SI.SpecificEnthalpy hs=1e5;
       Water.Flow1DFEM hex(
         redeclare package Medium = Medium,
         N=Nnodes,
@@ -6233,26 +6233,26 @@
       extends Modelica.Icons.Example;
       replaceable package Medium = Modelica.Media.Water.WaterIF97OnePhase_ph
         constrainedby Modelica.Media.Interfaces.PartialMedium;
-      // number of Nodes
+      // number of Nodes
       parameter Integer Nnodes=12;
       // total length
-      parameter Modelica.SIunits.Length Lhex=200;
+      parameter Modelica.Units.SI.Length Lhex=200;
       // internal diameter
-      parameter Modelica.SIunits.Diameter Dihex=0.02;
+      parameter Modelica.Units.SI.Diameter Dihex=0.02;
       // internal radius
-      parameter Modelica.SIunits.Radius rhex=Dihex/2;
+      parameter Modelica.Units.SI.Radius rhex=Dihex/2;
       // internal perimeter
-      parameter Modelica.SIunits.Length omegahex=Modelica.Constants.pi*Dihex;
+      parameter Modelica.Units.SI.Length omegahex=Modelica.Constants.pi*Dihex;
       // internal cross section
-      parameter Modelica.SIunits.Area Ahex=Modelica.Constants.pi*rhex^2;
-      // friction coefficient
+      parameter Modelica.Units.SI.Area Ahex=Modelica.Constants.pi*rhex^2;
+      // friction coefficient
       parameter Real Cfhex=0.005;
       // nominal (and initial) mass flow rate
-      parameter Modelica.SIunits.MassFlowRate whex=0.3;
+      parameter Modelica.Units.SI.MassFlowRate whex=0.3;
       // initial pressure
-      parameter Modelica.SIunits.Pressure phex=1e5;
+      parameter Modelica.Units.SI.Pressure phex=1e5;
       // initial specific enthalpy
-      parameter Modelica.SIunits.SpecificEnthalpy hs=1e5;
+      parameter Modelica.Units.SI.SpecificEnthalpy hs=1e5;
       Water.Flow1DFEM hex(
         redeclare package Medium = Medium,
         N=Nnodes,
@@ -6367,26 +6367,26 @@
       extends Modelica.Icons.Example;
       replaceable package Medium = Modelica.Media.Water.WaterIF97OnePhase_ph
         constrainedby Modelica.Media.Interfaces.PartialMedium;
-      // number of Nodes
+      // number of Nodes
       parameter Integer Nnodes=12;
       // total length
-      parameter Modelica.SIunits.Length Lhex=10;
+      parameter Modelica.Units.SI.Length Lhex=10;
       // internal diameter
-      parameter Modelica.SIunits.Diameter Dihex=0.02;
+      parameter Modelica.Units.SI.Diameter Dihex=0.02;
       // internal radius
-      parameter Modelica.SIunits.Radius rhex=Dihex/2;
+      parameter Modelica.Units.SI.Radius rhex=Dihex/2;
       // internal perimeter
-      parameter Modelica.SIunits.Length omegahex=Modelica.Constants.pi*Dihex;
+      parameter Modelica.Units.SI.Length omegahex=Modelica.Constants.pi*Dihex;
       // internal cross section
-      parameter Modelica.SIunits.Area Ahex=Modelica.Constants.pi*rhex^2;
-      // friction coefficient
+      parameter Modelica.Units.SI.Area Ahex=Modelica.Constants.pi*rhex^2;
+      // friction coefficient
       parameter Real Cfhex=0.005;
       // nominal (and initial) mass flow rate
-      parameter Modelica.SIunits.MassFlowRate whex=1e-2;
+      parameter Modelica.Units.SI.MassFlowRate whex=1e-2;
       // initial pressure
-      parameter Modelica.SIunits.Pressure phex=0.2e5;
+      parameter Modelica.Units.SI.Pressure phex=0.2e5;
       // initial specific enthalpy
-      parameter Modelica.SIunits.SpecificEnthalpy hs=3e6;
+      parameter Modelica.Units.SI.SpecificEnthalpy hs=3e6;
       Water.Flow1DFEM hex(
         redeclare package Medium = Medium,
         N=Nnodes,
@@ -6486,28 +6486,28 @@
       extends Modelica.Icons.Example;
       replaceable package Medium = Modelica.Media.Water.WaterIF97OnePhase_ph
         constrainedby Modelica.Media.Interfaces.PartialMedium;
-      // number of Nodes
+      // number of Nodes
       parameter Integer Nnodes=12;
       // total length
-      parameter Modelica.SIunits.Length Lhex=200;
+      parameter Modelica.Units.SI.Length Lhex=200;
       // internal diameter
-      parameter Modelica.SIunits.Diameter Dihex=0.02;
+      parameter Modelica.Units.SI.Diameter Dihex=0.02;
       // internal radius
-      parameter Modelica.SIunits.Radius rhex=Dihex/2;
+      parameter Modelica.Units.SI.Radius rhex=Dihex/2;
       // internal perimeter
-      parameter Modelica.SIunits.Length omegahex=Modelica.Constants.pi*Dihex;
+      parameter Modelica.Units.SI.Length omegahex=Modelica.Constants.pi*Dihex;
       // internal cross section
-      parameter Modelica.SIunits.Area Ahex=Modelica.Constants.pi*rhex^2;
-      // friction coefficient
+      parameter Modelica.Units.SI.Area Ahex=Modelica.Constants.pi*rhex^2;
+      // friction coefficient
       parameter Real Cfhex=0.005;
       // nominal (and initial) mass flow rate
-      parameter Modelica.SIunits.MassFlowRate whex=0.31;
+      parameter Modelica.Units.SI.MassFlowRate whex=0.31;
       // initial pressure
-      parameter Modelica.SIunits.Pressure phex=3e5;
+      parameter Modelica.Units.SI.Pressure phex=3e5;
       // initial inlet specific enthalpy
-      parameter Modelica.SIunits.SpecificEnthalpy hinhex=1e5;
+      parameter Modelica.Units.SI.SpecificEnthalpy hinhex=1e5;
       // initial outlet specific enthalpy
-      parameter Modelica.SIunits.SpecificEnthalpy houthex=1e5;
+      parameter Modelica.Units.SI.SpecificEnthalpy houthex=1e5;
       Water.Flow1DFEM hexA(
         N=Nnodes,
         Nt=1,
@@ -6695,28 +6695,28 @@
       extends Modelica.Icons.Example;
       replaceable package Medium = Modelica.Media.Water.WaterIF97OnePhase_ph
         constrainedby Modelica.Media.Interfaces.PartialMedium;
-      // number of Nodes
+      // number of Nodes
       parameter Integer Nnodes=16;
       // total length
-      parameter Modelica.SIunits.Length Lhex=200;
+      parameter Modelica.Units.SI.Length Lhex=200;
       // internal diameter
-      parameter Modelica.SIunits.Diameter Dihex=0.02;
+      parameter Modelica.Units.SI.Diameter Dihex=0.02;
       // internal radius
-      parameter Modelica.SIunits.Radius rhex=Dihex/2;
+      parameter Modelica.Units.SI.Radius rhex=Dihex/2;
       // internal perimeter
-      parameter Modelica.SIunits.Length omegahex=Modelica.Constants.pi*Dihex;
+      parameter Modelica.Units.SI.Length omegahex=Modelica.Constants.pi*Dihex;
       // internal cross section
-      parameter Modelica.SIunits.Area Ahex=Modelica.Constants.pi*rhex^2;
-      // friction coefficient
+      parameter Modelica.Units.SI.Area Ahex=Modelica.Constants.pi*rhex^2;
+      // friction coefficient
       parameter Real Cfhex=0.005;
       // nominal (and initial) mass flow rate
-      parameter Modelica.SIunits.MassFlowRate whex=0.31;
+      parameter Modelica.Units.SI.MassFlowRate whex=0.31;
       // initial pressure
-      parameter Modelica.SIunits.Pressure phex=3e5;
+      parameter Modelica.Units.SI.Pressure phex=3e5;
       // initial inlet specific enthalpy
-      parameter Modelica.SIunits.SpecificEnthalpy hinhex=1e5;
+      parameter Modelica.Units.SI.SpecificEnthalpy hinhex=1e5;
       // initial outlet specific enthalpy
-      parameter Modelica.SIunits.SpecificEnthalpy houthex=1e5;
+      parameter Modelica.Units.SI.SpecificEnthalpy houthex=1e5;
       Water.Flow1DFEM hexA(
         N=Nnodes,
         Nt=1,
@@ -6917,33 +6917,33 @@
       extends Modelica.Icons.Example;
       replaceable package Medium = Modelica.Media.Water.WaterIF97OnePhase_ph
         constrainedby Modelica.Media.Interfaces.PartialMedium;
-      // number of Nodes
+      // number of Nodes
       parameter Integer Nnodes=6;
-      // total length
+      // total length
       parameter SI.Length Lhex=10;
-      // internal diameter
+      // internal diameter
       parameter SI.Diameter Dihex=0.02;
-      // internal radius
+      // internal radius
       parameter SI.Radius rhex=Dihex/2;
-      // internal perimeter
+      // internal perimeter
       parameter SI.Length omegahex=Modelica.Constants.pi*Dihex;
-      // internal cross section
+      // internal cross section
       parameter SI.Area Ahex=Modelica.Constants.pi*rhex^2;
-      // friction coefficient
+      // friction coefficient
       parameter SI.PerUnit Cfhex=0.005;
-      // nominal (and initial) mass flow rate
+      // nominal (and initial) mass flow rate
       parameter SI.MassFlowRate whex=0.3;
-      // initial pressure
+      // initial pressure
       parameter SI.Pressure phex=2e5;
-      // initial inlet specific enthalpy
+      // initial inlet specific enthalpy
       parameter SI.SpecificEnthalpy hinhex=1e5;
-      // initial outlet specific enthalpy
+      // initial outlet specific enthalpy
       parameter SI.SpecificEnthalpy houthex=1e5;
 
-      //height of enthalpy step
+//height of enthalpy step
       parameter SI.SpecificEnthalpy deltah=41800;
 
-      //height of power step
+//height of power step
       parameter SI.EnergyFlowRate W=41800*whex;
 
       ThermoPower.Water.SourceMassFlow
@@ -7035,47 +7035,47 @@
       extends Modelica.Icons.Example;
       replaceable package Medium = Modelica.Media.Water.StandardWater
         constrainedby Modelica.Media.Interfaces.PartialMedium;
-      // number of Nodes
+      // number of Nodes
       parameter Integer Nnodes=11;
-      // total length
+      // total length
       parameter SI.Length Lhex=10;
-      // internal diameter
+      // internal diameter
       parameter SI.Diameter Dihex=0.02;
-      // internal radius
+      // internal radius
       parameter SI.Radius rhex=Dihex/2;
-      // internal perimeter
+      // internal perimeter
       parameter SI.Length omegahex=Modelica.Constants.pi*Dihex;
-      // internal cross section
+      // internal cross section
       parameter SI.Area Ahex=Modelica.Constants.pi*rhex^2;
-      // friction coefficient
+      // friction coefficient
       parameter SI.PerUnit Cfhex=0.05;
-      // nominal (and initial) mass flow rate
+      // nominal (and initial) mass flow rate
       parameter SI.MassFlowRate whex=0.3;
-      // initial pressure
+      // initial pressure
       parameter SI.Pressure phex=30e5;
-      // initial temperature
+      // initial temperature
       parameter SI.Temperature Thex=700;
-      // initial specific enthalpy
+      // initial specific enthalpy
       final parameter SI.SpecificEnthalpy hhex=
           Medium.specificEnthalpy_pT(phex, Thex);
-      // initial density
+      // initial density
       final parameter SI.Density rhohex=Medium.density_pT(phex,
           Thex);
-      // Cv of fluid
+      // Cv of fluid
       final parameter SI.SpecificHeatCapacity cp=
           Medium.specificHeatCapacityCp(Medium.setState_pT(phex, Thex));
-      //height of power step
+      //height of power step
       parameter SI.EnergyFlowRate W=100;
-      // prediction of the flow rate going out the pipe from each side
-      // Approximated value of drho/dT, assuming ideal gas
+      // prediction of the flow rate going out the pipe from each side
+      // Approximated value of drho/dT, assuming ideal gas
       final parameter Real drho_dT = rhohex/Thex;
-      // Initial mass
+      // Initial mass
       final parameter SI.Mass M = rhohex*Ahex*Lhex;
-      // Approximated value of temperature derivative (isobaric expansion)
+      // Approximated value of temperature derivative (isobaric expansion)
       final parameter Real dT_dt = W/(cp*M);
-      // Approximated dM/dT = V*drho_dT*dT_dt
+      // Approximated dM/dT = V*drho_dT*dT_dt
       final parameter SI.MassFlowRate dM_dT = Ahex*Lhex*drho_dT*dT_dt;
-      // Approximated value of flow rate at each end
+      // Approximated value of flow rate at each end
       final parameter SI.MassFlowRate wout=0.5*dM_dT;
 
       ThermoPower.Water.SinkPressure
@@ -7160,37 +7160,36 @@
       extends Modelica.Icons.Example;
       replaceable package Medium = Modelica.Media.Water.StandardWater
         constrainedby Modelica.Media.Interfaces.PartialMedium;
-      // number of Nodes
+      // number of Nodes
       parameter Integer Nnodes=11;
-      // total length
+      // total length
       parameter SI.Length Lhex=10;
-      // internal diameter
+      // internal diameter
       parameter SI.Diameter Dihex=0.02;
-      // internal radius
+      // internal radius
       parameter SI.Radius rhex=Dihex/2;
-      // internal perimeter
+      // internal perimeter
       parameter SI.Length omegahex=Modelica.Constants.pi*Dihex;
-      // internal cross section
+      // internal cross section
       parameter SI.Area Ahex=Modelica.Constants.pi*rhex^2;
-      // friction coefficient
+      // friction coefficient
       parameter SI.PerUnit Cfhex=0.05;
-      // nominal (and initial) mass flow rate
+      // nominal (and initial) mass flow rate
       parameter SI.MassFlowRate whex=0.03;
-      // initial pressure
+      // initial pressure
       parameter SI.Pressure phex=30e5;
-      // initial temperature
+      // initial temperature
       parameter SI.Temperature Thex=700;
-      // initial specific enthalpy
+      // initial specific enthalpy
       final parameter SI.SpecificEnthalpy hhex=
           Medium.specificEnthalpy_pT(phex, Thex);
-      // initial density
+      // initial density
       final parameter SI.Density rhohex=Medium.density_pT(phex,
           Thex);
-      // Cv of fluid
+      // Cv of fluid
       final parameter SI.SpecificHeatCapacity cv=
           Medium.specificHeatCapacityCv(Medium.setState_pT(phex, Thex));
-      //height of power step
-
+      //height of power step
       ThermoPower.Water.SinkPressure
                               sink1(p0=phex, h=hhex,
         use_in_p0=true,
@@ -7271,21 +7270,21 @@
       extends Modelica.Icons.Example;
        package Medium = Modelica.Media.Water.WaterIF97_ph;
       constant Real pi = Modelica.Constants.pi;
-      // number of Nodes
+      // number of Nodes
       parameter Integer Nnodes=15;
-      // total length
+      // total length
       parameter SI.Length Lhex=20;
-      // internal diameter
+      // internal diameter
       parameter SI.Diameter Dhex=0.01;
-      // wall thickness
+      // wall thickness
       parameter SI.Thickness thhex=0.002;
-      // internal radius
+      // internal radius
       parameter SI.Radius rhex=Dhex/2;
-      // internal perimeter
+      // internal perimeter
       parameter SI.Length omegahex=pi*Dhex;
-      // internal cross section
+      // internal cross section
       parameter SI.Area Ahex=pi*rhex^2;
-      // friction factor
+      // friction factor
       parameter SI.PerUnit Cfhex=0.005;
       Water.ValveLin             valve(Kv=0.05/60e5) annotation (Placement(
             transformation(extent={{30,-70},{50,-50}}, rotation=0)));
@@ -7411,21 +7410,21 @@
       extends Modelica.Icons.Example;
       package Medium = Modelica.Media.Water.WaterIF97_ph;
       constant Real pi = Modelica.Constants.pi;
-      // number of Nodes
+      // number of Nodes
       parameter Integer Nnodes=10;
-      // total length
+      // total length
       parameter SI.Length Lhex=10;
-      // internal diameter
+      // internal diameter
       parameter SI.Diameter Dhex=0.06;
-      // wall thickness
+      // wall thickness
       parameter SI.Thickness thhex=0;
-      // internal radius
+      // internal radius
       parameter SI.Radius rhex=Dhex/2;
-      // internal perimeter
+      // internal perimeter
       parameter SI.Length omegahex=Dhex;
-      // internal cross section
+      // internal cross section
       parameter SI.Area Ahex=pi*rhex^2;
-      // friction factor
+      // friction factor
       parameter SI.PerUnit Cfhex=0.005;
       SI.Mass Mhex "Mass in the heat exchanger";
       SI.Mass Mbal "Mass resulting from the mass balance";
@@ -7557,21 +7556,21 @@
       extends Modelica.Icons.Example;
       package Medium = Modelica.Media.Water.WaterIF97_ph;
       constant Real pi = Modelica.Constants.pi;
-      // number of Nodes
+      // number of Nodes
       parameter Integer Nnodes=10;
-      // total length
+      // total length
       parameter SI.Length Lhex=10;
-      // internal diameter
+      // internal diameter
       parameter SI.Diameter Dhex=0.06;
-      // wall thickness
+      // wall thickness
       parameter SI.Thickness thhex=0;
-      // internal radius
+      // internal radius
       parameter SI.Radius rhex=Dhex/2;
-      // internal perimeter
+      // internal perimeter
       parameter SI.Length omegahex=Dhex;
-      // internal cross section
+      // internal cross section
       parameter SI.Area Ahex=pi*rhex^2;
-      // friction factor
+      // friction factor
       parameter SI.PerUnit Cfhex=0.005;
       SI.Mass Mhex "Mass in the heat exchanger";
       SI.Mass Mbal "Mass resulting from the mass balance";
@@ -7698,21 +7697,21 @@
       extends Modelica.Icons.Example;
       package Medium = Modelica.Media.Water.WaterIF97_ph;
       constant Real pi = Modelica.Constants.pi;
-      // number of Nodes
+      // number of Nodes
       parameter Integer Nnodes=20;
-      // total length
+      // total length
       parameter SI.Length Lhex=10;
-      // internal diameter
+      // internal diameter
       parameter SI.Diameter Dhex=0.06;
-      // wall thickness
+      // wall thickness
       parameter SI.Thickness thhex=0;
-      // internal radius
+      // internal radius
       parameter SI.Radius rhex=Dhex/2;
-      // internal perimeter
+      // internal perimeter
       parameter SI.Length omegahex=Dhex;
-      // internal cross section
+      // internal cross section
       parameter SI.Area Ahex=pi*rhex^2;
-      // friction factor
+      // friction factor
       parameter SI.PerUnit Cfhex=0.005;
       SI.Mass Mhex "Mass in the heat exchanger";
       SI.Mass Mbal "Mass resulting from the mass balance";
@@ -7837,21 +7836,21 @@
      extends Modelica.Icons.Example;
      package Medium = Modelica.Media.Water.WaterIF97_ph;
       constant Real pi = Modelica.Constants.pi;
-      // number of Nodes
+      // number of Nodes
       parameter Integer Nnodes=10;
-      // total length
+      // total length
       parameter SI.Length Lhex=10;
-      // internal diameter
+      // internal diameter
       parameter SI.Diameter Dhex=0.06;
-      // wall thickness
+      // wall thickness
       parameter SI.Thickness thhex=0;
-      // internal radius
+      // internal radius
       parameter SI.Radius rhex=Dhex/2;
-      // internal perimeter
+      // internal perimeter
       parameter SI.Length omegahex=Dhex;
-      // internal cross section
+      // internal cross section
       parameter SI.Area Ahex=pi*rhex^2;
-      // friction factor
+      // friction factor
       parameter SI.PerUnit Cfhex=0.005;
       SI.Mass Mhex "Mass in the heat exchanger";
       SI.Mass Mbal "Mass resulting from the mass balance";
@@ -8010,7 +8009,7 @@
       Medium.Density rho[N] "Fluid density";
       Units.LiquidDensity rhol "Saturated liquid density";
       Units.GasDensity rhov "Saturated vapour density";
-      // protected
+      // protected
       SI.DerEnthalpyByPressure dhldp
         "Derivative of saturated liquid enthalpy by pressure";
       SI.DerEnthalpyByPressure dhvdp
@@ -8054,99 +8053,67 @@
       end for;
     initial equation
       rhobar_check = rhobar;
-    equation
-      for j in 1:(N - 1) loop
-        if noEvent((h[j] < hl and h[j + 1] < hl) or (h[j] > hv and h[j + 1] >
-            hv) or p >= (pc - pzero) or abs(h[j + 1] - h[j]) < hzero) then
-          // 1-phase or almost uniform properties
-          rhobar[j] = (rho[j] + rho[j + 1])/2;
-          drbdp[j] = (drdp[j] + drdp[j + 1])/2;
-          drbdh1[j] = drdh[j]/2;
-          drbdh2[j] = drdh[j + 1]/2;
-          case[j] = 0;
-        elseif noEvent(h[j] >= hl and h[j] <= hv and h[j + 1] >= hl and h[j + 1]
-             <= hv) then
-          // 2-phase
-          rhobar[j] = AA*log(rho[j]/rho[j + 1])/(h[j + 1] - h[j]);
-          drbdp[j] = (AA1*log(rho[j]/rho[j + 1]) + AA*(1/rho[j]*drdp[j] - 1/rho[
-            j + 1]*drdp[j + 1]))/(h[j + 1] - h[j]);
-          drbdh1[j] = (rhobar[j] - rho[j])/(h[j + 1] - h[j]);
-          drbdh2[j] = (rho[j + 1] - rhobar[j])/(h[j + 1] - h[j]);
-          case[j] = 1;
-        elseif noEvent(h[j] < hl and h[j + 1] >= hl and h[j + 1] <= hv) then
-          // liquid/2-phase
-          rhobar[j] = ((rho[j] + rhol)*(hl - h[j])/2 + AA*log(rhol/rho[j + 1]))
-            /(h[j + 1] - h[j]);
-          drbdp[j] = ((drdp[j] + drldp)*(hl - h[j])/2 + (rho[j] + rhol)/2*dhldp
-             + AA1*log(rhol/rho[j + 1]) + AA*(1/rhol*drldp - 1/rho[j + 1]*drdp[
-            j + 1]))/(h[j + 1] - h[j]);
-          drbdh1[j] = (rhobar[j] - (rho[j] + rhol)/2 + drdh[j]*(hl - h[j])/2)/(
-            h[j + 1] - h[j]);
-          drbdh2[j] = (rho[j + 1] - rhobar[j])/(h[j + 1] - h[j]);
-          case[j] = 2;
-        elseif noEvent(h[j] >= hl and h[j] <= hv and h[j + 1] > hv) then
-          // 2-phase/vapour
-          rhobar[j] = (AA*log(rho[j]/rhov) + (rhov + rho[j + 1])*(h[j + 1] - hv)
-            /2)/(h[j + 1] - h[j]);
-          drbdp[j] = (AA1*log(rho[j]/rhov) + AA*(1/rho[j]*drdp[j] - 1/rhov*
-            drvdp) + (drvdp + drdp[j + 1])*(h[j + 1] - hv)/2 - (rhov + rho[j +
-            1])/2*dhvdp)/(h[j + 1] - h[j]);
-          drbdh1[j] = (rhobar[j] - rho[j])/(h[j + 1] - h[j]);
-          drbdh2[j] = ((rhov + rho[j + 1])/2 - rhobar[j] + drdh[j + 1]*(h[j + 1]
-             - hv)/2)/(h[j + 1] - h[j]);
-          case[j] = 3;
-        elseif noEvent(h[j] < hl and h[j + 1] > hv) then
-          // liquid/2-phase/vapour
-          rhobar[j] = ((rho[j] + rhol)*(hl - h[j])/2 + AA*log(rhol/rhov) + (
-            rhov + rho[j + 1])*(h[j + 1] - hv)/2)/(h[j + 1] - h[j]);
-          drbdp[j] = ((drdp[j] + drldp)*(hl - h[j])/2 + (rho[j] + rhol)/2*dhldp
-             + AA1*log(rhol/rhov) + AA*(1/rhol*drldp - 1/rhov*drvdp) + (drvdp
-             + drdp[j + 1])*(h[j + 1] - hv)/2 - (rhov + rho[j + 1])/2*dhvdp)/(h[
-            j + 1] - h[j]);
-          drbdh1[j] = (rhobar[j] - (rho[j] + rhol)/2 + drdh[j]*(hl - h[j])/2)/(
-            h[j + 1] - h[j]);
-          drbdh2[j] = ((rhov + rho[j + 1])/2 - rhobar[j] + drdh[j + 1]*(h[j + 1]
-             - hv)/2)/(h[j + 1] - h[j]);
-          case[j] = 4;
-        elseif noEvent(h[j] >= hl and h[j] <= hv and h[j + 1] < hl) then
-          // 2-phase/liquid
-          rhobar[j] = (AA*log(rho[j]/rhol) + (rhol + rho[j + 1])*(h[j + 1] - hl)
-            /2)/(h[j + 1] - h[j]);
-          drbdp[j] = (AA1*log(rho[j]/rhol) + AA*(1/rho[j]*drdp[j] - 1/rhol*
-            drldp) + (drldp + drdp[j + 1])*(h[j + 1] - hl)/2 - (rhol + rho[j +
-            1])/2*dhldp)/(h[j + 1] - h[j]);
-          drbdh1[j] = (rhobar[j] - rho[j])/(h[j + 1] - h[j]);
-          drbdh2[j] = ((rhol + rho[j + 1])/2 - rhobar[j] + drdh[j + 1]*(h[j + 1]
-             - hl)/2)/(h[j + 1] - h[j]);
-          case[j] = 5;
-        elseif noEvent(h[j] > hv and h[j + 1] < hl) then
-          // vapour/2-phase/liquid
-          rhobar[j] = ((rho[j] + rhov)*(hv - h[j])/2 + AA*log(rhov/rhol) + (
-            rhol + rho[j + 1])*(h[j + 1] - hl)/2)/(h[j + 1] - h[j]);
-          drbdp[j] = ((drdp[j] + drvdp)*(hv - h[j])/2 + (rho[j] + rhov)/2*dhvdp
-             + AA1*log(rhov/rhol) + AA*(1/rhov*drvdp - 1/rhol*drldp) + (drldp
-             + drdp[j + 1])*(h[j + 1] - hl)/2 - (rhol + rho[j + 1])/2*dhldp)/(h[
-            j + 1] - h[j]);
-          drbdh1[j] = (rhobar[j] - (rho[j] + rhov)/2 + drdh[j]*(hv - h[j])/2)/(
-            h[j + 1] - h[j]);
-          drbdh2[j] = ((rhol + rho[j + 1])/2 - rhobar[j] + drdh[j + 1]*(h[j + 1]
-             - hl)/2)/(h[j + 1] - h[j]);
-          case[j] = 6;
-        else
-          // vapour/2-phase
-          rhobar[j] = ((rho[j] + rhov)*(hv - h[j])/2 + AA*log(rhov/rho[j + 1]))
-            /(h[j + 1] - h[j]);
-          drbdp[j] = ((drdp[j] + drvdp)*(hv - h[j])/2 + (rho[j] + rhov)/2*dhvdp
-             + AA1*log(rhov/rho[j + 1]) + AA*(1/rhov*drvdp - 1/rho[j + 1]*drdp[
-            j + 1]))/(h[j + 1] - h[j]);
-          drbdh1[j] = (rhobar[j] - (rho[j] + rhov)/2 + drdh[j]*(hv - h[j])/2)/(
-            h[j + 1] - h[j]);
-          drbdh2[j] = (rho[j + 1] - rhobar[j])/(h[j + 1] - h[j]);
-          case[j] = 7;
-        end if;
-      end for;
-
-      // Saturated fluid property calculations
+    equation
+  for j in 1:N - 1 loop
+        if noEvent(h[j] < hl and h[j + 1] < hl or h[j] > hv and h[j + 1] > hv or p >= pc - pzero or abs(h[j + 1] - h[j]) < hzero) then
+// 1-phase or almost uniform properties
+          rhobar[j] = (rho[j] + rho[j + 1]) / 2;
+          drbdp[j] = (drdp[j] + drdp[j + 1]) / 2;
+          drbdh1[j] = drdh[j] / 2;
+          drbdh2[j] = drdh[j + 1] / 2;
+          case[j] = 0;
+        elseif noEvent(h[j] >= hl and h[j] <= hv and h[j + 1] >= hl and h[j + 1] <= hv) then
+// 2-phase
+          rhobar[j] = AA * log(rho[j] / rho[j + 1]) / (h[j + 1] - h[j]);
+          drbdp[j] = (AA1 * log(rho[j] / rho[j + 1]) + AA * (1 / rho[j] * drdp[j] - 1 / rho[j + 1] * drdp[j + 1])) / (h[j + 1] - h[j]);
+          drbdh1[j] = (rhobar[j] - rho[j]) / (h[j + 1] - h[j]);
+          drbdh2[j] = (rho[j + 1] - rhobar[j]) / (h[j + 1] - h[j]);
+          case[j] = 1;
+        elseif noEvent(h[j] < hl and h[j + 1] >= hl and h[j + 1] <= hv) then
+// liquid/2-phase
+          rhobar[j] = ((rho[j] + rhol) * (hl - h[j]) / 2 + AA * log(rhol / rho[j + 1])) / (h[j + 1] - h[j]);
+          drbdp[j] = ((drdp[j] + drldp) * (hl - h[j]) / 2 + (rho[j] + rhol) / 2 * dhldp + AA1 * log(rhol / rho[j + 1]) + AA * (1 / rhol * drldp - 1 / rho[j + 1] * drdp[j + 1])) / (h[j + 1] - h[j]);
+          drbdh1[j] = (rhobar[j] - (rho[j] + rhol) / 2 + drdh[j] * (hl - h[j]) / 2) / (h[j + 1] - h[j]);
+          drbdh2[j] = (rho[j + 1] - rhobar[j]) / (h[j + 1] - h[j]);
+          case[j] = 2;
+        elseif noEvent(h[j] >= hl and h[j] <= hv and h[j + 1] > hv) then
+// 2-phase/vapour
+          rhobar[j] = (AA * log(rho[j] / rhov) + (rhov + rho[j + 1]) * (h[j + 1] - hv) / 2) / (h[j + 1] - h[j]);
+          drbdp[j] = (AA1 * log(rho[j] / rhov) + AA * (1 / rho[j] * drdp[j] - 1 / rhov * drvdp) + (drvdp + drdp[j + 1]) * (h[j + 1] - hv) / 2 - (rhov + rho[j + 1]) / 2 * dhvdp) / (h[j + 1] - h[j]);
+          drbdh1[j] = (rhobar[j] - rho[j]) / (h[j + 1] - h[j]);
+          drbdh2[j] = ((rhov + rho[j + 1]) / 2 - rhobar[j] + drdh[j + 1] * (h[j + 1] - hv) / 2) / (h[j + 1] - h[j]);
+          case[j] = 3;
+        elseif noEvent(h[j] < hl and h[j + 1] > hv) then
+// liquid/2-phase/vapour
+          rhobar[j] = ((rho[j] + rhol) * (hl - h[j]) / 2 + AA * log(rhol / rhov) + (rhov + rho[j + 1]) * (h[j + 1] - hv) / 2) / (h[j + 1] - h[j]);
+          drbdp[j] = ((drdp[j] + drldp) * (hl - h[j]) / 2 + (rho[j] + rhol) / 2 * dhldp + AA1 * log(rhol / rhov) + AA * (1 / rhol * drldp - 1 / rhov * drvdp) + (drvdp + drdp[j + 1]) * (h[j + 1] - hv) / 2 - (rhov + rho[j + 1]) / 2 * dhvdp) / (h[j + 1] - h[j]);
+          drbdh1[j] = (rhobar[j] - (rho[j] + rhol) / 2 + drdh[j] * (hl - h[j]) / 2) / (h[j + 1] - h[j]);
+          drbdh2[j] = ((rhov + rho[j + 1]) / 2 - rhobar[j] + drdh[j + 1] * (h[j + 1] - hv) / 2) / (h[j + 1] - h[j]);
+          case[j] = 4;
+        elseif noEvent(h[j] >= hl and h[j] <= hv and h[j + 1] < hl) then
+// 2-phase/liquid
+          rhobar[j] = (AA * log(rho[j] / rhol) + (rhol + rho[j + 1]) * (h[j + 1] - hl) / 2) / (h[j + 1] - h[j]);
+          drbdp[j] = (AA1 * log(rho[j] / rhol) + AA * (1 / rho[j] * drdp[j] - 1 / rhol * drldp) + (drldp + drdp[j + 1]) * (h[j + 1] - hl) / 2 - (rhol + rho[j + 1]) / 2 * dhldp) / (h[j + 1] - h[j]);
+          drbdh1[j] = (rhobar[j] - rho[j]) / (h[j + 1] - h[j]);
+          drbdh2[j] = ((rhol + rho[j + 1]) / 2 - rhobar[j] + drdh[j + 1] * (h[j + 1] - hl) / 2) / (h[j + 1] - h[j]);
+          case[j] = 5;
+        elseif noEvent(h[j] > hv and h[j + 1] < hl) then
+// vapour/2-phase/liquid
+          rhobar[j] = ((rho[j] + rhov) * (hv - h[j]) / 2 + AA * log(rhov / rhol) + (rhol + rho[j + 1]) * (h[j + 1] - hl) / 2) / (h[j + 1] - h[j]);
+          drbdp[j] = ((drdp[j] + drvdp) * (hv - h[j]) / 2 + (rho[j] + rhov) / 2 * dhvdp + AA1 * log(rhov / rhol) + AA * (1 / rhov * drvdp - 1 / rhol * drldp) + (drldp + drdp[j + 1]) * (h[j + 1] - hl) / 2 - (rhol + rho[j + 1]) / 2 * dhldp) / (h[j + 1] - h[j]);
+          drbdh1[j] = (rhobar[j] - (rho[j] + rhov) / 2 + drdh[j] * (hv - h[j]) / 2) / (h[j + 1] - h[j]);
+          drbdh2[j] = ((rhol + rho[j + 1]) / 2 - rhobar[j] + drdh[j + 1] * (h[j + 1] - hl) / 2) / (h[j + 1] - h[j]);
+          case[j] = 6;
+        else
+// vapour/2-phase
+          rhobar[j] = ((rho[j] + rhov) * (hv - h[j]) / 2 + AA * log(rhov / rho[j + 1])) / (h[j + 1] - h[j]);
+          drbdp[j] = ((drdp[j] + drvdp) * (hv - h[j]) / 2 + (rho[j] + rhov) / 2 * dhvdp + AA1 * log(rhov / rho[j + 1]) + AA * (1 / rhov * drvdp - 1 / rho[j + 1] * drdp[j + 1])) / (h[j + 1] - h[j]);
+          drbdh1[j] = (rhobar[j] - (rho[j] + rhov) / 2 + drdh[j] * (hv - h[j]) / 2) / (h[j + 1] - h[j]);
+          drbdh2[j] = (rho[j + 1] - rhobar[j]) / (h[j + 1] - h[j]);
+          case[j] = 7;
+        end if;
+      end for;
+// Saturated fluid property calculations
       sat = Medium.setSat_p(p);
       Ts = sat.Tsat;
       bubble = Medium.setBubbleState(sat, 1);
@@ -8161,18 +8128,16 @@
       dhvdp = Medium.dDewEnthalpy_dPressure(sat);
       AA = (hv - hl)/(1/rhov - 1/rhol);
       AA1 = ((dhvdp - dhldp)*(rhol - rhov)*rhol*rhov - (hv - hl)*(rhov^2*drldp
-         - rhol^2*drvdp))/(rhol - rhov)^2;
-
-      // Fluid property calculations
-      for j in 1:N loop
-        fluid[j].p = p;
-        fluid[j].h = h[j];
-        T[j] = fluid[j].T;
-        rho[j] = fluid[j].d;
-        drdp[j] = Medium.density_derp_h(fluid[j].state);
-        drdh[j] = Medium.density_derh_p(fluid[j].state);
-        x[j] = noEvent(if h[j] <= hl then 0 else if h[j] >= hv then 1 else (h[j]
-           - hl)/(hv - hl));
+         - rhol^2*drvdp))/(rhol - rhov)^2;
+// Fluid property calculations
+      for j in 1:N loop
+        fluid[j].p = p;
+        fluid[j].h = h[j];
+        T[j] = fluid[j].T;
+        rho[j] = fluid[j].d;
+        drdp[j] = Medium.density_derp_h(fluid[j].state);
+        drdh[j] = Medium.density_derh_p(fluid[j].state);
+        x[j] = noEvent(if h[j] <= hl then 0 else if h[j] >= hv then 1 else (h[j] - hl) / (hv - hl));
       end for;
       annotation (
         experiment(
@@ -8189,21 +8154,21 @@
       extends Modelica.Icons.Example;
       package Medium = Modelica.Media.Water.WaterIF97_ph;
       constant Real pi = Modelica.Constants.pi;
-      // number of Nodes
+      // number of Nodes
       parameter Integer Nnodes=8;
-      // total length
+      // total length
       parameter SI.Length Lhex=20;
-      // internal diameter
+      // internal diameter
       parameter SI.Diameter Dhex=0.01;
-      // wall thickness
+      // wall thickness
       parameter SI.Thickness thhex=0.002;
-      // internal radius
+      // internal radius
       parameter SI.Radius rhex=Dhex/2;
-      // internal perimeter
+      // internal perimeter
       parameter SI.Length omegahex=pi*Dhex;
-      // internal cross section
+      // internal cross section
       parameter SI.Area Ahex=pi*rhex^2;
-      // friction factor
+      // friction factor
       parameter SI.PerUnit Cfhex=0.005;
       Water.Flow1D2phDB hex(
         N=Nnodes,
@@ -8353,21 +8318,21 @@
       extends Modelica.Icons.Example;
       package Medium = Modelica.Media.Water.WaterIF97_ph (smoothModel=true);
       constant Real pi = Modelica.Constants.pi;
-      // number of Nodes
+      // number of Nodes
       parameter Integer Nnodes=10;
-      // total length
+      // total length
       parameter SI.Length Lhex=10;
-      // internal diameter
+      // internal diameter
       parameter SI.Diameter Dhex=0.02;
-      // wall thickness
+      // wall thickness
       parameter SI.Thickness thhex=0;
-      // internal radius
+      // internal radius
       parameter SI.Radius rhex=Dhex/2;
-      // internal perimeter
+      // internal perimeter
       parameter SI.Length omegahex=Dhex;
-      // internal cross section
+      // internal cross section
       parameter SI.Area Ahex=pi*rhex^2;
-      // friction factor
+      // friction factor
       parameter Real Cfhex=0.005;
       Water.Flow1D2phDB hex(
         N=Nnodes,
@@ -8502,21 +8467,21 @@
       extends Modelica.Icons.Example;
       package Medium = Modelica.Media.Water.WaterIF97_ph;
       import Modelica.Constants.*;
-      // number of Nodes
+      // number of Nodes
       parameter Integer Nnodes=8;
-      // total length
+      // total length
       parameter SI.Length Lhex=20;
-      // internal diameter
+      // internal diameter
       parameter SI.Diameter Dhex=0.01;
-      // wall thickness
+      // wall thickness
       parameter SI.Thickness thhex=0.002;
-      // internal radius
+      // internal radius
       parameter SI.Radius rhex=Dhex/2;
-      // internal perimeter
+      // internal perimeter
       parameter SI.Length omegahex=pi*Dhex;
-      // internal cross section
+      // internal cross section
       parameter SI.Area Ahex=pi*rhex^2;
-      // friction factor
+      // friction factor
       parameter SI.PerUnit Cfhex=0.005;
       Water.Flow1D2phChen hex(
         N=Nnodes,
@@ -8664,21 +8629,21 @@
       extends Modelica.Icons.Example;
       package Medium = Modelica.Media.Water.WaterIF97_ph (smoothModel=true);
       constant Real pi = Modelica.Constants.pi;
-      // number of Nodes
+      // number of Nodes
       parameter Integer Nnodes=10;
-      // total length
+      // total length
       parameter SI.Length Lhex=10;
-      // internal diameter
+      // internal diameter
       parameter SI.Diameter Dhex=0.02;
-      // wall thickness
+      // wall thickness
       parameter SI.Thickness thhex=0;
-      // internal radius
+      // internal radius
       parameter SI.Radius rhex=Dhex/2;
-      // internal perimeter
+      // internal perimeter
       parameter SI.Length omegahex=Dhex;
-      // internal cross section
+      // internal cross section
       parameter SI.Area Ahex=pi*rhex^2;
-      // friction factor
+      // friction factor
       parameter Real Cfhex=0.005;
       Water.Flow1D2phChen hex(
         N=Nnodes,
@@ -8813,21 +8778,21 @@
     model TestFlow1Dfem2ph "Test case for Flow1D2ph"
       extends Modelica.Icons.Example;
       package Medium = Modelica.Media.Water.WaterIF97_ph;
-      // number of Nodes
+      // number of Nodes
       parameter Integer Nnodes=11;
-      // total length
+      // total length
       parameter SI.Length Lhex=10;
-      // internal diameter
+      // internal diameter
       parameter SI.Diameter Dhex=0.03;
-      // wall thickness
+      // wall thickness
       parameter SI.Thickness thhex=1e-3;
-      // internal radius
+      // internal radius
       parameter SI.Radius rhex=Dhex/2;
-      // internal perimeter
+      // internal perimeter
       parameter SI.Length omegahex=Modelica.Constants.pi*Dhex;
-      // internal cross section
+      // internal cross section
       parameter SI.Area Ahex=Modelica.Constants.pi*rhex^2;
-      // friction factor
+      // friction factor
       parameter SI.PerUnit Cfhex=0.005;
 
       parameter SI.SpecificEnthalpy hin=6e5;
@@ -8981,7 +8946,7 @@
         Mvol[j] = A*l*rhobar[j];
         Evol[j] = Mvol[j]*((h[j] + h[j + 1])/2 - p/rhobar[j]);
       end for;
-      // M is computed in base class
+// M is computed in base class
       Mtot = M;
       Etot = sum(Evol);
       balM = infl.m_flow + outfl.m_flow;
@@ -9170,7 +9135,7 @@
       parameter Medium.SpecificEnthalpy hstartin = 1e5;
       Medium.SpecificEnthalpy hstartout = (1e5+0.001) + 3.4e6*time;
       Medium.SpecificEnthalpy h[Nnodes] = linspace(hstartin,hstartout,Nnodes);
-      parameter SI.Area Across = 2.827e-3; // r = 0.03 [m] , A = pi*r^2
+      parameter SI.Area Across = 2.827e-3;       // r = 0.03 [m] , A = pi*r^2
       parameter Medium.AbsolutePressure p = 3e6;
       parameter Medium.MassFlowRate wnom = 2;
       parameter Medium.MassFlowRate w[Nnodes] = wnom*ones(Nnodes);
@@ -9284,20 +9249,20 @@
         constrainedby Modelica.Media.Interfaces.PartialPureSubstance;
       parameter Integer Nnodes=4 "Number of nodes";
       parameter Integer Nt = 5 "Number of tubes";
-      parameter Modelica.SIunits.Length Lhex=2 "Total length";
-      parameter Modelica.SIunits.Diameter Dihex=0.02 "Internal diameter";
-      final parameter Modelica.SIunits.Radius rhex=Dihex/2 "Internal radius";
-      final parameter Modelica.SIunits.Length omegahex=Modelica.Constants.pi*Dihex
+      parameter Modelica.Units.SI.Length Lhex=2 "Total length";
+      parameter Modelica.Units.SI.Diameter Dihex=0.02 "Internal diameter";
+      final parameter Modelica.Units.SI.Radius rhex=Dihex/2 "Internal radius";
+      final parameter Modelica.Units.SI.Length omegahex=Modelica.Constants.pi*Dihex
         "Internal perimeter";
-      final parameter Modelica.SIunits.Area Ahex=Modelica.Constants.pi*rhex^2
+      final parameter Modelica.Units.SI.Area Ahex=Modelica.Constants.pi*rhex^2
         "Internal cross section";
       parameter Real Cfhex=0.005 "Friction coefficient";
-      parameter Modelica.SIunits.MassFlowRate whex=0.31
+      parameter Modelica.Units.SI.MassFlowRate whex=0.31
         "Nominal mass flow rate";
-      parameter Modelica.SIunits.Pressure phex=3e5 "Initial pressure";
-      parameter Modelica.SIunits.SpecificEnthalpy hs=Medium.specificEnthalpy_pT(phex,293.15)
+      parameter Modelica.Units.SI.Pressure phex=3e5 "Initial pressure";
+      parameter Modelica.Units.SI.SpecificEnthalpy hs=Medium.specificEnthalpy_pT(phex,293.15)
         "Initial inlet specific enthalpy";
-      parameter Modelica.SIunits.CoefficientOfHeatTransfer gamma = 5000
+      parameter Modelica.Units.SI.CoefficientOfHeatTransfer gamma = 5000
         "Fixed heat transfer coefficient";
       Real cp = Medium.specificHeatCapacityCp(hex.fluidState[1]);
       Real NTU = (Nt*Lhex*Dihex*3.1415*gamma)/(whex*Medium.specificHeatCapacityCp(hex.fluidState[1]))
@@ -9418,26 +9383,26 @@
 
       model TestFlow1Db "Test case for Flow1D"
         package Medium = Modelica.Media.Water.WaterIF97OnePhase_ph;
-        // number of Nodes
+        // number of Nodes
         parameter Integer Nnodes=10;
         // total length
-        parameter Modelica.SIunits.Length Lhex=200;
+        parameter Modelica.Units.SI.Length Lhex=200;
         // internal diameter
-        parameter Modelica.SIunits.Diameter Dihex=0.02;
+        parameter Modelica.Units.SI.Diameter Dihex=0.02;
         // internal radius
-        parameter Modelica.SIunits.Radius rhex=Dihex/2;
+        parameter Modelica.Units.SI.Radius rhex=Dihex/2;
         // internal perimeter
-        parameter Modelica.SIunits.Length omegahex=Modelica.Constants.pi*Dihex;
+        parameter Modelica.Units.SI.Length omegahex=Modelica.Constants.pi*Dihex;
         // internal cross section
-        parameter Modelica.SIunits.Area Ahex=Modelica.Constants.pi*rhex^2;
-        // friction coefficient
+        parameter Modelica.Units.SI.Area Ahex=Modelica.Constants.pi*rhex^2;
+        // friction coefficient
         parameter Real Cfhex=0.005;
         // nominal (and initial) mass flow rate
-        parameter Modelica.SIunits.MassFlowRate whex=0.31;
+        parameter Modelica.Units.SI.MassFlowRate whex=0.31;
         // initial pressure
-        parameter Modelica.SIunits.Pressure phex=3e5;
+        parameter Modelica.Units.SI.Pressure phex=3e5;
         // initial inlet specific enthalpy
-        parameter Modelica.SIunits.SpecificEnthalpy hs=1e5;
+        parameter Modelica.Units.SI.SpecificEnthalpy hs=1e5;
         Water.Flow1D hex(
           N=Nnodes,
           L=Lhex,
@@ -9543,27 +9508,27 @@
 
       model TestFlow1Dd "Test case for Flow1D"
         package Medium = Modelica.Media.Water.WaterIF97OnePhase_ph;
-        // number of Nodes
+        // number of Nodes
         parameter Integer Nnodes=20;
         // total length
-        parameter Modelica.SIunits.Length Lhex=10;
+        parameter Modelica.Units.SI.Length Lhex=10;
         // internal diameter
-        parameter Modelica.SIunits.Diameter Dihex=0.02;
+        parameter Modelica.Units.SI.Diameter Dihex=0.02;
         // internal radius
-        parameter Modelica.SIunits.Radius rhex=Dihex/2;
+        parameter Modelica.Units.SI.Radius rhex=Dihex/2;
         // internal perimeter
-        parameter Modelica.SIunits.Length omegahex=Modelica.Constants.pi*Dihex;
+        parameter Modelica.Units.SI.Length omegahex=Modelica.Constants.pi*Dihex;
         // internal cross section
-        parameter Modelica.SIunits.Area Ahex=Modelica.Constants.pi*rhex^2;
-        // friction coefficient
+        parameter Modelica.Units.SI.Area Ahex=Modelica.Constants.pi*rhex^2;
+        // friction coefficient
         parameter Real Cfhex=0.005;
         // nominal (and initial) mass flow rate
-        parameter Modelica.SIunits.MassFlowRate whex=1e-2;
+        parameter Modelica.Units.SI.MassFlowRate whex=1e-2;
         // initial pressure
-        parameter Modelica.SIunits.Pressure phex=0.2e5;
+        parameter Modelica.Units.SI.Pressure phex=0.2e5;
         // initial specific enthalpy
-        parameter Modelica.SIunits.SpecificEnthalpy hs=3e6;
-        // Time constant
+        parameter Modelica.Units.SI.SpecificEnthalpy hs=3e6;
+        // Time constant
         SI.Time tau;
 
         Water.Flow1D hex(
@@ -9616,7 +9581,7 @@
         inner System system
           annotation (Placement(transformation(extent={{80,80},{100,100}})));
       equation
-        // RC constant of equivalent circuit
+// RC constant of equivalent circuit
         tau = (1/ValveLin1.Kv)*(Ahex*Lhex/1200^2);
         connect(ValveLin1.inlet, hex.outfl) annotation (Line(
             points={{34,0},{0,0}},
@@ -9670,28 +9635,28 @@
 
       model TestFlow1De "Test case for Flow1D"
         package Medium = Modelica.Media.Water.WaterIF97OnePhase_ph;
-        // number of Nodes
+        // number of Nodes
         parameter Integer Nnodes=20;
         // total length
-        parameter Modelica.SIunits.Length Lhex=200;
+        parameter Modelica.Units.SI.Length Lhex=200;
         // internal diameter
-        parameter Modelica.SIunits.Diameter Dihex=0.02;
+        parameter Modelica.Units.SI.Diameter Dihex=0.02;
         // internal radius
-        parameter Modelica.SIunits.Radius rhex=Dihex/2;
+        parameter Modelica.Units.SI.Radius rhex=Dihex/2;
         // internal perimeter
-        parameter Modelica.SIunits.Length omegahex=Modelica.Constants.pi*Dihex;
+        parameter Modelica.Units.SI.Length omegahex=Modelica.Constants.pi*Dihex;
         // internal cross section
-        parameter Modelica.SIunits.Area Ahex=Modelica.Constants.pi*rhex^2;
-        // friction coefficient
+        parameter Modelica.Units.SI.Area Ahex=Modelica.Constants.pi*rhex^2;
+        // friction coefficient
         parameter Real Cfhex=0.005;
         // nominal (and initial) mass flow rate
-        parameter Modelica.SIunits.MassFlowRate whex=0.31;
+        parameter Modelica.Units.SI.MassFlowRate whex=0.31;
         // initial pressure
-        parameter Modelica.SIunits.Pressure phex=3e5;
+        parameter Modelica.Units.SI.Pressure phex=3e5;
         // initial inlet specific enthalpy
-        parameter Modelica.SIunits.SpecificEnthalpy hinhex=1e5;
+        parameter Modelica.Units.SI.SpecificEnthalpy hinhex=1e5;
         // initial outlet specific enthalpy
-        parameter Modelica.SIunits.SpecificEnthalpy houthex=1e5;
+        parameter Modelica.Units.SI.SpecificEnthalpy houthex=1e5;
         Water.Flow1D hexA(
           N=Nnodes,
           Nt=1,
@@ -9862,28 +9827,28 @@
 
       model TestFlow1Df "Test case for Flow1D"
         package Medium = Modelica.Media.Water.WaterIF97OnePhase_ph;
-        // number of Nodes
+        // number of Nodes
         parameter Integer Nnodes=20;
         // total length
-        parameter Modelica.SIunits.Length Lhex=200;
+        parameter Modelica.Units.SI.Length Lhex=200;
         // internal diameter
-        parameter Modelica.SIunits.Diameter Dihex=0.02;
+        parameter Modelica.Units.SI.Diameter Dihex=0.02;
         // internal radius
-        parameter Modelica.SIunits.Radius rhex=Dihex/2;
+        parameter Modelica.Units.SI.Radius rhex=Dihex/2;
         // internal perimeter
-        parameter Modelica.SIunits.Length omegahex=Modelica.Constants.pi*Dihex;
+        parameter Modelica.Units.SI.Length omegahex=Modelica.Constants.pi*Dihex;
         // internal cross section
-        parameter Modelica.SIunits.Area Ahex=Modelica.Constants.pi*rhex^2;
-        // friction coefficient
+        parameter Modelica.Units.SI.Area Ahex=Modelica.Constants.pi*rhex^2;
+        // friction coefficient
         parameter Real Cfhex=0.005;
         // nominal (and initial) mass flow rate
-        parameter Modelica.SIunits.MassFlowRate whex=0.31;
+        parameter Modelica.Units.SI.MassFlowRate whex=0.31;
         // initial pressure
-        parameter Modelica.SIunits.Pressure phex=3e5;
+        parameter Modelica.Units.SI.Pressure phex=3e5;
         // initial inlet specific enthalpy
-        parameter Modelica.SIunits.SpecificEnthalpy hinhex=1e5;
+        parameter Modelica.Units.SI.SpecificEnthalpy hinhex=1e5;
         // initial outlet specific enthalpy
-        parameter Modelica.SIunits.SpecificEnthalpy houthex=1e5;
+        parameter Modelica.Units.SI.SpecificEnthalpy houthex=1e5;
         Water.Flow1D hexA(
           N=Nnodes,
           Nt=1,
@@ -10153,26 +10118,26 @@
 
       model TestFlow1DDB "Test case for Flow1D"
         package Medium = Modelica.Media.Water.WaterIF97OnePhase_ph;
-        // number of Nodes
+        // number of Nodes
         parameter Integer Nnodes=20;
         // total length
-        parameter Modelica.SIunits.Length Lhex=200;
+        parameter Modelica.Units.SI.Length Lhex=200;
         // internal diameter
-        parameter Modelica.SIunits.Diameter Dihex=0.02;
+        parameter Modelica.Units.SI.Diameter Dihex=0.02;
         // internal radius
-        parameter Modelica.SIunits.Radius rhex=Dihex/2;
+        parameter Modelica.Units.SI.Radius rhex=Dihex/2;
         // internal perimeter
-        parameter Modelica.SIunits.Length omegahex=Modelica.Constants.pi*Dihex;
+        parameter Modelica.Units.SI.Length omegahex=Modelica.Constants.pi*Dihex;
         // internal cross section
-        parameter Modelica.SIunits.Area Ahex=Modelica.Constants.pi*rhex^2;
-        // friction coefficient
+        parameter Modelica.Units.SI.Area Ahex=Modelica.Constants.pi*rhex^2;
+        // friction coefficient
         parameter Real Cfhex=0.005;
         // nominal (and initial) mass flow rate
-        parameter Modelica.SIunits.MassFlowRate whex=0.31;
+        parameter Modelica.Units.SI.MassFlowRate whex=0.31;
         // initial pressure
-        parameter Modelica.SIunits.Pressure phex=3e5;
+        parameter Modelica.Units.SI.Pressure phex=3e5;
         // initial inlet specific enthalpy
-        parameter Modelica.SIunits.SpecificEnthalpy hs=1e5;
+        parameter Modelica.Units.SI.SpecificEnthalpy hs=1e5;
         Water.Flow1DDB hex(
           N=Nnodes,
           L=Lhex,
@@ -11352,7 +11317,7 @@
       der(powerOffset) = 5*Pnom/(Ts*droop)*(frequency-f0)/f0;
     initial equation
       if initOpt == ThermoPower.Choices.Init.Options.noInit then
-        // do nothing
+// do nothing
       elseif initOpt == ThermoPower.Choices.Init.Options.steadyState then
         der(powerOffset) = 0;
       elseif initOpt == ThermoPower.Choices.Init.Options.fixedState then
@@ -11381,7 +11346,6 @@
 </html>"));
     end SecondaryController;
   end ElectricalComponents;
-
   annotation (Documentation(info="<HTML>
 This package contains test cases for the ThermoPower library.
 </HTML>"));
diff -ur "/home/hudson/saved_omc/libraries/.openmodelica/libraries/ThermoPower 3.1.0-master/Thermal.mo" "converted-libraries/.openmodelica/libraries/ThermoPower 3.1.0-master/Thermal.mo"
--- "/home/hudson/saved_omc/libraries/.openmodelica/libraries/ThermoPower 3.1.0-master/Thermal.mo"	2022-03-10 09:57:37.956144120 +0000
+++ "converted-libraries/.openmodelica/libraries/ThermoPower 3.1.0-master/Thermal.mo"	2022-03-10 09:58:42.676152319 +0000
@@ -64,13 +64,12 @@
     for i in 1:N loop
       DHT_port.T[i] = HT_port.T "Uniform temperature distribution on DHT side";
     end for;
-    if N == 1 then
-      // Uniform flow distribution
-      DHT_port.phi[1]*exchangeSurface + HT_port.Q_flow = 0 "Energy balance";
-    else
-      // Piecewise linear flow distribution
-      sum(DHT_port.phi[1:N - 1] + DHT_port.phi[2:N])/2*exchangeSurface/(N - 1)
-         + HT_port.Q_flow = 0 "Energy balance";
+    if N == 1 then
+// Uniform flow distribution
+      DHT_port.phi[1] * exchangeSurface + HT_port.Q_flow = 0 "Energy balance";
+    else
+// Piecewise linear flow distribution
+      sum(DHT_port.phi[1:N - 1] + DHT_port.phi[2:N]) / 2 * exchangeSurface / (N - 1) + HT_port.Q_flow = 0 "Energy balance";
     end if;
     annotation (Icon(graphics={
           Polygon(
@@ -414,26 +413,25 @@
   equation
     assert(rext > rint, "External radius must be greater than internal radius");
     (L/Nw*Nt)*rhomcm*Am*der(Tvol) = int.Q + ext.Q "Energy balance";
-    if WallRes then
-      // Thermal resistance of the tube walls accounted for
-      int.Q = (lambda*(2*pi*L/Nw)*(int.T - Tvol))/(log((rint + rext)/(2*rint)))*Nt
-        "Heat conduction through the internal half-thickness";
+    if WallRes then
+// Thermal resistance of the tube walls accounted for
+      int.Q = lambda * (2 * pi * L / Nw) * (int.T - Tvol) / log((rint + rext) / (2 * rint)) * Nt "Heat conduction through the internal half-thickness";
       ext.Q = (lambda*(2*pi*L/Nw)*(ext.T - Tvol))/(log((2*rext)/(rint + rext)))*Nt
         "Heat conduction through the external half-thickness";
-    else
-      // No temperature gradients across the thickness
+    else
+// No temperature gradients across the thickness
       ext.T = Tvol;
       int.T = Tvol;
     end if;
   initial equation
     if initOpt == Choices.Init.Options.noInit then
-      // do nothing
+// do nothing
     elseif initOpt == Choices.Init.Options.fixedState then
       Tvol = Tvolstart;
     elseif initOpt == Choices.Init.Options.steadyState then
       der(Tvol) = zeros(Nw);
     elseif initOpt == Choices.Init.Options.steadyStateNoT then
-      // do nothing
+// do nothing
     else
       assert(false, "Unsupported initialisation option");
     end if;
@@ -519,19 +517,19 @@
       ext.phi = lambda/(rext*log((2*rext)/(rint + rext)))*(ext.T - T)
         "Heat conduction through the external half-thickness";
     else
-      // No temperature gradients across the thickness
+// No temperature gradients across the thickness
       int.T = T;
       ext.T = T;
     end if;
   initial equation
     if initOpt == Choices.Init.Options.noInit then
-      // do nothing
+// do nothing
     elseif initOpt == Choices.Init.Options.fixedState then
       T = Tstart;
     elseif initOpt == Choices.Init.Options.steadyState then
       der(T) = zeros(N);
     elseif initOpt == Choices.Init.Options.steadyStateNoT then
-      // do nothing
+// do nothing
     else
       assert(false, "Unsupported initialisation option");
     end if;
@@ -617,19 +615,19 @@
       ext.Q = (ext.T-Tvol)*UA_ext/Nw;
       int.Q = (int.T-Tvol)*UA_int/Nw;
     else
-      // No temperature gradients across the thickness
+// No temperature gradients across the thickness
       ext.T = Tvol;
       int.T = Tvol;
     end if;
   initial equation
     if initOpt == ThermoPower.Choices.Init.Options.noInit then
-      // do nothing
+// do nothing
     elseif initOpt == Choices.Init.Options.fixedState then
       Tvol = Tvolstart;
     elseif initOpt == ThermoPower.Choices.Init.Options.steadyState then
       der(Tvol) = zeros(Nw);
     elseif initOpt == ThermoPower.Choices.Init.Options.steadyStateNoT then
-      // do nothing
+// do nothing
     else
       assert(false, "Unsupported initialisation option");
     end if;
@@ -705,18 +703,18 @@
             rotation=0)));
   equation
     Cm*der(T) = Sint*int.phi + Sext*ext.phi "Energy balance";
-    // No temperature gradients across the thickness
+// No temperature gradients across the thickness
     int.T = T;
     ext.T = T;
   initial equation
     if initOpt == ThermoPower.Choices.Init.Options.noInit then
-      // do nothing
+// do nothing
     elseif initOpt == Choices.Init.Options.fixedState then
       T = Tstart;
     elseif initOpt == ThermoPower.Choices.Init.Options.steadyState then
       der(T) = zeros(N);
     elseif initOpt == ThermoPower.Choices.Init.Options.steadyStateNoT then
-      // do nothing
+// do nothing
     else
       assert(false, "Unsupported initialisation option");
     end if;
@@ -843,7 +841,7 @@
     Thermal.DHTNodes side2(N=N) annotation (Placement(transformation(extent={{-40,-42},
               {40,-20}}, rotation=0)));
   equation
-    // Swap temperature and flux vector order
+// Swap temperature and flux vector order
     if counterCurrent then
       side1.phi = -side2.phi[N:-1:1];
       side1.T = side2.T[N:-1:1];
@@ -954,7 +952,7 @@
         "Constant heat transfer coefficient";
        parameter Boolean adaptiveAverageTemperature = true
         "Adapt the average temperature at low flow rates";
-       parameter Modelica.SIunits.PerUnit sigma = 0.1
+       parameter Modelica.Units.SI.PerUnit sigma = 0.1
         "Fraction of nominal flow rate below which the heat transfer is computed on outlet volume temperatures";
 
        SI.PerUnit w_wnom "Ratio between actual and nominal flow rate";
@@ -1080,7 +1078,7 @@
         "Nominal flow rate for heat transfer correlation (single tube)";
        parameter Boolean adaptiveAverageTemperature = true
         "Adapt the average temperature at low flow rates";
-       parameter Modelica.SIunits.PerUnit sigma = 0.1
+       parameter Modelica.Units.SI.PerUnit sigma = 0.1
         "Fraction of nominal flow rate below which the heat transfer is computed on outlet volume temperatures";
        parameter Boolean useHomotopy = true
        "use nominal heat transfer coefficient for simplified model";
@@ -1093,8 +1091,7 @@
         "Regularized ratio between actual and nominal flow rate";
     equation
       assert(Nw ==  Nf - 1, "Number of volumes Nw on wall side should be equal to number of volumes fluid side Nf - 1");
-
-      // Computation of actual heat transfer coefficient with smooth lower saturation to avoid numerical singularities at low flows
+// Computation of actual heat transfer coefficient with smooth lower saturation to avoid numerical singularities at low flows
       w_wnom = abs(w[1])/wnom_ht;
       w_wnom_reg = Functions.smoothSat(w_wnom, beta, 1e9, beta/2);
       if useHomotopy then
@@ -1161,7 +1158,7 @@
 
     equation
       assert(Nw == Nf - 1, "Number of volumes Nw on wall side should be equal to number of volumes fluid side Nf - 1");
-      // Fluid properties at the nodes
+// Fluid properties at the nodes
       for j in 1:Nf loop
         mu[j] = Medium.dynamicViscosity(fluidState[j]);
         k[j] = Medium.thermalConductivity(fluidState[j]);
@@ -1244,9 +1241,8 @@
       SI.Power Q "Total heat flow through lateral boundary";
 
     equation
-      assert(Nw == Nf - 1, "The number of volumes Nw on wall side should be equal to number of volumes fluid side Nf - 1");
-
-      // Saturated fluid property calculations
+      assert(Nw == Nf - 1, "The number of volumes Nw on wall side should be equal to number of volumes fluid side Nf - 1");
+// Saturated fluid property calculations
       p = Medium.pressure(fluidState[1]);
       sat = Medium.setSat_p(p);
       Ts = sat.Tsat;
@@ -1259,84 +1255,74 @@
       cp_bubble = Medium.heatCapacity_cp(bubble);
       mu_dew =  Medium.dynamicViscosity(dew);
       k_dew = Medium.thermalConductivity(dew);
-      cp_dew = Medium.heatCapacity_cp(dew);
-
-      // Heat transfer coefficient at bubble/dew point
-      gamma_bubble = Water.f_dittus_boelter(
-        w[1],
-        Dhyd,
-        A,
-        mu_bubble,
-        k_bubble,
-        cp_bubble);
+      cp_dew = Medium.heatCapacity_cp(dew);
+// Heat transfer coefficient at bubble/dew point
+      gamma_bubble = Water.f_dittus_boelter(w[1], Dhyd, A, mu_bubble, k_bubble, cp_bubble);
       gamma_dew = Water.f_dittus_boelter(
         w[1],
         Dhyd,
         A,
         mu_dew,
         k_dew,
-        cp_dew);
-
-      // Fluid property calculations at nodes
-      for j in 1:Nf loop
-        h[j] = Medium.specificEnthalpy(fluidState[j]);
-        /* to be fixed */
-        mu[j] = Medium.dynamicViscosity(fluidState[j]);  //not all nodes, only 1-phase nodes
-        k[j] = Medium.thermalConductivity(fluidState[j]); //not all nodes, only 1-phase nodes
-        cp[j] = Medium.heatCapacity_cp(fluidState[j]); //not all nodes, only 1-phase nodes
-        gamma1ph[j] = Water.f_dittus_boelter(
-          w[j],
-          Dhyd,
-          A,
-          mu[j],
-          k[j],
-          cp[j]);                                                     //not all nodes, only 1-phase nodes
-        /* to be fixed */
-      end for;
-
-      for j in 1:Nw loop
-         if noEvent((h[j] < hl and h[j + 1] < hl) or (h[j] > hv and h[j + 1]> hv)) then  // 1-phase liquid or vapour
-           Qw[j] = (Tw[j] - Tvol[j])*omega*l*Nt*((gamma1ph[j] + gamma1ph[j+1])/2)*kc;
-           state[j] = 1;
-           alpha_l[j] = 0;
-           alpha_v[j] = 0;
-         elseif noEvent((h[j] < hl and h[j + 1] >= hl and h[j + 1] <= hv)) then          // liquid --> 2-phase
-           Qw[j] = (alpha_l[j]*      (Tw[j] - (T[j] + Ts)/2)*omega*l*Nt*((gamma1ph[j] + gamma_bubble)/2) +
-                    (1 - alpha_l[j])*(Tw[j] - Ts)*omega*l*Nt*gamma2ph)*kc;
-           state[j] = 2;
-           alpha_l[j] = (hl - h[j])/(h[j + 1] - h[j]);
-           alpha_v[j] = 0;
-         elseif noEvent(h[j] >= hl and h[j] <= hv and h[j + 1] >= hl and h[j + 1]<= hv) then   // 2-phase
-           Qw[j] = (Tw[j] - Ts)*omega*l*Nt*gamma2ph*kc;
-           state[j] = 3;
-           alpha_l[j] = 0;
-           alpha_v[j] = 0;
-         elseif noEvent(h[j] >= hl and h[j] <= hv and h[j + 1] > hv) then                // 2-phase --> vapour
-           //Qw[j] = alpha_v[j]*(Tw[j] - (T[j + 1] + Ts)/2)*omega*l*(gamma1ph[j] + gamma1ph[j+1])/2 + (1 - alpha_v[j])*(Tw[j] - Ts)*omega*l*gamma2ph;
-           Qw[j] = (alpha_v[j]*      (Tw[j] - (T[j + 1] + Ts)/2)*omega*l*Nt*(gamma_dew + gamma1ph[j+1])/2 +
-                    (1 - alpha_v[j])*(Tw[j] - Ts)*omega*l*Nt*gamma2ph)*kc;
-           state[j] = 4;
-           alpha_l[j] = 0;
-           alpha_v[j] = (h[j + 1] - hv)/(h[j + 1] - h[j]);
-         elseif noEvent(h[j] >= hl and h[j] <= hv and h[j + 1] < hl) then                // 2-phase --> liquid
-           Qw[j] = (alpha_l[j]*      (Tw[j] - (T[j + 1] + Ts)/2)*omega*l*Nt*(gamma_bubble + gamma1ph[j+1])/2 +
-                    (1 - alpha_l[j])*(Tw[j] - Ts)*omega*l*Nt*gamma2ph)*kc;
-           state[j] = 5;
-           alpha_l[j] = (hl - h[j + 1])/(h[j] - h[j + 1]);
-           alpha_v[j] = 0;
-         else // if noEvent(h[j] > hv and h[j + 1] <= hv and h[j + 1] >= hl) then        // vapour --> 2-phase
-           Qw[j] = (alpha_v[j]*      (Tw[j] - (T[j] + Ts)/2)*omega*l*Nt*(gamma1ph[j] + gamma_dew)/2 +
-                    (1 - alpha_v[j])*(Tw[j] - Ts)*omega*l*Nt*gamma2ph)*kc;
-           state[j] = 6;
-           alpha_l[j] = 0;
-           alpha_v[j] = (h[j] - hv)/(h[j] - h[j + 1]);
-         end if;
-
-         if useAverageTemperature then
-           Tvol[j] = (T[j] + T[j + 1])/2;
-         else
-           Tvol[j] = T[j + 1];
-         end if;
+        cp_dew);
+// Fluid property calculations at nodes
+      for j in 1:Nf loop
+        h[j] = Medium.specificEnthalpy(fluidState[j]);
+/* to be fixed */
+        mu[j] = Medium.dynamicViscosity(fluidState[j]);
+//not all nodes, only 1-phase nodes
+        k[j] = Medium.thermalConductivity(fluidState[j]);
+//not all nodes, only 1-phase nodes
+        cp[j] = Medium.heatCapacity_cp(fluidState[j]);
+//not all nodes, only 1-phase nodes
+        gamma1ph[j] = Water.f_dittus_boelter(w[j], Dhyd, A, mu[j], k[j], cp[j]);
+//not all nodes, only 1-phase nodes
+/* to be fixed */
+      end for;
+  for j in 1:Nw loop
+        if noEvent(h[j] < hl and h[j + 1] < hl or h[j] > hv and h[j + 1] > hv) then
+// 1-phase liquid or vapour
+          Qw[j] = (Tw[j] - Tvol[j]) * omega * l * Nt * ((gamma1ph[j] + gamma1ph[j + 1]) / 2) * kc;
+          state[j] = 1;
+          alpha_l[j] = 0;
+          alpha_v[j] = 0;
+        elseif noEvent(h[j] < hl and h[j + 1] >= hl and h[j + 1] <= hv) then
+// liquid --> 2-phase
+          Qw[j] = (alpha_l[j] * (Tw[j] - (T[j] + Ts) / 2) * omega * l * Nt * ((gamma1ph[j] + gamma_bubble) / 2) + (1 - alpha_l[j]) * (Tw[j] - Ts) * omega * l * Nt * gamma2ph) * kc;
+          state[j] = 2;
+          alpha_l[j] = (hl - h[j]) / (h[j + 1] - h[j]);
+          alpha_v[j] = 0;
+        elseif noEvent(h[j] >= hl and h[j] <= hv and h[j + 1] >= hl and h[j + 1] <= hv) then
+// 2-phase
+          Qw[j] = (Tw[j] - Ts) * omega * l * Nt * gamma2ph * kc;
+          state[j] = 3;
+          alpha_l[j] = 0;
+          alpha_v[j] = 0;
+        elseif noEvent(h[j] >= hl and h[j] <= hv and h[j + 1] > hv) then
+// 2-phase --> vapour
+//Qw[j] = alpha_v[j]*(Tw[j] - (T[j + 1] + Ts)/2)*omega*l*(gamma1ph[j] + gamma1ph[j+1])/2 + (1 - alpha_v[j])*(Tw[j] - Ts)*omega*l*gamma2ph;
+          Qw[j] = (alpha_v[j] * (Tw[j] - (T[j + 1] + Ts) / 2) * omega * l * Nt * (gamma_dew + gamma1ph[j + 1]) / 2 + (1 - alpha_v[j]) * (Tw[j] - Ts) * omega * l * Nt * gamma2ph) * kc;
+          state[j] = 4;
+          alpha_l[j] = 0;
+          alpha_v[j] = (h[j + 1] - hv) / (h[j + 1] - h[j]);
+        elseif noEvent(h[j] >= hl and h[j] <= hv and h[j + 1] < hl) then
+// 2-phase --> liquid
+          Qw[j] = (alpha_l[j] * (Tw[j] - (T[j + 1] + Ts) / 2) * omega * l * Nt * (gamma_bubble + gamma1ph[j + 1]) / 2 + (1 - alpha_l[j]) * (Tw[j] - Ts) * omega * l * Nt * gamma2ph) * kc;
+          state[j] = 5;
+          alpha_l[j] = (hl - h[j + 1]) / (h[j] - h[j + 1]);
+          alpha_v[j] = 0;
+        else
+// if noEvent(h[j] > hv and h[j + 1] <= hv and h[j + 1] >= hl) then        // vapour --> 2-phase
+          Qw[j] = (alpha_v[j] * (Tw[j] - (T[j] + Ts) / 2) * omega * l * Nt * (gamma1ph[j] + gamma_dew) / 2 + (1 - alpha_v[j]) * (Tw[j] - Ts) * omega * l * Nt * gamma2ph) * kc;
+          state[j] = 6;
+          alpha_l[j] = 0;
+          alpha_v[j] = (h[j] - hv) / (h[j] - h[j + 1]);
+        end if;
+        if useAverageTemperature then
+          Tvol[j] = (T[j] + T[j + 1]) / 2;
+        else
+          Tvol[j] = T[j + 1];
+        end if;
       end for;
        annotation (
         Diagram(coordinateSystem(preserveAspectRatio=false, extent={{-100,-100},{100,
@@ -1383,11 +1369,9 @@
       Medium.SaturationProperties sat "Properties of saturated fluid";
       Medium.AbsolutePressure p "Fluid pressure for property calculations";
     equation
-      assert(Nw == Nf - 1, "The number of volumes Nw on wall side should be equal to number of volumes fluid side Nf - 1");
-
-      // Computation of actual h.t.c.'s
-      w_wnom = abs(w[1])/wnom_ht
-        "Inlet flow rate used for the computation of the h.t.c.";
+      assert(Nw == Nf - 1, "The number of volumes Nw on wall side should be equal to number of volumes fluid side Nf - 1");
+// Computation of actual h.t.c.'s
+      w_wnom = abs(w[1]) / wnom_ht "Inlet flow rate used for the computation of the h.t.c.";
       w_wnom_reg = Functions.smoothSat(w_wnom, beta, 1e9, beta/2)
         "Regularized w/wnom ratio";
       gamma_liq = homotopy(gamma_nom_liq*w_wnom_reg^alpha,
@@ -1395,67 +1379,66 @@
       gamma_2ph = homotopy(gamma_nom_2ph*w_wnom_reg^alpha,
                            gamma_nom_2ph);
       gamma_vap = homotopy(gamma_nom_vap*w_wnom_reg^alpha,
-                           gamma_nom_vap);
-
-      // Saturated fluid property calculations
+                           gamma_nom_vap);
+// Saturated fluid property calculations
       p = Medium.pressure(fluidState[1]);
       sat = Medium.setSat_p(p);
       Ts = sat.Tsat;
       hl = Medium.bubbleEnthalpy(sat);
-      hv = Medium.dewEnthalpy(sat);
-
-      // Fluid property calculations at nodes
-      for j in 1:Nf loop
-        h[j] = Medium.specificEnthalpy(fluidState[j]);
-      end for;
-
-      for j in 1:Nw loop
-         if noEvent(h[j] < hl and h[j + 1] < hl) then  // liquid
-           Qw[j] = (Tw[j] - Tvol[j])*omega*l*Nt*gamma_liq*kc;
-           state[j] = 0;
-           alpha_l[j] = 1;
-           alpha_v[j] = 0;
-         elseif noEvent(h[j] > hv and h[j + 1]> hv) then  // vapour
-           Qw[j] = (Tw[j] - Tvol[j])*omega*l*Nt*gamma_vap*kc;
-           state[j] = 1;
-           alpha_l[j] = 0;
-           alpha_v[j] = 1;
-         elseif noEvent((h[j] < hl and h[j + 1] >= hl and h[j + 1] <= hv)) then // liquid --> 2-phase
-           Qw[j] = (alpha_l[j]      *(Tw[j] - (T[j] + Ts)/2)*omega*l*Nt*gamma_liq +
-                    (1 - alpha_l[j])*(Tw[j] - Ts)           *omega*l*Nt*gamma_2ph)*kc;
-           state[j] = 2;
-           alpha_l[j] = (hl - h[j])/(h[j + 1] - h[j]);
-           alpha_v[j] = 0;
-         elseif noEvent(h[j] >= hl and h[j] <= hv and h[j + 1] >= hl and h[j + 1]<= hv) then // 2-phase
-           Qw[j] = (Tw[j] - Ts)*omega*l*Nt*gamma_2ph*kc;
-           state[j] = 3;
-           alpha_l[j] = 0;
-           alpha_v[j] = 0;
-         elseif noEvent(h[j] >= hl and h[j] <= hv and h[j + 1] > hv) then // 2-phase --> vapour
-           Qw[j] = (alpha_v[j]      *(Tw[j] - (T[j + 1] + Ts)/2)*omega*l*Nt*gamma_vap +
-                    (1 - alpha_v[j])*(Tw[j] - Ts)               *omega*l*Nt*gamma_2ph)*kc;
-           state[j] = 4;
-           alpha_l[j] = 0;
-           alpha_v[j] = (h[j + 1] - hv)/(h[j + 1] - h[j]);
-         elseif noEvent(h[j] >= hl and h[j] <= hv and h[j + 1] < hl) then // 2-phase --> liquid
-           Qw[j] = (alpha_l[j]      *(Tw[j] - (T[j + 1] + Ts)/2)*omega*l*Nt*gamma_liq +
-                    (1 - alpha_l[j])*(Tw[j] - Ts)               *omega*l*Nt*gamma_2ph)*kc;
-           state[j] = 5;
-           alpha_l[j] = (hl - h[j + 1])/(h[j] - h[j + 1]);
-           alpha_v[j] = 0;
-         else // if noEvent(h[j] > hv and h[j + 1] <= hv and h[j + 1] >= hl) then        // vapour --> 2-phase
-           Qw[j] = (alpha_v[j]      *(Tw[j] - (T[j] + Ts)/2)*omega*l*Nt*gamma_vap +
-                    (1 - alpha_v[j])*(Tw[j] - Ts)           *omega*l*Nt*gamma_2ph)*kc;
-           state[j] = 6;
-           alpha_l[j] = 0;
-           alpha_v[j] = (h[j] - hv)/(h[j] - h[j + 1]);
-         end if;
-
-         if useAverageTemperature then
-           Tvol[j] = (T[j] + T[j + 1])/2;
-         else
-           Tvol[j] = T[j + 1];
-         end if;
+      hv = Medium.dewEnthalpy(sat);
+// Fluid property calculations at nodes
+      for j in 1:Nf loop
+        h[j] = Medium.specificEnthalpy(fluidState[j]);
+      end for;
+  for j in 1:Nw loop
+        if noEvent(h[j] < hl and h[j + 1] < hl) then
+// liquid
+          Qw[j] = (Tw[j] - Tvol[j]) * omega * l * Nt * gamma_liq * kc;
+          state[j] = 0;
+          alpha_l[j] = 1;
+          alpha_v[j] = 0;
+        elseif noEvent(h[j] > hv and h[j + 1] > hv) then
+// vapour
+          Qw[j] = (Tw[j] - Tvol[j]) * omega * l * Nt * gamma_vap * kc;
+          state[j] = 1;
+          alpha_l[j] = 0;
+          alpha_v[j] = 1;
+        elseif noEvent(h[j] < hl and h[j + 1] >= hl and h[j + 1] <= hv) then
+// liquid --> 2-phase
+          Qw[j] = (alpha_l[j] * (Tw[j] - (T[j] + Ts) / 2) * omega * l * Nt * gamma_liq + (1 - alpha_l[j]) * (Tw[j] - Ts) * omega * l * Nt * gamma_2ph) * kc;
+          state[j] = 2;
+          alpha_l[j] = (hl - h[j]) / (h[j + 1] - h[j]);
+          alpha_v[j] = 0;
+        elseif noEvent(h[j] >= hl and h[j] <= hv and h[j + 1] >= hl and h[j + 1] <= hv) then
+// 2-phase
+          Qw[j] = (Tw[j] - Ts) * omega * l * Nt * gamma_2ph * kc;
+          state[j] = 3;
+          alpha_l[j] = 0;
+          alpha_v[j] = 0;
+        elseif noEvent(h[j] >= hl and h[j] <= hv and h[j + 1] > hv) then
+// 2-phase --> vapour
+          Qw[j] = (alpha_v[j] * (Tw[j] - (T[j + 1] + Ts) / 2) * omega * l * Nt * gamma_vap + (1 - alpha_v[j]) * (Tw[j] - Ts) * omega * l * Nt * gamma_2ph) * kc;
+          state[j] = 4;
+          alpha_l[j] = 0;
+          alpha_v[j] = (h[j + 1] - hv) / (h[j + 1] - h[j]);
+        elseif noEvent(h[j] >= hl and h[j] <= hv and h[j + 1] < hl) then
+// 2-phase --> liquid
+          Qw[j] = (alpha_l[j] * (Tw[j] - (T[j + 1] + Ts) / 2) * omega * l * Nt * gamma_liq + (1 - alpha_l[j]) * (Tw[j] - Ts) * omega * l * Nt * gamma_2ph) * kc;
+          state[j] = 5;
+          alpha_l[j] = (hl - h[j + 1]) / (h[j] - h[j + 1]);
+          alpha_v[j] = 0;
+        else
+// if noEvent(h[j] > hv and h[j + 1] <= hv and h[j + 1] >= hl) then        // vapour --> 2-phase
+          Qw[j] = (alpha_v[j] * (Tw[j] - (T[j] + Ts) / 2) * omega * l * Nt * gamma_vap + (1 - alpha_v[j]) * (Tw[j] - Ts) * omega * l * Nt * gamma_2ph) * kc;
+          state[j] = 6;
+          alpha_l[j] = 0;
+          alpha_v[j] = (h[j] - hv) / (h[j] - h[j + 1]);
+        end if;
+        if useAverageTemperature then
+          Tvol[j] = (T[j] + T[j + 1]) / 2;
+        else
+          Tvol[j] = T[j + 1];
+        end if;
       end for;
        annotation (
         Diagram(coordinateSystem(preserveAspectRatio=false, extent={{-100,-100},{100,
@@ -1527,8 +1510,7 @@
         "Regularized ratio between actual and nominal flow rate";
     equation
       assert(Nw ==  Nf, "Number of nodes Nw on wall side should be equal to number of nodes on the fluid side Nf");
-
-      // Computation of actual heat transfer coefficient with smooth lower saturation to avoid numerical singularities at low flows
+// Computation of actual heat transfer coefficient with smooth lower saturation to avoid numerical singularities at low flows
       w_wnom = abs(w[1])/wnom_ht
         "Inlet flow rate used for the computation of the h.t.c.";
       w_wnom_reg = Functions.smoothSat(w_wnom, beta, 1e9, beta/2);
@@ -1577,8 +1559,7 @@
       SI.PerUnit Pr_l[Nf] "Prandtl number limited to validity range";
     equation
       assert(Nw ==  Nf, "Number of nodes Nw on wall side should be equal to number of nodes on the fluid side Nf");
-
-      // Fluid properties and heat transfer coefficients at the nodes
+// Fluid properties and heat transfer coefficients at the nodes
       for j in 1:Nf loop
         mu[j] = Medium.dynamicViscosity(fluidState[j]);
         k[j] = Medium.thermalConductivity(fluidState[j]);
@@ -1621,9 +1602,9 @@
       partial model PartialMaterial
         "Partial material properties (base model of all material models)"
 
-        import Modelica.SIunits.*;
+        import Modelica.Units.SI.*;
 
-        // Constants to be set in Material
+// Constants to be set in Material
         constant String materialName "Name of the material";
         constant String materialDescription
           "Textual description of the material";
@@ -1631,7 +1612,7 @@
         constant PoissonNumber poissonRatio "Poisson ration of material";
         constant Density density "Density of material";
 
-        // Material properties depending on the material state
+// Material properties depending on the material state
         ModulusOfElasticity youngModulus "Young modulus of material";
         Stress yieldStress "Tensione di snervamento";
         Stress ultimateStress "Tensione di rottura";
@@ -1642,7 +1623,7 @@
         ThermalConductivity thermalConductivity
           "Thermal conductivity of the material";
 
-        // Material thermodynamic state
+// Material thermodynamic state
         connector InputTemperature = input SI.Temperature;
         InputTemperature T "Material temperature";
       end PartialMaterial;
@@ -1654,13 +1635,12 @@
 
         import Poly =
           ThermoPower.Thermal.MaterialProperties.Functions.Polynomials_Temp;
-        // Attenzione e' una funzione temporanea di Media!!!
-
+        // Attenzione e' una funzione temporanea di Media!!!
         extends Interfaces.PartialMaterial(materialName="tableMaterial",
             materialDescription="tableMaterial");
 
-        // Tables defining temperature dependent properties of material
-      protected
+// Tables defining temperature dependent properties of material
+        protected
         constant SI.ModulusOfElasticity[:, :] tableYoungModulus=fill(0, 0, 0)
           "Table for youngModulus(T)";
         constant SI.Stress[:, :] tableYieldStress=fill(0, 0, 0)
@@ -1673,7 +1653,7 @@
           tableLinearExpansionCoefficient=fill(0, 0,0) "Table for alfa(T)";
         constant SI.ThermalConductivity[:, :] tableThermalConductivity=fill(0, 0, 0)
           "Table for kappa(T)";
-        // Functions to interpolate table data
+        // Functions to interpolate table data
       public
         constant Integer npol=2 "degree of polynomial used for fitting";
       protected
@@ -1734,7 +1714,7 @@
           annotation (keepConstant=true);
 
       equation
-        // Table for main properties of the material should be defined!
+// Table for main properties of the material should be defined!
         assert(size(tableYoungModulus, 1) > 0, "Material " + materialName +
           " can not be used without assigning tableYoungModulus.");
         assert(size(tableSpecificHeatCapacity, 1) > 0, "Material " +
@@ -1763,7 +1743,7 @@
     package Functions
       "Utility functions. Provide conversions and interpolation for table data."
       function CtoKTable
-        extends Modelica.SIunits.Conversions.ConversionIcon;
+        extends Modelica.Units.Icons.Conversion;
 
         input Real[:, :] table_degC;
         output Real table_degK[size(table_degC, 1), size(table_degC, 2)];
@@ -1771,14 +1751,14 @@
         table_degK := table_degC;
 
         for i in 1:size(table_degC, 1) loop
-          table_degK[i, 1] := Modelica.SIunits.Conversions.from_degC(table_degC[
+          table_degK[i, 1] := Modelica.Units.Conversions.from_degC(table_degC[
             i, 1]);
         end for;
       end CtoKTable;
 
       package Polynomials_Temp "Temporary Functions operating on polynomials (including polynomial fitting), extracted from Modelica.Media.Incompressible.TableBased;
    only to be used in Material.MaterialTable"
-        extends Modelica.Icons.Library;
+        extends Modelica.Icons.Package;
 
         function evaluate "Evaluate polynomial at a given abszissa value"
           extends Modelica.Icons.Function;
@@ -1804,14 +1784,13 @@
             "Polynomial coefficients of polynomial that fits the date points";
         protected
           Real V[size(u, 1), n + 1] "Vandermonde matrix";
-        algorithm
-          // Construct Vandermonde matrix
+        algorithm
+// Construct Vandermonde matrix
           V[:, n + 1] := ones(size(u, 1));
           for j in n:-1:1 loop
             V[:, j] := {u[i]*V[i, j + 1] for i in 1:size(u, 1)};
-          end for;
-
-          // Solve least squares problem
+          end for;
+// Solve least squares problem
           p := Modelica.Math.Matrices.leastSquares(V, y);
         end fitting;
       end Polynomials_Temp;
@@ -1937,9 +1916,10 @@
       end AlloySteel_A335P12;
     end Metals;
 
+
     package Test "Test cases"
       model TestMaterial
-        import Modelica.SIunits.*;
+        import Modelica.Units.SI.*;
         replaceable Metals.CarbonSteel_A106C Material(npol=3) constrainedby
           Interfaces.PartialMaterial "Material model";
         Temp_K T;
@@ -1947,12 +1927,11 @@
         Stress E;
       equation
         T_C = 21 + 500*time;
-        T = Modelica.SIunits.Conversions.from_degC(T_C);
+        T = Modelica.Units.Conversions.from_degC(T_C);
         Material.T = T;
         E = Material.yieldStress;
       end TestMaterial;
     end Test;
-
     annotation (Documentation(revisions="<html>
 <ul>
 <li><i>8 June 2005</i>
@@ -2002,8 +1981,8 @@
       algorithm
         assert(mod(Nw,2) == 0,"Number of volumes must be even");
         assert(Ntp >= 1, "Number of passes tube-side must be greater than one");
-        // side1 <---> tube
-        // side2 <---> shell
+// side1 <---> tube
+// side2 <---> shell
         k := 1;
         correspondingVolumes[1] := k;
         if (inletTubeAtTop and inletShellAtTop) or (inletTubeAtTop == false and inletShellAtTop == false) then
@@ -2106,8 +2085,8 @@
         "= true to use average temperature for heat transfer";
       ThermoPower.Thermal.DHTVolumes wall(final N=Nw) annotation (Placement(transformation(extent={{-40,20},{40,
                 40}}, rotation=0)));
-      // The medium model and the following parameters will be set by the Flow1D
-      // models at instantiation not by end users
+      // The medium model and the following parameters will be set by the Flow1D
+      // models at instantiation not by end users
       replaceable package Medium = Modelica.Media.Interfaces.PartialMedium
         "Medium model"
         annotation(Dialog(enable=false, tab = "Set by Flow1D model"));
@@ -2129,7 +2108,7 @@
       parameter SI.MassFlowRate wnom "Nominal mass flow rate (single tube)"
         annotation(Dialog(enable=false, tab = "Set by Flow1D model"));
       final parameter SI.Length l=L/(Nw) "Length of a single volume";
-      parameter Modelica.SIunits.PerUnit kc = 1 "Correction factor for heat transfer";
+      parameter Modelica.Units.SI.PerUnit kc = 1 "Correction factor for heat transfer";
 
       Medium.Temperature T[Nf] "Temperatures at the fluid side nodes";
       Medium.Temperature Tw[Nw] "Temperatures of the wall volumes";
@@ -2154,8 +2133,8 @@
       input Medium.MassFlowRate w[Nf];
       ThermoPower.Thermal.DHTNodes wall(final N=Nw) annotation (Placement(transformation(extent={{-40,20},{40,
                 40}}, rotation=0)));
-      // The medium model and the following parameters will be set by the Flow1D
-      // models at instantiation not by end users
+      // The medium model and the following parameters will be set by the Flow1D
+      // models at instantiation not by end users
       replaceable package Medium = Modelica.Media.Interfaces.PartialMedium
         "Medium model"
         annotation(Dialog(enable=false, tab = "Set by Flow1D model"));
@@ -2182,7 +2161,7 @@
       Medium.Temperature Tw[Nw] "Temperatures of the wall volumes";
       SI.HeatFlux phi_w[Nw] "Heat fluxes entering from the wall connector";
       SI.HeatFlux phi_f[Nf] = phi_w "Heat fluxes going to the fluid nodes";
-      // SI.Power Q "Total heat flow through lateral boundary";
+      // SI.Power Q "Total heat flow through lateral boundary";
 
     equation
       for j in 1:Nf loop
@@ -2190,8 +2169,7 @@
       end for;
       Tw = wall.T;
       phi_w = wall.phi;
-      // Q = sum(wall.Q);
-
+// Q = sum(wall.Q);
     end DistributedHeatTransferFEM;
 
     partial model HeatExchangerTopologyData
@@ -2279,13 +2257,12 @@
     for i in 1:N loop
       DHT_port.T[i] = HT_port.T "Uniform temperature distribution on DHT side";
     end for;
-    if N == 1 then
-      // Uniform flow distribution
-      DHT_port.phi[1]*exchangeSurface + HT_port.Q_flow = 0 "Energy balance";
-    else
-      // Piecewise linear flow distribution
-      sum(DHT_port.phi[1:N - 1] + DHT_port.phi[2:N])/2*exchangeSurface/(N - 1)
-         + HT_port.Q_flow = 0 "Energy balance";
+    if N == 1 then
+// Uniform flow distribution
+      DHT_port.phi[1] * exchangeSurface + HT_port.Q_flow = 0 "Energy balance";
+    else
+// Piecewise linear flow distribution
+      sum(DHT_port.phi[1:N - 1] + DHT_port.phi[2:N]) / 2 * exchangeSurface / (N - 1) + HT_port.Q_flow = 0 "Energy balance";
     end if;
     annotation (Icon(graphics={
           Polygon(
@@ -2559,24 +2536,15 @@
       input Integer Nf "Number of nodes on the side with fewer nodes";
       output Real H[Nf, Nm] "Temperature weight matrix";
     algorithm
-      H := zeros(Nf, Nm);
-      // Flux on the first semi-cell, few nodes side
-      H[1, :] := fluxWeights(
-            Nm,
-            0,
-            0.5/(Nf - 1));
-      // Flux on the central cells, few nodes side
-      for i in 2:Nf - 1 loop
-        H[i, :] := fluxWeights(
-              Nm,
-              (i - 1.5)/(Nf - 1),
-              (i - 0.5)/(Nf - 1));
-      end for;
-      // Flux on the last semi-cell, few nodes side
-      H[Nf, :] := fluxWeights(
-            Nm,
-            1 - 0.5/(Nf - 1),
-            1);
+      H := zeros(Nf, Nm);
+// Flux on the first semi-cell, few nodes side
+      H[1, :] := fluxWeights(Nm, 0, 0.5 / (Nf - 1));
+// Flux on the central cells, few nodes side
+      for i in 2:Nf - 1 loop
+        H[i, :] := fluxWeights(Nm, (i - 1.5) / (Nf - 1), (i - 0.5) / (Nf - 1));
+      end for;
+// Flux on the last semi-cell, few nodes side
+      H[Nf, :] := fluxWeights(Nm, 1 - 0.5 / (Nf - 1), 1);
     end compHm;
 
     function fluxWeights "Returns the vector of the weights of the nodal fluxes
@@ -2592,48 +2560,48 @@
       Real hl "Width of the leftmost cell";
       Real hr "Width of the rightmost cell";
     algorithm
-      v := zeros(Nm);
-      // Index of the rightmost and leftmost involved nodes
-      lbi := 1 + integer(floor(lb*(Nm - 1) - 1e-6));
-      rbi := 1 + integer(ceil(rb*(Nm - 1) + 1e-6));
-      // Width of the inner, leftmost and rightmost cells
-      h := 1/(Nm - 1);
+      v := zeros(Nm);
+// Index of the rightmost and leftmost involved nodes
+      lbi := 1 + integer(floor(lb * (Nm - 1) - 1e-6));
+      rbi := 1 + integer(ceil(rb*(Nm - 1) + 1e-6));
+// Width of the inner, leftmost and rightmost cells
+      h := 1 / (Nm - 1);
       hl := lbi*h - lb;
-      hr := rb - (rbi - 2)*h;
-      // Coefficients of the contribution of the leftmost partial cell flow
-      if abs(hl) > 1e-6 then
-        v[lbi] := (hl/h)/2*hl;
-        v[lbi + 1] := ((h - hl)/h + 1)/2*hl;
-      end if;
-      // Coefficients of the contribution of the rightmost partial cell flow
-      if abs(hr) > 1e-6 then
-        v[rbi - 1] := (1 + (h - hr)/h)/2*hr;
-        v[rbi] := (hr/h)/2*hr;
-      end if;
-      // Coefficients of the additional contributions of the internal cells
-      for i in lbi + 1:rbi - 2 loop
-        v[i] := v[i] + h/2;
-        v[i + 1] := v[i + 1] + h/2;
-      end for;
-      // Coefficients are scaled to get the average flux from the flow
-      v := v/(rb - lb);
+      hr := rb - (rbi - 2)*h;
+// Coefficients of the contribution of the leftmost partial cell flow
+      if abs(hl) > 1e-6 then
+        v[lbi] := hl / h / 2 * hl;
+        v[lbi + 1] := ((h - hl) / h + 1) / 2 * hl;
+      end if;
+// Coefficients of the contribution of the rightmost partial cell flow
+      if abs(hr) > 1e-6 then
+        v[rbi - 1] := (1 + (h - hr) / h) / 2 * hr;
+        v[rbi] := hr / h / 2 * hr;
+      end if;
+// Coefficients of the additional contributions of the internal cells
+      for i in lbi + 1:rbi - 2 loop
+        v[i] := v[i] + h / 2;
+        v[i + 1] := v[i + 1] + h / 2;
+      end for;
+// Coefficients are scaled to get the average flux from the flow
+      v := v / (rb - lb);
     end fluxWeights;
 
     function compHf "Computes matrix H - side with fewer nodes"
       input Integer Nf "Number of nodes on the side with fewer nodes";
       output Real H[Nf, Nf] "Heat flux weight matrix";
     algorithm
-      H := zeros(Nf, Nf);
-      // Flux on the first semi-cell is average(phi[1],average(phi[1],phi[2]))
-      H[1, 1:2] := {3/4,1/4};
-      // Flux on the central cells is the average between the flux on the left
-      // semi-cell average(average(phi[i-1],phi[i]),phi[i]) and the flux on the right
-      // semi-cell average(phi[i],average(phi[i],phi[i+1]))
-      for i in 2:Nf - 1 loop
-        H[i, i - 1:i + 1] := {1/8,3/4,1/8};
-      end for;
-      // Flux on the last semi-cell is average(average(phi[Nf-1],phi[Nf]), phi[Nf])
-      H[Nf, Nf - 1:Nf] := {1/4,3/4};
+      H := zeros(Nf, Nf);
+// Flux on the first semi-cell is average(phi[1],average(phi[1],phi[2]))
+      H[1, 1:2] := {3 / 4, 1 / 4};
+// Flux on the central cells is the average between the flux on the left
+// semi-cell average(average(phi[i-1],phi[i]),phi[i]) and the flux on the right
+// semi-cell average(phi[i],average(phi[i],phi[i+1]))
+      for i in 2:Nf - 1 loop
+        H[i, i - 1:i + 1] := {1 / 8, 3 / 4, 1 / 8};
+      end for;
+// Flux on the last semi-cell is average(average(phi[Nf-1],phi[Nf]), phi[Nf])
+      H[Nf, Nf - 1:Nf] := {1 / 4, 3 / 4};
     end compHf;
 
     function compG "Computes matrix G"
@@ -2650,7 +2618,7 @@
       G := zeros(Nm, Nf);
       G[1, 1] := 1 "Temperature of first node";
       G[Nm, Nf] := 1 "Temperature of last node";
-      // Temperature of internal nodes by interpolation
+// Temperature of internal nodes by interpolation
       for i in 2:Nm - 1 loop
         firstNode := 1 + div((Nf - 1)*(i - 1), Nm - 1);
         lastNode := 1 + firstNode;
@@ -2697,7 +2665,7 @@
     end compH2;
 
   equation
-    // H1*side1.phi+H2*side2.phi = zeros(min(N1,N2)) "Energy balance";
+// H1*side1.phi+H2*side2.phi = zeros(min(N1,N2)) "Energy balance";
     if N1 >= N2 then
       side1.phi = gamma*(side1.T - G2*side2.T) "Convective heat transfer";
       side2.phi = -H21*side1.phi "Energy balance";
@@ -2796,24 +2764,15 @@
       input Integer Nf "Number of nodes on the side with fewer nodes";
       output Real H[Nf, Nm] "Temperature weight matrix";
     algorithm
-      H := zeros(Nf, Nm);
-      // Flux on the first semi-cell, few nodes side
-      H[1, :] := fluxWeights(
-            Nm,
-            0,
-            0.5/(Nf - 1));
-      // Flux on the central cells, few nodes side
-      for i in 2:Nf - 1 loop
-        H[i, :] := fluxWeights(
-              Nm,
-              (i - 1.5)/(Nf - 1),
-              (i - 0.5)/(Nf - 1));
-      end for;
-      // Flux on the last semi-cell, few nodes side
-      H[Nf, :] := fluxWeights(
-            Nm,
-            1 - 0.5/(Nf - 1),
-            1);
+      H := zeros(Nf, Nm);
+// Flux on the first semi-cell, few nodes side
+      H[1, :] := fluxWeights(Nm, 0, 0.5 / (Nf - 1));
+// Flux on the central cells, few nodes side
+      for i in 2:Nf - 1 loop
+        H[i, :] := fluxWeights(Nm, (i - 1.5) / (Nf - 1), (i - 0.5) / (Nf - 1));
+      end for;
+// Flux on the last semi-cell, few nodes side
+      H[Nf, :] := fluxWeights(Nm, 1 - 0.5 / (Nf - 1), 1);
     end compHm;
 
     function fluxWeights "Returns the vector of the weights of the nodal fluxes
@@ -2829,48 +2788,48 @@
       Real hl "Width of the leftmost cell";
       Real hr "Width of the rightmost cell";
     algorithm
-      v := zeros(Nm);
-      // Index of the rightmost and leftmost involved nodes
-      lbi := 1 + integer(floor(lb*(Nm - 1) - 1e-6));
-      rbi := 1 + integer(ceil(rb*(Nm - 1) + 1e-6));
-      // Width of the inner, leftmost and rightmost cells
-      h := 1/(Nm - 1);
+      v := zeros(Nm);
+// Index of the rightmost and leftmost involved nodes
+      lbi := 1 + integer(floor(lb * (Nm - 1) - 1e-6));
+      rbi := 1 + integer(ceil(rb*(Nm - 1) + 1e-6));
+// Width of the inner, leftmost and rightmost cells
+      h := 1 / (Nm - 1);
       hl := lbi*h - lb;
-      hr := rb - (rbi - 2)*h;
-      // Coefficients of the contribution of the leftmost partial cell flow
-      if abs(hl) > 1e-6 then
-        v[lbi] := (hl/h)/2*hl;
-        v[lbi + 1] := ((h - hl)/h + 1)/2*hl;
-      end if;
-      // Coefficients of the contribution of the rightmost partial cell flow
-      if abs(hr) > 1e-6 then
-        v[rbi - 1] := (1 + (h - hr)/h)/2*hr;
-        v[rbi] := (hr/h)/2*hr;
-      end if;
-      // Coefficients of the additional contributions of the internal cells
-      for i in lbi + 1:rbi - 2 loop
-        v[i] := v[i] + h/2;
-        v[i + 1] := v[i + 1] + h/2;
-      end for;
-      // Coefficients are scaled to get the average flux from the flow
-      v := v/(rb - lb);
+      hr := rb - (rbi - 2)*h;
+// Coefficients of the contribution of the leftmost partial cell flow
+      if abs(hl) > 1e-6 then
+        v[lbi] := hl / h / 2 * hl;
+        v[lbi + 1] := ((h - hl) / h + 1) / 2 * hl;
+      end if;
+// Coefficients of the contribution of the rightmost partial cell flow
+      if abs(hr) > 1e-6 then
+        v[rbi - 1] := (1 + (h - hr) / h) / 2 * hr;
+        v[rbi] := hr / h / 2 * hr;
+      end if;
+// Coefficients of the additional contributions of the internal cells
+      for i in lbi + 1:rbi - 2 loop
+        v[i] := v[i] + h / 2;
+        v[i + 1] := v[i + 1] + h / 2;
+      end for;
+// Coefficients are scaled to get the average flux from the flow
+      v := v / (rb - lb);
     end fluxWeights;
 
     function compHf "Computes matrix H - side with fewer nodes"
       input Integer Nf "Number of nodes on the side with fewer nodes";
       output Real H[Nf, Nf] "Heat flux weight matrix";
     algorithm
-      H := zeros(Nf, Nf);
-      // Flux on the first semi-cell is average(phi[1],average(phi[1],phi[2]))
-      H[1, 1:2] := {3/4,1/4};
-      // Flux on the central cells is the average between the flux on the left
-      // semi-cell average(average(phi[i-1],phi[i]),phi[i]) and the flux on the right
-      // semi-cell average(phi[i],average(phi[i],phi[i+1]))
-      for i in 2:Nf - 1 loop
-        H[i, i - 1:i + 1] := {1/8,3/4,1/8};
-      end for;
-      // Flux on the last semi-cell is average(average(phi[Nf-1],phi[Nf]), phi[Nf])
-      H[Nf, Nf - 1:Nf] := {1/4,3/4};
+      H := zeros(Nf, Nf);
+// Flux on the first semi-cell is average(phi[1],average(phi[1],phi[2]))
+      H[1, 1:2] := {3 / 4, 1 / 4};
+// Flux on the central cells is the average between the flux on the left
+// semi-cell average(average(phi[i-1],phi[i]),phi[i]) and the flux on the right
+// semi-cell average(phi[i],average(phi[i],phi[i+1]))
+      for i in 2:Nf - 1 loop
+        H[i, i - 1:i + 1] := {1 / 8, 3 / 4, 1 / 8};
+      end for;
+// Flux on the last semi-cell is average(average(phi[Nf-1],phi[Nf]), phi[Nf])
+      H[Nf, Nf - 1:Nf] := {1 / 4, 3 / 4};
     end compHf;
 
     function compG "Computes matrix G"
@@ -2887,7 +2846,7 @@
       G := zeros(Nm, Nf);
       G[1, 1] := 1 "Temperature of first node";
       G[Nm, Nf] := 1 "Temperature of last node";
-      // Temperature of internal nodes by interpolation
+// Temperature of internal nodes by interpolation
       for i in 2:Nm - 1 loop
         firstNode := 1 + div((Nf - 1)*(i - 1), Nm - 1);
         lastNode := 1 + firstNode;
@@ -2934,7 +2893,7 @@
     end compH2;
 
   equation
-    //H1*side1.phi+H2*side2.phi = zeros(min(N1,N2)) "Energy balance";
+//H1*side1.phi+H2*side2.phi = zeros(min(N1,N2)) "Energy balance";
     if N1 >= N2 then
       side1.phi = side1.gamma[1]*(side1.T - G2*side2.T)
         "Convective heat transfer";
@@ -2981,7 +2940,7 @@
     Thermal.DHT side2(N=N) annotation (Placement(transformation(extent={{-40,-42},
               {40,-20}}, rotation=0)));
   equation
-    // Swap temperature and flux vector order
+// Swap temperature and flux vector order
     if counterCurrent then
       side1.phi = -side2.phi[N:-1:1];
       side1.T = side2.T[N:-1:1];
@@ -3113,7 +3072,7 @@
 
   model CylinderFourier
     "Thermal model of a hollow cylinder by Fourier's equation - 1 axial node and Nr radial nodes"
-    import Modelica.SIunits.*;
+    import Modelica.Units.SI.*;
     import ThermoPower.Choices.CylinderFourier.NodeDistribution;
     extends ThermoPower.Icons.MetalWall;
 
@@ -3154,12 +3113,9 @@
     ThermoPower.Thermal.DHT externalBoundary(final N=1) annotation (Placement(
           transformation(extent={{-20,-40},{20,-20}}, rotation=0)));
 
-  equation
-    // Generation of the temperature node distribution
-    r_lin = linspace(
-        rint,
-        rext,
-        Nr) "Linearly distributed node radii";
+  equation
+// Generation of the temperature node distribution
+    r_lin = linspace(rint, rext, Nr) "Linearly distributed node radii";
     for i in 1:Nr loop
       if nodeDistribution == NodeDistribution.uniform then
         r[i] = r_lin[i] "Uniform distribution of node radii";
@@ -3184,48 +3140,40 @@
     end for;
     for i in 1:Nr - 1 loop
       r1_2[i] = (r[i + 1] + r[i])/2;
-    end for;
-
-    // Spatially discretized coefficients of Fourier's equation
-    for i in 2:Nr - 1 loop
-      A[i] = r1_2[i - 1]/(r[i]*(r[i] - r[i - 1])*(r1_2[i] - r1_2[i - 1]));
-      C[i] = r1_2[i]/(r[i]*(r[i + 1] - r[i])*(r1_2[i] - r1_2[i - 1]));
-      B[i] = -A[i] - C[i];
-    end for;
-    // Not used by Fourier equations
+    end for;
+// Spatially discretized coefficients of Fourier's equation
+    for i in 2:Nr - 1 loop
+      A[i] = r1_2[i - 1] / (r[i] * (r[i] - r[i - 1]) * (r1_2[i] - r1_2[i - 1]));
+      C[i] = r1_2[i] / (r[i] * (r[i + 1] - r[i]) * (r1_2[i] - r1_2[i - 1]));
+      B[i] = (-A[i]) - C[i];
+    end for;
+// Not used by Fourier equations
     A[1] = 0;
     B[1] = 0;
     C[1] = 0;
     A[Nr] = 0;
     B[Nr] = 0;
-    C[Nr] = 0;
-
-    // Metal temperature equations
-    metal[1:Nr].T = T[1:Nr];
-
-    // Thermal field
-    for i in 2:Nr - 1 loop
-      metal[i].density*metal[i].specificHeatCapacity/metal[i].thermalConductivity
-        *der(T[i]) = A[i]*T[i - 1] + B[i]*T[i] + C[i]*T[i + 1]
-        "Fourier's equation";
-    end for;
-
-    // Thermal boundary conditions
+    C[Nr] = 0;
+// Metal temperature equations
+    metal[1:Nr].T = T[1:Nr];
+// Thermal field
+    for i in 2:Nr - 1 loop
+      metal[i].density * metal[i].specificHeatCapacity / metal[i].thermalConductivity * der(T[i]) = A[i] * T[i - 1] + B[i] * T[i] + C[i] * T[i + 1] "Fourier's equation";
+    end for;
+// Thermal boundary conditions
     internalBoundary.T[1] = T[1];
     externalBoundary.T[1] = T[Nr];
     internalBoundary.phi[1] = -metal[1].thermalConductivity*(T[2] - T[1])/(r[2]
        - r[1]);
     externalBoundary.phi[1] = metal[Nr].thermalConductivity*(T[Nr] - T[Nr - 1])
-      /(r[Nr] - r[Nr - 1]);
-
-    // Mean temperature
-    Tm = 1/(rext^2 - rint^2)*sum((T[i]*r[i] + T[i + 1]*r[i + 1])*(r[i + 1] - r[
-      i]) for i in 1:Nr - 1);
-    //  Tm = sum(T)/Nr;
+      /(r[Nr] - r[Nr - 1]);
+// Mean temperature
+    Tm = 1 / (rext ^ 2 - rint ^ 2) * sum((T[i] * r[i] + T[i + 1] * r[i + 1]) * (r[i + 1] - r[i]) for i in 1:Nr - 1);
+//  Tm = sum(T)/Nr;
   initial equation
-    // Initial conditions
+// Initial conditions
     if initOpt == Choices.Init.Options.noInit then
-      // do nothing
+// do nothing
     elseif initOpt == Choices.Init.Options.steadyState then
       der(T[2:Nr - 1]) = zeros(Nr - 2);
     else
diff -ur "/home/hudson/saved_omc/libraries/.openmodelica/libraries/ThermoPower 3.1.0-master/Water.mo" "converted-libraries/.openmodelica/libraries/ThermoPower 3.1.0-master/Water.mo"
--- "/home/hudson/saved_omc/libraries/.openmodelica/libraries/ThermoPower 3.1.0-master/Water.mo"	2022-03-10 09:57:37.956144120 +0000
+++ "converted-libraries/.openmodelica/libraries/ThermoPower 3.1.0-master/Water.mo"	2022-03-10 09:58:41.624152187 +0000
@@ -1,20 +1,16 @@
-within ThermoPower;
-package Water "Models of components with water/steam as working fluid"
-  connector Flange "Flange connector for water/steam flows"
-    replaceable package Medium = StandardWater constrainedby
-      Modelica.Media.Interfaces.PartialMedium "Medium model";
-    flow Medium.MassFlowRate m_flow
-      "Mass flow rate from the connection point into the component";
-    Medium.AbsolutePressure p "Thermodynamic pressure in the connection point";
-    stream Medium.SpecificEnthalpy h_outflow
-      "Specific thermodynamic enthalpy close to the connection point if m_flow < 0";
-    stream Medium.MassFraction Xi_outflow[Medium.nXi]
-      "Independent mixture mass fractions m_i/m close to the connection point if m_flow < 0";
-    stream Medium.ExtraProperty C_outflow[Medium.nC]
-      "Properties c_i/m close to the connection point if m_flow < 0";
-    annotation (
-      Documentation(info="<HTML>.
-</HTML>", revisions="<html>
+within ThermoPower;
+
+package Water "Models of components with water/steam as working fluid"
+  connector Flange "Flange connector for water/steam flows"
+    replaceable package Medium = StandardWater constrainedby Modelica.Media.Interfaces.PartialMedium "Medium model";
+    flow Medium.MassFlowRate m_flow "Mass flow rate from the connection point into the component";
+    Medium.AbsolutePressure p "Thermodynamic pressure in the connection point";
+    stream Medium.SpecificEnthalpy h_outflow "Specific thermodynamic enthalpy close to the connection point if m_flow < 0";
+    stream Medium.MassFraction Xi_outflow[Medium.nXi] "Independent mixture mass fractions m_i/m close to the connection point if m_flow < 0";
+    stream Medium.ExtraProperty C_outflow[Medium.nC] "Properties c_i/m close to the connection point if m_flow < 0";
+    annotation(
+      Documentation(info = "<HTML>.
+</HTML>", revisions = "<html>
 <ul>
 <li><i>16 Dec 2004</i>
     by <a href=\"mailto:francesco.casella@polimi.it\">Francesco Casella</a>:<br>
@@ -23,131 +19,99 @@
     by <a href=\"mailto:francesco.casella@polimi.it\">Francesco Casella</a>:<br>
        First release.</li>
 </ul>
-</html>"),
-      Diagram(graphics),
-      Icon(graphics));
-  end Flange;
-
-  connector FlangeA "A-type flange connector for water/steam flows"
-    extends ThermoPower.Water.Flange;
-    annotation (Icon(graphics={Ellipse(
-            extent={{-100,100},{100,-100}},
-            lineColor={0,0,255},
-            fillColor={0,0,255},
-            fillPattern=FillPattern.Solid)}));
-  end FlangeA;
-
-  connector FlangeB "B-type flange connector for water/steam flows"
-    extends ThermoPower.Water.Flange;
-    annotation (Icon(graphics={Ellipse(
-            extent={{-100,100},{100,-100}},
-            lineColor={0,0,255},
-            fillColor={0,0,255},
-            fillPattern=FillPattern.Solid), Ellipse(
-            extent={{-40,40},{40,-40}},
-            lineColor={0,0,255},
-            fillColor={255,255,255},
-            fillPattern=FillPattern.Solid)}));
-  end FlangeB;
-  extends Modelica.Icons.Package;
-
-  package StandardWater = Modelica.Media.Water.StandardWater;
-  model SourcePressure "Pressure source for water/steam flows"
-    extends Icons.Water.SourceP;
-    replaceable package Medium = StandardWater constrainedby
-      Modelica.Media.Interfaces.PartialMedium "Medium model"
-      annotation(choicesAllMatching = true);
-    type HydraulicResistance = Real (
-       final quantity="HydraulicResistance", final unit="Pa/(kg/s)");
-    parameter Medium.AbsolutePressure p0=1.01325e5 "Nominal pressure";
-    parameter Units.HydraulicResistance R=0 "Hydraulic resistance";
-    parameter Boolean use_T = false "Use the temperature if true, otherwise use specific enthalpy";
-    parameter Medium.Temperature T = 298.15 "Nominal temperature"
-      annotation(Dialog(enable = use_T and not use_in_T));
-    parameter Medium.SpecificEnthalpy h=1e5 "Nominal specific enthalpy"
-      annotation(Dialog(enable = not use_T and not use_in_h));
-    parameter Boolean allowFlowReversal=system.allowFlowReversal
-      "= true to allow flow reversal, false restricts to design direction"
-      annotation(Evaluate=true);
-    parameter Boolean use_in_p0 = false "Use connector input for the pressure" annotation(Dialog(group="External inputs"), choices(checkBox=true));
-    parameter Boolean use_in_T = false
-      "Use connector input for the temperature"
-      annotation(Dialog(group="External inputs"), choices(checkBox=true));
-    parameter Boolean use_in_h = false
-      "Use connector input for the specific enthalpy" annotation(Dialog(group="External inputs"), choices(checkBox=true));
-    outer ThermoPower.System system "System wide properties";
-    Medium.AbsolutePressure p "Actual pressure";
-    FlangeB flange(redeclare package Medium = Medium) annotation (
-       Placement(transformation(extent={{80,-20},{120,20}}, rotation=0)));
-    Modelica.Blocks.Interfaces.RealInput in_p0 if use_in_p0 annotation (Placement(
-          transformation(
-          origin={-40,92},
-          extent={{-20,-20},{20,20}},
-          rotation=270), iconTransformation(
-          extent={{-16,-16},{16,16}},
-          rotation=270,
-          origin={-40,84})));
-    Modelica.Blocks.Interfaces.RealInput in_T if use_in_T
-      "Externally supplied temperature" annotation (Placement(transformation(
-          origin={0,60},
-          extent={{-20,-20},{20,20}},
-          rotation=270), iconTransformation(
-          extent={{-16,-16},{16,16}},
-          rotation=270,
-          origin={0,96})));
-    Modelica.Blocks.Interfaces.RealInput in_h if use_in_h annotation (Placement(
-          transformation(
-          origin={40,90},
-          extent={{-20,-20},{20,20}},
-          rotation=270), iconTransformation(
-          extent={{-16,-16},{16,16}},
-          rotation=270,
-          origin={42,84})));
-  protected
-    Modelica.Blocks.Interfaces.RealInput in_p0_internal;
-    Modelica.Blocks.Interfaces.RealInput in_T_internal;
-    Modelica.Blocks.Interfaces.RealInput in_h_internal;
-  equation
-    if R > 0 then
-      flange.p = p + flange.m_flow*R;
-    else
-      flange.p = p;
-    end if;
-
-    p = in_p0_internal;
-    if not use_in_p0 then
-      in_p0_internal = p0 "Pressure set by parameter";
-    end if;
-
-    if use_T then
-      flange.h_outflow = Medium.specificEnthalpy_pTX(flange.p, in_T_internal, fill(0,0));
-    else
-      flange.h_outflow = in_h_internal "Enthalpy set by connector";
-    end if;
-
-    if not use_in_T then
-      in_T_internal = T "Temperature set by parameter";
-    end if;
-    if not use_in_h then
-      in_h_internal = h "Enthalpy set by parameter";
-    end if;
-
-    // Connect protected connectors to public conditional connectors
-    connect(in_p0, in_p0_internal);
-    connect(in_T, in_T_internal);
-    connect(in_h, in_h_internal);
-
-    // Restrictions on modelling options
-    assert(not (use_in_T and use_in_h), "Either temperature or specific enthalpy input");
-    assert(not (use_T and use_in_h), "use_in_h required use_T = false");
-    assert(not (not use_T and use_in_T), "use_in_T required use_T = true");
-    annotation (
-      Documentation(info="<HTML>
+</html>"),
+      Diagram(graphics),
+      Icon(graphics));
+  end Flange;
+
+  connector FlangeA "A-type flange connector for water/steam flows"
+    extends ThermoPower.Water.Flange;
+    annotation(
+      Icon(graphics = {Ellipse(extent = {{-100, 100}, {100, -100}}, lineColor = {0, 0, 255}, fillColor = {0, 0, 255}, fillPattern = FillPattern.Solid)}));
+  end FlangeA;
+
+  connector FlangeB "B-type flange connector for water/steam flows"
+    extends ThermoPower.Water.Flange;
+    annotation(
+      Icon(graphics = {Ellipse(extent = {{-100, 100}, {100, -100}}, lineColor = {0, 0, 255}, fillColor = {0, 0, 255}, fillPattern = FillPattern.Solid), Ellipse(extent = {{-40, 40}, {40, -40}}, lineColor = {0, 0, 255}, fillColor = {255, 255, 255}, fillPattern = FillPattern.Solid)}));
+  end FlangeB;
+
+  extends Modelica.Icons.Package;
+  package StandardWater = Modelica.Media.Water.StandardWater;
+
+  model SourcePressure "Pressure source for water/steam flows"
+    extends Icons.Water.SourceP;
+    replaceable package Medium = StandardWater constrainedby Modelica.Media.Interfaces.PartialMedium "Medium model" annotation(
+       choicesAllMatching = true);
+    type HydraulicResistance = Real(final quantity = "HydraulicResistance", final unit = "Pa/(kg/s)");
+    parameter Medium.AbsolutePressure p0 = 1.01325e5 "Nominal pressure";
+    parameter Units.HydraulicResistance R = 0 "Hydraulic resistance";
+    parameter Boolean use_T = false "Use the temperature if true, otherwise use specific enthalpy";
+    parameter Medium.Temperature T = 298.15 "Nominal temperature" annotation(
+      Dialog(enable = use_T and not use_in_T));
+    parameter Medium.SpecificEnthalpy h = 1e5 "Nominal specific enthalpy" annotation(
+      Dialog(enable = not use_T and not use_in_h));
+    parameter Boolean allowFlowReversal = system.allowFlowReversal "= true to allow flow reversal, false restricts to design direction" annotation(
+      Evaluate = true);
+    parameter Boolean use_in_p0 = false "Use connector input for the pressure" annotation(
+      Dialog(group = "External inputs"),
+      choices(checkBox = true));
+    parameter Boolean use_in_T = false "Use connector input for the temperature" annotation(
+      Dialog(group = "External inputs"),
+      choices(checkBox = true));
+    parameter Boolean use_in_h = false "Use connector input for the specific enthalpy" annotation(
+      Dialog(group = "External inputs"),
+      choices(checkBox = true));
+    outer ThermoPower.System system "System wide properties";
+    Medium.AbsolutePressure p "Actual pressure";
+    FlangeB flange(redeclare package Medium = Medium) annotation(
+      Placement(transformation(extent = {{80, -20}, {120, 20}}, rotation = 0)));
+    Modelica.Blocks.Interfaces.RealInput in_p0 if use_in_p0 annotation(
+      Placement(transformation(origin = {-40, 92}, extent = {{-20, -20}, {20, 20}}, rotation = 270), iconTransformation(extent = {{-16, -16}, {16, 16}}, rotation = 270, origin = {-40, 84})));
+    Modelica.Blocks.Interfaces.RealInput in_T if use_in_T "Externally supplied temperature" annotation(
+      Placement(transformation(origin = {0, 60}, extent = {{-20, -20}, {20, 20}}, rotation = 270), iconTransformation(extent = {{-16, -16}, {16, 16}}, rotation = 270, origin = {0, 96})));
+    Modelica.Blocks.Interfaces.RealInput in_h if use_in_h annotation(
+      Placement(transformation(origin = {40, 90}, extent = {{-20, -20}, {20, 20}}, rotation = 270), iconTransformation(extent = {{-16, -16}, {16, 16}}, rotation = 270, origin = {42, 84})));
+  protected
+    Modelica.Blocks.Interfaces.RealInput in_p0_internal;
+    Modelica.Blocks.Interfaces.RealInput in_T_internal;
+    Modelica.Blocks.Interfaces.RealInput in_h_internal;
+  equation
+    if R > 0 then
+      flange.p = p + flange.m_flow * R;
+    else
+      flange.p = p;
+    end if;
+    p = in_p0_internal;
+    if not use_in_p0 then
+      in_p0_internal = p0 "Pressure set by parameter";
+    end if;
+    if use_T then
+      flange.h_outflow = Medium.specificEnthalpy_pTX(flange.p, in_T_internal, fill(0, 0));
+    else
+      flange.h_outflow = in_h_internal "Enthalpy set by connector";
+    end if;
+    if not use_in_T then
+      in_T_internal = T "Temperature set by parameter";
+    end if;
+    if not use_in_h then
+      in_h_internal = h "Enthalpy set by parameter";
+    end if;
+// Connect protected connectors to public conditional connectors
+    connect(in_p0, in_p0_internal);
+    connect(in_T, in_T_internal);
+    connect(in_h, in_h_internal);
+// Restrictions on modelling options
+    assert(not (use_in_T and use_in_h), "Either temperature or specific enthalpy input");
+    assert(not (use_T and use_in_h), "use_in_h required use_T = false");
+    assert(not (not use_T and use_in_T), "use_in_T required use_T = true");
+    annotation(
+      Documentation(info = "<HTML>
 <p><b>Modelling options</b></p>
 <p>If <tt>R</tt> is set to zero, the pressure source is ideal; otherwise, the outlet pressure decreases proportionally to the outgoing flowrate.</p>
 <p>If <code>use_T</code> is false, the specific enthalpy is prescribed, otherwise the temperature is prescribed.</p>
 <p>The pressure, specific enthalpy and temperature can be supplied from external inputs by setting to true the corresponding <code>use_in_XX</code> parameter and connecting an external signal to the input connector.</p>
-</HTML>", revisions="<html>
+</HTML>", revisions = "<html>
 <ul>
 <li><i>09 Oct 2017</i>
     by <a href=\"mailto:francesco.casella@polimi.it\">Francesco Casella</a>:<br>
@@ -156,109 +120,84 @@
     by <a href=\"mailto:francesco.casella@polimi.it\">Francesco Casella</a>:<br>
        First release.</li>
 </ul>
-</html>"));
-  end SourcePressure;
-
-  model SinkPressure "Pressure sink for water/steam flows"
-    extends Icons.Water.SourceP;
-    replaceable package Medium = StandardWater constrainedby
-      Modelica.Media.Interfaces.PartialMedium "Medium model"
-      annotation(choicesAllMatching = true);
-    type HydraulicResistance = Real (
-       final quantity="HydraulicResistance", final unit="Pa/(kg/s)");
-    parameter Medium.AbsolutePressure p0=1.01325e5 "Nominal pressure";
-    parameter Units.HydraulicResistance R=0 "Hydraulic resistance"
-      annotation (Evaluate=true);
-    parameter Boolean use_T = false "Use the temperature if true, otherwise use specific enthalpy";
-    parameter Medium.Temperature T = 298.15 "Nominal temperature"
-      annotation(Dialog(enable = use_T and not use_in_T));
-    parameter Medium.SpecificEnthalpy h=1e5 "Nominal specific enthalpy"
-      annotation(Dialog(enable = not use_T and not use_in_h));
-    parameter Boolean allowFlowReversal=system.allowFlowReversal
-      "= true to allow flow reversal, false restricts to design direction"
-      annotation(Evaluate=true);
-    parameter Boolean use_in_p0 = false "Use connector input for the pressure" annotation(Dialog(group="External inputs"), choices(checkBox=true));
-    parameter Boolean use_in_T = false
-      "Use connector input for the temperature"
-      annotation(Dialog(group="External inputs"), choices(checkBox=true));
-    parameter Boolean use_in_h = false
-      "Use connector input for the specific enthalpy" annotation(Dialog(group="External inputs"), choices(checkBox=true));
-    outer ThermoPower.System system "System wide properties";
-    Medium.AbsolutePressure p "Actual pressure";
-    FlangeA flange(redeclare package Medium = Medium, m_flow(min=if
-            allowFlowReversal then -Modelica.Constants.inf else 0)) annotation (
-       Placement(transformation(extent={{-120,-20},{-80,20}}, rotation=0)));
-    Modelica.Blocks.Interfaces.RealInput in_p0 if use_in_p0 annotation (Placement(
-          transformation(
-          origin={-40,92},
-          extent={{-20,-20},{20,20}},
-          rotation=270), iconTransformation(
-          extent={{-16,-16},{16,16}},
-          rotation=270,
-          origin={-40,84})));
-    Modelica.Blocks.Interfaces.RealInput in_T if use_in_T
-      "Externally supplied temperature" annotation (Placement(transformation(
-          origin={0,60},
-          extent={{-20,-20},{20,20}},
-          rotation=270), iconTransformation(
-          extent={{-16,-16},{16,16}},
-          rotation=270,
-          origin={0,96})));
-    Modelica.Blocks.Interfaces.RealInput in_h if use_in_h annotation (Placement(
-          transformation(
-          origin={40,90},
-          extent={{-20,-20},{20,20}},
-          rotation=270), iconTransformation(
-          extent={{-16,-16},{16,16}},
-          rotation=270,
-          origin={42,84})));
-  protected
-    Modelica.Blocks.Interfaces.RealInput in_p0_internal;
-    Modelica.Blocks.Interfaces.RealInput in_T_internal;
-    Modelica.Blocks.Interfaces.RealInput in_h_internal;
-
-  equation
-    if R > 0 then
-      flange.p = p + flange.m_flow*R;
-    else
-      flange.p = p;
-    end if;
-
-    p = in_p0_internal;
-    if not use_in_p0 then
-      in_p0_internal = p0 "Pressure set by parameter";
-    end if;
-
-    if use_T then
-      flange.h_outflow = Medium.specificEnthalpy_pTX(flange.p, in_T_internal, fill(0,0));
-    else
-      flange.h_outflow = in_h_internal "Enthalpy set by connector";
-    end if;
-
-    if not use_in_T then
-      in_T_internal = T "Temperature set by parameter";
-    end if;
-    if not use_in_h then
-      in_h_internal = h "Enthalpy set by parameter";
-    end if;
-
-    // Connect protected connectors to public conditional connectors
-    connect(in_p0, in_p0_internal);
-    connect(in_T, in_T_internal);
-    connect(in_h, in_h_internal);
-
-    // Restrictions on modelling options
-    assert(not (use_in_T and use_in_h), "Either temperature or specific enthalpy input");
-    assert(not (use_T and use_in_h), "use_in_h required use_T = false");
-    assert(not (not use_T and use_in_T), "use_in_T required use_T = true");
-    annotation (
-      Diagram(graphics),
-      Documentation(info="<HTML>
+</html>"));
+  end SourcePressure;
+
+  model SinkPressure "Pressure sink for water/steam flows"
+    extends Icons.Water.SourceP;
+    replaceable package Medium = StandardWater constrainedby Modelica.Media.Interfaces.PartialMedium "Medium model" annotation(
+       choicesAllMatching = true);
+    type HydraulicResistance = Real(final quantity = "HydraulicResistance", final unit = "Pa/(kg/s)");
+    parameter Medium.AbsolutePressure p0 = 1.01325e5 "Nominal pressure";
+    parameter Units.HydraulicResistance R = 0 "Hydraulic resistance" annotation(
+      Evaluate = true);
+    parameter Boolean use_T = false "Use the temperature if true, otherwise use specific enthalpy";
+    parameter Medium.Temperature T = 298.15 "Nominal temperature" annotation(
+      Dialog(enable = use_T and not use_in_T));
+    parameter Medium.SpecificEnthalpy h = 1e5 "Nominal specific enthalpy" annotation(
+      Dialog(enable = not use_T and not use_in_h));
+    parameter Boolean allowFlowReversal = system.allowFlowReversal "= true to allow flow reversal, false restricts to design direction" annotation(
+      Evaluate = true);
+    parameter Boolean use_in_p0 = false "Use connector input for the pressure" annotation(
+      Dialog(group = "External inputs"),
+      choices(checkBox = true));
+    parameter Boolean use_in_T = false "Use connector input for the temperature" annotation(
+      Dialog(group = "External inputs"),
+      choices(checkBox = true));
+    parameter Boolean use_in_h = false "Use connector input for the specific enthalpy" annotation(
+      Dialog(group = "External inputs"),
+      choices(checkBox = true));
+    outer ThermoPower.System system "System wide properties";
+    Medium.AbsolutePressure p "Actual pressure";
+    FlangeA flange(redeclare package Medium = Medium, m_flow(min = if allowFlowReversal then -Modelica.Constants.inf else 0)) annotation(
+      Placement(transformation(extent = {{-120, -20}, {-80, 20}}, rotation = 0)));
+    Modelica.Blocks.Interfaces.RealInput in_p0 if use_in_p0 annotation(
+      Placement(transformation(origin = {-40, 92}, extent = {{-20, -20}, {20, 20}}, rotation = 270), iconTransformation(extent = {{-16, -16}, {16, 16}}, rotation = 270, origin = {-40, 84})));
+    Modelica.Blocks.Interfaces.RealInput in_T if use_in_T "Externally supplied temperature" annotation(
+      Placement(transformation(origin = {0, 60}, extent = {{-20, -20}, {20, 20}}, rotation = 270), iconTransformation(extent = {{-16, -16}, {16, 16}}, rotation = 270, origin = {0, 96})));
+    Modelica.Blocks.Interfaces.RealInput in_h if use_in_h annotation(
+      Placement(transformation(origin = {40, 90}, extent = {{-20, -20}, {20, 20}}, rotation = 270), iconTransformation(extent = {{-16, -16}, {16, 16}}, rotation = 270, origin = {42, 84})));
+  protected
+    Modelica.Blocks.Interfaces.RealInput in_p0_internal;
+    Modelica.Blocks.Interfaces.RealInput in_T_internal;
+    Modelica.Blocks.Interfaces.RealInput in_h_internal;
+  equation
+    if R > 0 then
+      flange.p = p + flange.m_flow * R;
+    else
+      flange.p = p;
+    end if;
+    p = in_p0_internal;
+    if not use_in_p0 then
+      in_p0_internal = p0 "Pressure set by parameter";
+    end if;
+    if use_T then
+      flange.h_outflow = Medium.specificEnthalpy_pTX(flange.p, in_T_internal, fill(0, 0));
+    else
+      flange.h_outflow = in_h_internal "Enthalpy set by connector";
+    end if;
+    if not use_in_T then
+      in_T_internal = T "Temperature set by parameter";
+    end if;
+    if not use_in_h then
+      in_h_internal = h "Enthalpy set by parameter";
+    end if;
+// Connect protected connectors to public conditional connectors
+    connect(in_p0, in_p0_internal);
+    connect(in_T, in_T_internal);
+    connect(in_h, in_h_internal);
+// Restrictions on modelling options
+    assert(not (use_in_T and use_in_h), "Either temperature or specific enthalpy input");
+    assert(not (use_T and use_in_h), "use_in_h required use_T = false");
+    assert(not (not use_T and use_in_T), "use_in_T required use_T = true");
+    annotation(
+      Diagram(graphics),
+      Documentation(info = "<HTML>
 <p><b>Modelling options</b></p>
 <p>If <tt>R</tt> is set to zero, the pressure sink is ideal; otherwise, the inlet pressure increases proportionally to the incoming flowrate.</p>
 <p>If <code>use_T</code> is false, the specific enthalpy is prescribed, otherwise the temperature is prescribed.</p>
 <p>The pressure, specific enthalpy and temperature can be supplied from external inputs by setting to true the corresponding <code>use_in_XX</code> parameter and connecting an external signal to the input connector.</p>
-</HTML>", revisions="<html>
+</HTML>", revisions = "<html>
 <ul>
 <li><i>09 Oct 2017</i>
     by <a href=\"mailto:francesco.casella@polimi.it\">Francesco Casella</a>:<br>
@@ -267,108 +206,82 @@
     by <a href=\"mailto:francesco.casella@polimi.it\">Francesco Casella</a>:<br>
        First release.</li>
 </ul>
-</html>"));
-  end SinkPressure;
-
-  model SourceMassFlow "Flowrate source for water/steam flows"
-    extends Icons.Water.SourceW;
-    replaceable package Medium = StandardWater constrainedby
-      Modelica.Media.Interfaces.PartialPureSubstance "Medium model"
-      annotation(choicesAllMatching = true);
-    parameter Medium.MassFlowRate w0=0 "Nominal mass flowrate";
-    parameter Medium.AbsolutePressure p0=1e5 "Nominal pressure";
-    parameter Units.HydraulicConductance G=0 "Hydraulic conductance";
-    parameter Boolean use_T = false "Use the temperature if true, otherwise use specific enthalpy";
-    parameter Medium.Temperature T = 298.15 "Nominal temperature"
-      annotation(Dialog(enable = use_T and not use_in_T));
-    parameter Medium.SpecificEnthalpy h=1e5 "Nominal specific enthalpy"
-      annotation(Dialog(enable = not use_T and not use_in_h));
-    parameter Boolean allowFlowReversal=system.allowFlowReversal
-      "= true to allow flow reversal, false restricts to design direction"
-      annotation(Evaluate=true);
-    parameter Boolean use_in_w0 = false "Use connector input for the mass flow"
-      annotation(Dialog(group="External inputs"), choices(checkBox=true));
-    parameter Boolean use_in_T = false
-      "Use connector input for the temperature"
-      annotation(Dialog(group="External inputs"), choices(checkBox=true));
-    parameter Boolean use_in_h = false
-      "Use connector input for the specific enthalpy"
-      annotation(Dialog(group="External inputs"), choices(checkBox=true));
-    outer ThermoPower.System system "System wide properties";
-    Medium.MassFlowRate w "Mass flow rate";
-    FlangeB flange(redeclare package Medium = Medium) annotation (
-       Placement(transformation(extent={{80,-20},{120,20}}, rotation=0)));
-    Modelica.Blocks.Interfaces.RealInput in_w0 if use_in_w0
-      "Externally supplied mass flow rate"                  annotation (Placement(
-          transformation(
-          origin={-40,60},
-          extent={{-20,-20},{20,20}},
-          rotation=270), iconTransformation(
-          extent={{-16,-16},{16,16}},
-          rotation=270,
-          origin={-40,56})));
-    Modelica.Blocks.Interfaces.RealInput in_T if use_in_T
-      "Externally supplied temperature" annotation (Placement(transformation(
-          origin={0,60},
-          extent={{-20,-20},{20,20}},
-          rotation=270), iconTransformation(
-          extent={{-16,-16},{16,16}},
-          rotation=270,
-          origin={6,56})));
-    Modelica.Blocks.Interfaces.RealInput in_h if use_in_h
-      "Externally supplied specific enthalpy" annotation (Placement(
-          transformation(
-          origin={40,60},
-          extent={{-20,-20},{20,20}},
-          rotation=270), iconTransformation(
-          extent={{-16,-16},{16,16}},
-          rotation=270,
-          origin={52,56})));
-  protected
-    Modelica.Blocks.Interfaces.RealInput in_w0_internal;
-    Modelica.Blocks.Interfaces.RealInput in_T_internal;
-    Modelica.Blocks.Interfaces.RealInput in_h_internal;
-  equation
-    if G > 0 then
-      flange.m_flow = -w + (flange.p - p0)*G;
-    else
-      flange.m_flow = -w;
-    end if;
-
-    w = in_w0_internal;
-    if not use_in_w0 then
-      in_w0_internal = w0 "Flow rate set by parameter";
-    end if;
-
-    if use_T then
-      flange.h_outflow = Medium.specificEnthalpy_pTX(flange.p, in_T_internal, fill(0,0));
-    else
-      flange.h_outflow = in_h_internal "Enthalpy set by connector";
-    end if;
-
-    if not use_in_T then
-      in_T_internal = T "Temperature set by parameter";
-    end if;
-    if not use_in_h then
-      in_h_internal = h "Enthalpy set by parameter";
-    end if;
-
-    // Connect protected connectors to public conditional connectors
-    connect(in_w0, in_w0_internal);
-    connect(in_h, in_h_internal);
-    connect(in_T, in_T_internal);
-
-    // Restrictions on modelling options
-    assert(not (use_in_T and use_in_h), "Either temperature or specific enthalpy input");
-    assert(not (use_T and use_in_h), "use_in_h required use_T = false");
-    assert(not (not use_T and use_in_T), "use_in_T required use_T = true");
-    annotation (
-      Documentation(info="<HTML>
+</html>"));
+  end SinkPressure;
+
+  model SourceMassFlow "Flowrate source for water/steam flows"
+    extends Icons.Water.SourceW;
+    replaceable package Medium = StandardWater constrainedby Modelica.Media.Interfaces.PartialPureSubstance "Medium model" annotation(
+       choicesAllMatching = true);
+    parameter Medium.MassFlowRate w0 = 0 "Nominal mass flowrate";
+    parameter Medium.AbsolutePressure p0 = 1e5 "Nominal pressure";
+    parameter Units.HydraulicConductance G = 0 "Hydraulic conductance";
+    parameter Boolean use_T = false "Use the temperature if true, otherwise use specific enthalpy";
+    parameter Medium.Temperature T = 298.15 "Nominal temperature" annotation(
+      Dialog(enable = use_T and not use_in_T));
+    parameter Medium.SpecificEnthalpy h = 1e5 "Nominal specific enthalpy" annotation(
+      Dialog(enable = not use_T and not use_in_h));
+    parameter Boolean allowFlowReversal = system.allowFlowReversal "= true to allow flow reversal, false restricts to design direction" annotation(
+      Evaluate = true);
+    parameter Boolean use_in_w0 = false "Use connector input for the mass flow" annotation(
+      Dialog(group = "External inputs"),
+      choices(checkBox = true));
+    parameter Boolean use_in_T = false "Use connector input for the temperature" annotation(
+      Dialog(group = "External inputs"),
+      choices(checkBox = true));
+    parameter Boolean use_in_h = false "Use connector input for the specific enthalpy" annotation(
+      Dialog(group = "External inputs"),
+      choices(checkBox = true));
+    outer ThermoPower.System system "System wide properties";
+    Medium.MassFlowRate w "Mass flow rate";
+    FlangeB flange(redeclare package Medium = Medium) annotation(
+      Placement(transformation(extent = {{80, -20}, {120, 20}}, rotation = 0)));
+    Modelica.Blocks.Interfaces.RealInput in_w0 if use_in_w0 "Externally supplied mass flow rate" annotation(
+      Placement(transformation(origin = {-40, 60}, extent = {{-20, -20}, {20, 20}}, rotation = 270), iconTransformation(extent = {{-16, -16}, {16, 16}}, rotation = 270, origin = {-40, 56})));
+    Modelica.Blocks.Interfaces.RealInput in_T if use_in_T "Externally supplied temperature" annotation(
+      Placement(transformation(origin = {0, 60}, extent = {{-20, -20}, {20, 20}}, rotation = 270), iconTransformation(extent = {{-16, -16}, {16, 16}}, rotation = 270, origin = {6, 56})));
+    Modelica.Blocks.Interfaces.RealInput in_h if use_in_h "Externally supplied specific enthalpy" annotation(
+      Placement(transformation(origin = {40, 60}, extent = {{-20, -20}, {20, 20}}, rotation = 270), iconTransformation(extent = {{-16, -16}, {16, 16}}, rotation = 270, origin = {52, 56})));
+  protected
+    Modelica.Blocks.Interfaces.RealInput in_w0_internal;
+    Modelica.Blocks.Interfaces.RealInput in_T_internal;
+    Modelica.Blocks.Interfaces.RealInput in_h_internal;
+  equation
+    if G > 0 then
+      flange.m_flow = (-w) + (flange.p - p0) * G;
+    else
+      flange.m_flow = -w;
+    end if;
+    w = in_w0_internal;
+    if not use_in_w0 then
+      in_w0_internal = w0 "Flow rate set by parameter";
+    end if;
+    if use_T then
+      flange.h_outflow = Medium.specificEnthalpy_pTX(flange.p, in_T_internal, fill(0, 0));
+    else
+      flange.h_outflow = in_h_internal "Enthalpy set by connector";
+    end if;
+    if not use_in_T then
+      in_T_internal = T "Temperature set by parameter";
+    end if;
+    if not use_in_h then
+      in_h_internal = h "Enthalpy set by parameter";
+    end if;
+// Connect protected connectors to public conditional connectors
+    connect(in_w0, in_w0_internal);
+    connect(in_h, in_h_internal);
+    connect(in_T, in_T_internal);
+// Restrictions on modelling options
+    assert(not (use_in_T and use_in_h), "Either temperature or specific enthalpy input");
+    assert(not (use_T and use_in_h), "use_in_h required use_T = false");
+    assert(not (not use_T and use_in_T), "use_in_T required use_T = true");
+    annotation(
+      Documentation(info = "<HTML>
 <p><b>Modelling options</b></p>
 <p>If <code>G</code> is set to zero, the flowrate source is ideal; otherwise, the outgoing flowrate decreases proportionally to the outlet pressure.</p>
 <p>If <code>use_T</code> is false, the specific enthalpy is prescribed, otherwise the temperature is prescribed.</p>
 <p>The mass flow rate, specific enthalpy and temperature can be supplied from external inputs by setting to true the corresponding <code>use_in_XX</code> parameter and connecting an external signal to the input connector.</p>
-</HTML>", revisions="<html>
+</HTML>", revisions = "<html>
 <ul>
 <li><i>09 Oct 2017</i>
     by <a href=\"mailto:francesco.casella@polimi.it\">Francesco Casella</a>:<br>
@@ -377,112 +290,82 @@
     by <a href=\"mailto:francesco.casella@polimi.it\">Francesco Casella</a>:<br>
        First release.</li>
 </ul>
-</html>"));
-  end SourceMassFlow;
-
-  model SinkMassFlow "Flowrate sink for water/steam flows"
-    extends Icons.Water.SourceW;
-    replaceable package Medium = StandardWater constrainedby
-      Modelica.Media.Interfaces.PartialPureSubstance "Medium model"
-      annotation(choicesAllMatching = true);
-    parameter Medium.MassFlowRate w0=0 "Nominal mass flowrate";
-    parameter Medium.AbsolutePressure p0=1e5 "Nominal pressure";
-    parameter Units.HydraulicConductance G=0 "Hydraulic conductance";
-    parameter Boolean use_T = false "Use the temperature if true, otherwise use specific enthalpy";
-    parameter Medium.Temperature T = 298.15 "Nominal temperature"
-      annotation(Dialog(enable = use_T and not use_in_T));
-    parameter Medium.SpecificEnthalpy h=1e5 "Nominal specific enthalpy"
-      annotation(Dialog(enable = not use_T and not use_in_h));
-    parameter Boolean allowFlowReversal=system.allowFlowReversal
-      "= true to allow flow reversal, false restricts to design direction"
-      annotation(Evaluate=true);
-    parameter Boolean use_in_w0 = false "Use connector input for the mass flow"
-      annotation(Dialog(group="External inputs"), choices(checkBox=true));
-    parameter Boolean use_in_T = false
-      "Use connector input for the temperature"
-      annotation(Dialog(group="External inputs"), choices(checkBox=true));
-    parameter Boolean use_in_h = false
-      "Use connector input for the specific enthalpy"
-      annotation(Dialog(group="External inputs"), choices(checkBox=true));
-    outer ThermoPower.System system "System wide properties";
-    Medium.MassFlowRate w "Mass flow rate";
-    FlangeA flange(
-      redeclare package Medium = Medium,
-      m_flow(min = if allowFlowReversal then -Modelica.Constants.inf else 0)) annotation (
-       Placement(transformation(extent={{-120,-20},{-80,20}},
-                                                            rotation=0),
-          iconTransformation(extent={{-120,-20},{-80,20}})));
-    Modelica.Blocks.Interfaces.RealInput in_w0 if use_in_w0
-      "Externally supplied mass flow rate"                  annotation (Placement(
-          transformation(
-          origin={-40,60},
-          extent={{-20,-20},{20,20}},
-          rotation=270), iconTransformation(
-          extent={{-16,-16},{16,16}},
-          rotation=270,
-          origin={-40,56})));
-    Modelica.Blocks.Interfaces.RealInput in_T if use_in_T
-      "Externally supplied temperature" annotation (Placement(transformation(
-          origin={0,60},
-          extent={{-20,-20},{20,20}},
-          rotation=270), iconTransformation(
-          extent={{-16,-16},{16,16}},
-          rotation=270,
-          origin={6,56})));
-    Modelica.Blocks.Interfaces.RealInput in_h if use_in_h
-      "Externally supplied specific enthalpy" annotation (Placement(
-          transformation(
-          origin={40,60},
-          extent={{-20,-20},{20,20}},
-          rotation=270), iconTransformation(
-          extent={{-16,-16},{16,16}},
-          rotation=270,
-          origin={52,56})));
-  protected
-    Modelica.Blocks.Interfaces.RealInput in_w0_internal;
-    Modelica.Blocks.Interfaces.RealInput in_T_internal;
-    Modelica.Blocks.Interfaces.RealInput in_h_internal;
-  equation
-    if G > 0 then
-      flange.m_flow = w + (flange.p - p0)*G;
-    else
-      flange.m_flow = w;
-    end if;
-
-    w = in_w0_internal;
-    if not use_in_w0 then
-      in_w0_internal = w0 "Flow rate set by parameter";
-    end if;
-
-    if use_T then
-      flange.h_outflow = Medium.specificEnthalpy_pTX(flange.p, in_T_internal, fill(0,0));
-    else
-      flange.h_outflow = in_h_internal "Enthalpy set by connector";
-    end if;
-
-    if not use_in_T then
-      in_T_internal = T "Temperature set by parameter";
-    end if;
-    if not use_in_h then
-      in_h_internal = h "Enthalpy set by parameter";
-    end if;
-
-    // Connect protected connectors to public conditional connectors
-    connect(in_w0, in_w0_internal);
-    connect(in_h, in_h_internal);
-    connect(in_T, in_T_internal);
-
-    // Restrictions on modelling options
-    assert(not (use_in_T and use_in_h), "Either temperature or specific enthalpy input");
-    assert(not (use_T and use_in_h), "use_in_h required use_T = false");
-    assert(not (not use_T and use_in_T), "use_in_T required use_T = true");
-    annotation (
-      Documentation(info="<HTML>
+</html>"));
+  end SourceMassFlow;
+
+  model SinkMassFlow "Flowrate sink for water/steam flows"
+    extends Icons.Water.SourceW;
+    replaceable package Medium = StandardWater constrainedby Modelica.Media.Interfaces.PartialPureSubstance "Medium model" annotation(
+       choicesAllMatching = true);
+    parameter Medium.MassFlowRate w0 = 0 "Nominal mass flowrate";
+    parameter Medium.AbsolutePressure p0 = 1e5 "Nominal pressure";
+    parameter Units.HydraulicConductance G = 0 "Hydraulic conductance";
+    parameter Boolean use_T = false "Use the temperature if true, otherwise use specific enthalpy";
+    parameter Medium.Temperature T = 298.15 "Nominal temperature" annotation(
+      Dialog(enable = use_T and not use_in_T));
+    parameter Medium.SpecificEnthalpy h = 1e5 "Nominal specific enthalpy" annotation(
+      Dialog(enable = not use_T and not use_in_h));
+    parameter Boolean allowFlowReversal = system.allowFlowReversal "= true to allow flow reversal, false restricts to design direction" annotation(
+      Evaluate = true);
+    parameter Boolean use_in_w0 = false "Use connector input for the mass flow" annotation(
+      Dialog(group = "External inputs"),
+      choices(checkBox = true));
+    parameter Boolean use_in_T = false "Use connector input for the temperature" annotation(
+      Dialog(group = "External inputs"),
+      choices(checkBox = true));
+    parameter Boolean use_in_h = false "Use connector input for the specific enthalpy" annotation(
+      Dialog(group = "External inputs"),
+      choices(checkBox = true));
+    outer ThermoPower.System system "System wide properties";
+    Medium.MassFlowRate w "Mass flow rate";
+    FlangeA flange(redeclare package Medium = Medium, m_flow(min = if allowFlowReversal then -Modelica.Constants.inf else 0)) annotation(
+      Placement(transformation(extent = {{-120, -20}, {-80, 20}}, rotation = 0), iconTransformation(extent = {{-120, -20}, {-80, 20}})));
+    Modelica.Blocks.Interfaces.RealInput in_w0 if use_in_w0 "Externally supplied mass flow rate" annotation(
+      Placement(transformation(origin = {-40, 60}, extent = {{-20, -20}, {20, 20}}, rotation = 270), iconTransformation(extent = {{-16, -16}, {16, 16}}, rotation = 270, origin = {-40, 56})));
+    Modelica.Blocks.Interfaces.RealInput in_T if use_in_T "Externally supplied temperature" annotation(
+      Placement(transformation(origin = {0, 60}, extent = {{-20, -20}, {20, 20}}, rotation = 270), iconTransformation(extent = {{-16, -16}, {16, 16}}, rotation = 270, origin = {6, 56})));
+    Modelica.Blocks.Interfaces.RealInput in_h if use_in_h "Externally supplied specific enthalpy" annotation(
+      Placement(transformation(origin = {40, 60}, extent = {{-20, -20}, {20, 20}}, rotation = 270), iconTransformation(extent = {{-16, -16}, {16, 16}}, rotation = 270, origin = {52, 56})));
+  protected
+    Modelica.Blocks.Interfaces.RealInput in_w0_internal;
+    Modelica.Blocks.Interfaces.RealInput in_T_internal;
+    Modelica.Blocks.Interfaces.RealInput in_h_internal;
+  equation
+    if G > 0 then
+      flange.m_flow = w + (flange.p - p0) * G;
+    else
+      flange.m_flow = w;
+    end if;
+    w = in_w0_internal;
+    if not use_in_w0 then
+      in_w0_internal = w0 "Flow rate set by parameter";
+    end if;
+    if use_T then
+      flange.h_outflow = Medium.specificEnthalpy_pTX(flange.p, in_T_internal, fill(0, 0));
+    else
+      flange.h_outflow = in_h_internal "Enthalpy set by connector";
+    end if;
+    if not use_in_T then
+      in_T_internal = T "Temperature set by parameter";
+    end if;
+    if not use_in_h then
+      in_h_internal = h "Enthalpy set by parameter";
+    end if;
+// Connect protected connectors to public conditional connectors
+    connect(in_w0, in_w0_internal);
+    connect(in_h, in_h_internal);
+    connect(in_T, in_T_internal);
+// Restrictions on modelling options
+    assert(not (use_in_T and use_in_h), "Either temperature or specific enthalpy input");
+    assert(not (use_T and use_in_h), "use_in_h required use_T = false");
+    assert(not (not use_T and use_in_T), "use_in_T required use_T = true");
+    annotation(
+      Documentation(info = "<HTML>
 <p><b>Modelling options</b></p>
 <p>If <tt>G</tt> is set to zero, the flowrate source is ideal; otherwise, the outgoing flowrate increases proportionally to the inlet pressure.</p>
 <p>If <code>use_T</code> is false, the specific enthalpy is prescribed, otherwise the temperature is prescribed.</p>
 <p>The mass flow rate, specific enthalpy and temperature can be supplied from external inputs by setting to true the corresponding <code>use_in_XX</code> parameter and connecting an external signal to the input connector.</p>
-</HTML>", revisions="<html>
+</HTML>", revisions = "<html>
 <ul>
 <li><i>09 Oct 2017</i>
     by <a href=\"mailto:francesco.casella@polimi.it\">Francesco Casella</a>:<br>
@@ -491,96 +374,82 @@
     by <a href=\"mailto:francesco.casella@polimi.it\">Francesco Casella</a>:<br>
        First release.</li>
 </ul>
-</html>"));
-  end SinkMassFlow;
-
-  model ThroughMassFlow "Prescribes the flow rate across the component"
-    extends Icons.Water.SourceW;
-    replaceable package Medium = StandardWater constrainedby
-      Modelica.Media.Interfaces.PartialMedium "Medium model"
-      annotation(choicesAllMatching = true);
-    parameter Medium.MassFlowRate w0=0 "Nominal mass flow rate";
-    parameter Boolean allowFlowReversal=system.allowFlowReversal
-      "= true to allow flow reversal, false restricts to design direction"
-      annotation(Evaluate=true);
-    parameter Boolean use_in_w0 = false "Use connector input for the mass flow" annotation(Dialog(group="External inputs"), choices(checkBox=true));
-    outer ThermoPower.System system "System wide properties";
-    Medium.MassFlowRate w "Mass flow rate";
-    FlangeA inlet(redeclare package Medium = Medium, m_flow(min=if
-            allowFlowReversal then -Modelica.Constants.inf else 0)) annotation (
-       Placement(transformation(extent={{-120,-20},{-80,20}}, rotation=0)));
-    FlangeB outlet(redeclare package Medium = Medium, m_flow(max=if
-            allowFlowReversal then +Modelica.Constants.inf else 0)) annotation (
-       Placement(transformation(extent={{80,-20},{120,20}}, rotation=0)));
-    Modelica.Blocks.Interfaces.RealInput in_w0 if use_in_w0 annotation (Placement(
-          transformation(
-          origin={-40,60},
-          extent={{-20,-20},{20,20}},
-          rotation=270)));
-  protected
-    Modelica.Blocks.Interfaces.RealInput in_w0_internal;
-
-  equation
-    inlet.m_flow + outlet.m_flow = 0 "Mass balance";
-    inlet.m_flow = w "Flow characteristics";
-
-    w = in_w0_internal;
-    if not use_in_w0 then
-      in_w0_internal = w0 "Flow rate set by parameter";
-    end if;
-
-    // Energy balance
-    inlet.h_outflow = inStream(outlet.h_outflow);
-    inStream(inlet.h_outflow) = outlet.h_outflow;
-
-    // Connect protected connectors to public conditional connectors
-    connect(in_w0, in_w0_internal);
-
-    annotation (
-      Icon(graphics={Text(extent={{-98,72},{-48,40}}, textString="w0")}),
-      Documentation(info="<HTML>
+</html>"));
+  end SinkMassFlow;
+
+  model ThroughMassFlow "Prescribes the flow rate across the component"
+    extends Icons.Water.SourceW;
+    replaceable package Medium = StandardWater constrainedby Modelica.Media.Interfaces.PartialMedium "Medium model" annotation(
+       choicesAllMatching = true);
+    parameter Medium.MassFlowRate w0 = 0 "Nominal mass flow rate";
+    parameter Boolean allowFlowReversal = system.allowFlowReversal "= true to allow flow reversal, false restricts to design direction" annotation(
+      Evaluate = true);
+    parameter Boolean use_in_w0 = false "Use connector input for the mass flow" annotation(
+      Dialog(group = "External inputs"),
+      choices(checkBox = true));
+    outer ThermoPower.System system "System wide properties";
+    Medium.MassFlowRate w "Mass flow rate";
+    FlangeA inlet(redeclare package Medium = Medium, m_flow(min = if allowFlowReversal then -Modelica.Constants.inf else 0)) annotation(
+      Placement(transformation(extent = {{-120, -20}, {-80, 20}}, rotation = 0)));
+    FlangeB outlet(redeclare package Medium = Medium, m_flow(max = if allowFlowReversal then +Modelica.Constants.inf else 0)) annotation(
+      Placement(transformation(extent = {{80, -20}, {120, 20}}, rotation = 0)));
+    Modelica.Blocks.Interfaces.RealInput in_w0 if use_in_w0 annotation(
+      Placement(transformation(origin = {-40, 60}, extent = {{-20, -20}, {20, 20}}, rotation = 270)));
+  protected
+    Modelica.Blocks.Interfaces.RealInput in_w0_internal;
+  equation
+    inlet.m_flow + outlet.m_flow = 0 "Mass balance";
+    inlet.m_flow = w "Flow characteristics";
+    w = in_w0_internal;
+    if not use_in_w0 then
+      in_w0_internal = w0 "Flow rate set by parameter";
+    end if;
+// Energy balance
+    inlet.h_outflow = inStream(outlet.h_outflow);
+    inStream(inlet.h_outflow) = outlet.h_outflow;
+// Connect protected connectors to public conditional connectors
+    connect(in_w0, in_w0_internal);
+    annotation(
+      Icon(graphics = {Text(extent = {{-98, 72}, {-48, 40}}, textString = "w0")}),
+      Documentation(info = "<HTML>
 This component prescribes the flow rate passing through it. The change of
 specific enthalpy due to the pressure difference between the inlet and the
 outlet is ignored; use <t>Pump</t> models if this has to be taken into account correctly.
 <p><b>Modelling options</b></p>
 <p>If <tt>w0Fix</tt> is set to true, the flowrate is given by the parameter <tt>w0</tt>; otherwise, the <tt>in_w0</tt> connector must be wired, providing the (possibly varying) flowrate value.</p>
-</HTML>", revisions="<html>
+</HTML>", revisions = "<html>
 <ul>
 <li><i>18 Mar 2005</i>
     by <a href=\"mailto:francesco.casella@polimi.it\">Francesco Casella</a>:<br>
        First release.</li>
 </ul>
-</html>"),
-      Diagram(graphics));
-  end ThroughMassFlow;
-
-  model PressDropLin "Linear pressure drop for water/steam flows"
-    extends Icons.Water.PressDrop;
-    replaceable package Medium = StandardWater constrainedby
-      Modelica.Media.Interfaces.PartialMedium "Medium model"
-      annotation(choicesAllMatching = true);
-    parameter Units.HydraulicResistance R "Hydraulic resistance";
-    parameter Boolean allowFlowReversal=system.allowFlowReversal
-      "= true to allow flow reversal, false restricts to design direction"
-      annotation(Evaluate=true);
-    outer ThermoPower.System system "System wide properties";
-    FlangeA inlet(redeclare package Medium = Medium, m_flow(min=if
-            allowFlowReversal then -Modelica.Constants.inf else 0)) annotation (
-       Placement(transformation(extent={{-120,-20},{-80,20}}, rotation=0)));
-    FlangeB outlet(redeclare package Medium = Medium, m_flow(max=if
-            allowFlowReversal then +Modelica.Constants.inf else 0)) annotation (
-       Placement(transformation(extent={{80,-20},{120,20}}, rotation=0)));
-  equation
-    inlet.m_flow + outlet.m_flow = 0;
-    inlet.p - outlet.p = R*inlet.m_flow "Flow characteristics";
-    // Energy balance
-    inlet.h_outflow = inStream(outlet.h_outflow);
-    inStream(inlet.h_outflow) = outlet.h_outflow;
-    annotation (
-      Icon(graphics={Text(extent={{-100,-44},{100,-76}}, textString="%name")}),
-      Documentation(info="<HTML>
+</html>"),
+      Diagram(graphics));
+  end ThroughMassFlow;
+
+  model PressDropLin "Linear pressure drop for water/steam flows"
+    extends Icons.Water.PressDrop;
+    replaceable package Medium = StandardWater constrainedby Modelica.Media.Interfaces.PartialMedium "Medium model" annotation(
+       choicesAllMatching = true);
+    parameter Units.HydraulicResistance R "Hydraulic resistance";
+    parameter Boolean allowFlowReversal = system.allowFlowReversal "= true to allow flow reversal, false restricts to design direction" annotation(
+      Evaluate = true);
+    outer ThermoPower.System system "System wide properties";
+    FlangeA inlet(redeclare package Medium = Medium, m_flow(min = if allowFlowReversal then -Modelica.Constants.inf else 0)) annotation(
+      Placement(transformation(extent = {{-120, -20}, {-80, 20}}, rotation = 0)));
+    FlangeB outlet(redeclare package Medium = Medium, m_flow(max = if allowFlowReversal then +Modelica.Constants.inf else 0)) annotation(
+      Placement(transformation(extent = {{80, -20}, {120, 20}}, rotation = 0)));
+  equation
+    inlet.m_flow + outlet.m_flow = 0;
+    inlet.p - outlet.p = R * inlet.m_flow "Flow characteristics";
+// Energy balance
+    inlet.h_outflow = inStream(outlet.h_outflow);
+    inStream(inlet.h_outflow) = outlet.h_outflow;
+    annotation(
+      Icon(graphics = {Text(extent = {{-100, -44}, {100, -76}}, textString = "%name")}),
+      Documentation(info = "<HTML>
 <p>This very simple model provides a pressure drop which is proportional to the flowrate, without computing any fluid property.</p>
-</HTML>", revisions="<html>
+</HTML>", revisions = "<html>
 <ul>
 <li><i>16 Dec 2004</i>
     by <a href=\"mailto:francesco.casella@polimi.it\">Francesco Casella</a>:<br>
@@ -590,62 +459,57 @@
        First release.</li>
 </ul>
 </html>
-"),   Diagram(graphics));
-  end PressDropLin;
-
-  model PressDrop "Pressure drop for water/steam flows"
-    extends Icons.Water.PressDrop;
-    import ThermoPower.Choices.PressDrop.FFtypes;
-    replaceable package Medium = StandardWater constrainedby
-      Modelica.Media.Interfaces.PartialMedium "Medium model"
-      annotation(choicesAllMatching = true);
-    Medium.ThermodynamicState state "Thermodynamic state of the fluid";
-    parameter Medium.MassFlowRate wnom "Nominal mass flowrate";
-    parameter FFtypes FFtype=FFtypes.Kf "Friction Factor Type";
-    parameter Real Kf = 0 "Hydraulic resistance coefficient (DP = Kf*w^2/rho)"
-      annotation(Dialog(enable = (FFtype == ThermoPower.Choices.PressDrop.FFtypes.Kf)));
-    parameter SI.PressureDifference dpnom "Nominal pressure drop";
-    parameter Medium.Density rhonom=0 "Nominal density"
-      annotation(Dialog(enable = (FFtype == ThermoPower.Choices.PressDrop.FFtypes.OpPoint)));
-    parameter Real K=0 "Kinetic resistance coefficient (DP=K*rho*velocity2/2)";
-    parameter SI.Area A=0 "Cross-section";
-    parameter SI.PerUnit wnf=0.01
-      "Fraction of nominal flow rate at which linear friction equals turbulent friction";
-    parameter SI.PerUnit Kfc=1 "Friction factor correction coefficient";
-    final parameter Real Kf_a(fixed = false)
-      "Actual hydraulic resistance coefficient";
-    parameter Boolean allowFlowReversal=system.allowFlowReversal
-      "= true to allow flow reversal, false restricts to design direction"
-      annotation(Evaluate=true);
-    outer ThermoPower.System system "System wide properties";
-    function squareReg = ThermoPower.Functions.squareReg;
-    Medium.Density rho "Fluid density";
-    Medium.MassFlowRate w "Flow rate at the inlet";
-    Medium.AbsolutePressure pin "Inlet pressure";
-    Medium.AbsolutePressure pout "Outlet pressure";
-    SI.PressureDifference dp "Pressure drop";
-    FlangeA inlet(m_flow(start=wnom, min=if allowFlowReversal then -Modelica.Constants.inf
-             else 0), redeclare package Medium = Medium) annotation (Placement(
-          transformation(extent={{-120,-20},{-80,20}}, rotation=0)));
-    FlangeB outlet(m_flow(start=-wnom, max=if allowFlowReversal then +Modelica.Constants.inf
-             else 0), redeclare package Medium = Medium) annotation (Placement(
-          transformation(extent={{80,-20},{120,20}}, rotation=0)));
-  initial equation
-    if FFtype == FFtypes.Kf then
-      Kf_a = Kf*Kfc;
-    elseif FFtype == FFtypes.OpPoint then
-      Kf_a = dpnom*rhonom/wnom^2*Kfc;
-    elseif FFtype == FFtypes.Kinetic then
-      Kf_a = K/(2*A^2)*Kfc;
-    else
-      Kf_a = 0;
-      assert(false, "Unsupported FFtype");
-    end if;
-  equation
-    assert(dpnom > 0, "Please set a positive value for dpnom");
-    assert(rhonom > 0 or FFtype <> FFtypes.OpPoint, "Please set a positive value for rhonom");
-    // Fluid properties
-  /*
+      "),
+      Diagram(graphics));
+  end PressDropLin;
+
+  model PressDrop "Pressure drop for water/steam flows"
+    extends Icons.Water.PressDrop;
+    import ThermoPower.Choices.PressDrop.FFtypes;
+    replaceable package Medium = StandardWater constrainedby Modelica.Media.Interfaces.PartialMedium "Medium model" annotation(
+       choicesAllMatching = true);
+    Medium.ThermodynamicState state "Thermodynamic state of the fluid";
+    parameter Medium.MassFlowRate wnom "Nominal mass flowrate";
+    parameter FFtypes FFtype = FFtypes.Kf "Friction Factor Type";
+    parameter Real Kf = 0 "Hydraulic resistance coefficient (DP = Kf*w^2/rho)" annotation(
+      Dialog(enable = FFtype == ThermoPower.Choices.PressDrop.FFtypes.Kf));
+    parameter SI.PressureDifference dpnom "Nominal pressure drop";
+    parameter Medium.Density rhonom = 0 "Nominal density" annotation(
+      Dialog(enable = FFtype == ThermoPower.Choices.PressDrop.FFtypes.OpPoint));
+    parameter Real K = 0 "Kinetic resistance coefficient (DP=K*rho*velocity2/2)";
+    parameter SI.Area A = 0 "Cross-section";
+    parameter SI.PerUnit wnf = 0.01 "Fraction of nominal flow rate at which linear friction equals turbulent friction";
+    parameter SI.PerUnit Kfc = 1 "Friction factor correction coefficient";
+    final parameter Real Kf_a(fixed = false) "Actual hydraulic resistance coefficient";
+    parameter Boolean allowFlowReversal = system.allowFlowReversal "= true to allow flow reversal, false restricts to design direction" annotation(
+      Evaluate = true);
+    outer ThermoPower.System system "System wide properties";
+    function squareReg = ThermoPower.Functions.squareReg;
+    Medium.Density rho "Fluid density";
+    Medium.MassFlowRate w "Flow rate at the inlet";
+    Medium.AbsolutePressure pin "Inlet pressure";
+    Medium.AbsolutePressure pout "Outlet pressure";
+    SI.PressureDifference dp "Pressure drop";
+    FlangeA inlet(m_flow(start = wnom, min = if allowFlowReversal then -Modelica.Constants.inf else 0), redeclare package Medium = Medium) annotation(
+      Placement(transformation(extent = {{-120, -20}, {-80, 20}}, rotation = 0)));
+    FlangeB outlet(m_flow(start = -wnom, max = if allowFlowReversal then +Modelica.Constants.inf else 0), redeclare package Medium = Medium) annotation(
+      Placement(transformation(extent = {{80, -20}, {120, 20}}, rotation = 0)));
+  initial equation
+    if FFtype == FFtypes.Kf then
+      Kf_a = Kf * Kfc;
+    elseif FFtype == FFtypes.OpPoint then
+      Kf_a = dpnom * rhonom / wnom ^ 2 * Kfc;
+    elseif FFtype == FFtypes.Kinetic then
+      Kf_a = K / (2 * A ^ 2) * Kfc;
+    else
+      Kf_a = 0;
+      assert(false, "Unsupported FFtype");
+    end if;
+  equation
+    assert(dpnom > 0, "Please set a positive value for dpnom");
+    assert(rhonom > 0 or FFtype <> FFtypes.OpPoint, "Please set a positive value for rhonom");
+// Fluid properties
+/*
   if not allowFlowReversal then
     state = Medium.setState_phX(inlet.p, inStream(inlet.h_outflow));
   else
@@ -655,25 +519,24 @@
         Medium.setState_phX(outlet.p, inStream(outlet.h_outflow)),
         wnom*wnf);
   end if;
-  */
-    state = Medium.setState_phX(inlet.p, inStream(inlet.h_outflow));
-
-    rho = Medium.density(state) "Fluid density";
-    pin - pout = homotopy(smooth(1, Kf_a*squareReg(w, wnom*wnf))/rho,
-                                 dpnom/wnom*w) "Flow characteristics";
-    inlet.m_flow + outlet.m_flow = 0 "Mass  balance";
-    // Energy balance
-    inlet.h_outflow = inStream(outlet.h_outflow);
-    inStream(inlet.h_outflow) = outlet.h_outflow;
-    //Boundary conditions
-    w = inlet.m_flow;
-    pin = inlet.p;
-    pout = outlet.p;
-    dp = pin - pout;
-      annotation(Dialog(enable = (FFtype == ThermoPower.Choices.PressDrop.FFtypes.Kinetic)),
-                 Dialog(enable = (FFtype == ThermoPower.Choices.PressDrop.FFtypes.Kinetic)),
-      Icon(graphics={Text(extent={{-100,-50},{100,-82}}, textString="%name")}),
-      Documentation(info="<HTML>
+  */
+    state = Medium.setState_phX(inlet.p, inStream(inlet.h_outflow));
+    rho = Medium.density(state) "Fluid density";
+    pin - pout = homotopy(smooth(1, Kf_a * squareReg(w, wnom * wnf)) / rho, dpnom / wnom * w) "Flow characteristics";
+    inlet.m_flow + outlet.m_flow = 0 "Mass  balance";
+// Energy balance
+    inlet.h_outflow = inStream(outlet.h_outflow);
+    inStream(inlet.h_outflow) = outlet.h_outflow;
+//Boundary conditions
+    w = inlet.m_flow;
+    pin = inlet.p;
+    pout = outlet.p;
+    dp = pin - pout;
+    annotation(
+      Dialog(enable = FFtype == ThermoPower.Choices.PressDrop.FFtypes.Kinetic),
+      Dialog(enable = FFtype == ThermoPower.Choices.PressDrop.FFtypes.Kinetic),
+      Icon(graphics = {Text(extent = {{-100, -50}, {100, -82}}, textString = "%name")}),
+      Documentation(info = "<HTML>
 <p>The pressure drop across the inlet and outlet connectors is computed according to a turbulent friction model, i.e. is proportional to the squared velocity of the fluid. The friction coefficient can be specified directly, or by giving an operating point, or as a multiple of the kinetic pressure. In the latter two cases, the correction coefficient <tt>Kfc</tt> can be used to modify the friction coefficient, e.g. to fit some experimental operating point.</p>
 <p>A small linear pressure drop is added to avoid numerical singularities at low or zero flowrate. The <tt>wnom</tt> parameter must be always specified; the additional linear pressure drop is such that it is equal to the turbulent pressure drop when the flowrate is equal to <tt>wnf*wnom</tt> (the default value is 1% of the nominal flowrate).
 <p><b>Modelling options</b></p>
@@ -681,7 +544,7 @@
 <ul><li><tt>FFtype = 0</tt>: the hydraulic friction coefficient <tt>Kf</tt> is set directly.</li>
 <li><tt>FFtype = 1</tt>: the hydraulic friction coefficient is specified by the nominal operating point (<tt>wnom</tt>,<tt>dpnom</tt>, <tt>rhonom</tt>).</li>
 <li><tt>FFtype = 2</tt>: the pressure drop is <tt>K</tt> times the kinetic pressure.</li></ul>
-</HTML>", revisions="<html>
+</HTML>", revisions = "<html>
 <ul>
 <li><i>16 Dec 2004</i>
     by <a href=\"mailto:francesco.casella@polimi.it\">Francesco Casella</a>:<br>
@@ -697,145 +560,121 @@
        First release.</li>
 </ul>
 </html>
-"),   Diagram(graphics));
-  end PressDrop;
-
-  model Header "Header with metal walls for water/steam flows"
-    extends Icons.Water.Header;
-    replaceable package Medium = StandardWater constrainedby
-      Modelica.Media.Interfaces.PartialMedium "Medium model"
-      annotation(choicesAllMatching = true);
-    Medium.ThermodynamicState fluidState "Thermodynamic state of the fluid";
-    parameter SI.Volume V "Inner volume";
-    parameter SI.Area S=0 "Internal surface";
-    parameter SI.Position H=0 "Elevation of outlet over inlet"
-      annotation (Evaluate=true);
-    parameter SI.CoefficientOfHeatTransfer gamma=0 "Heat Transfer Coefficient"
-      annotation (Evaluate=true);
-    parameter SI.HeatCapacity Cm=0 "Metal Heat Capacity" annotation (Evaluate=true);
-    parameter Boolean allowFlowReversal=system.allowFlowReversal
-      "= true to allow flow reversal, false restricts to design direction"
-      annotation(Evaluate=true);
-    outer ThermoPower.System system "System wide properties";
-    parameter Choices.FluidPhase.FluidPhases FluidPhaseStart=Choices.FluidPhase.FluidPhases.Liquid
-      "Fluid phase (only for initialization!)"
-      annotation (Dialog(tab="Initialisation"));
-    parameter Medium.AbsolutePressure pstart "Pressure start value"
-      annotation (Dialog(tab="Initialisation"));
-    parameter Medium.SpecificEnthalpy hstart=if FluidPhaseStart == Choices.FluidPhase.FluidPhases.Liquid
-         then 1e5 else if FluidPhaseStart == Choices.FluidPhase.FluidPhases.Steam
-         then 3e6 else 1e6 "Specific enthalpy start value"
-      annotation (Dialog(tab="Initialisation"));
-    parameter Medium.Temperature Tmstart=300
-      "Metal wall temperature start value"
-      annotation (Dialog(tab="Initialisation"));
-    parameter Choices.Init.Options initOpt=system.initOpt
-      "Initialisation option"
-      annotation (Dialog(tab="Initialisation"));
-    parameter Boolean noInitialPressure=false
-      "Remove initial equation on pressure"
-      annotation (Dialog(tab="Initialisation"),choices(checkBox=true));
-    parameter Boolean noInitialEnthalpy=false
-      "Remove initial equation on enthalpy"
-      annotation (Dialog(tab="Initialisation"),choices(checkBox=true));
-
-    FlangeA inlet(
-      h_outflow(start=hstart),
-      redeclare package Medium = Medium,
-      m_flow(min=if allowFlowReversal then -Modelica.Constants.inf else 0))
-      annotation (Placement(transformation(extent={{-122,-20},{-80,20}},
-            rotation=0)));
-    FlangeB outlet(
-      h_outflow(start=hstart),
-      redeclare package Medium = Medium,
-      m_flow(max=if allowFlowReversal then +Modelica.Constants.inf else 0))
-      annotation (Placement(transformation(extent={{80,-20},{120,20}}, rotation=
-             0)));
-    Medium.AbsolutePressure p(start=pstart, stateSelect=if Medium.singleState then StateSelect.avoid
-           else StateSelect.prefer) "Fluid pressure at the outlet";
-    Medium.SpecificEnthalpy h(start=hstart, stateSelect=StateSelect.prefer)
-      "Fluid specific enthalpy";
-    Medium.SpecificEnthalpy hi "Inlet specific enthalpy";
-    Medium.SpecificEnthalpy ho "Outlet specific enthalpy";
-    SI.Mass M "Fluid mass";
-    SI.Energy E "Fluid energy";
-    Medium.Temperature T "Fluid temperature";
-    Medium.Temperature Tm(start=Tmstart) "Wall temperature";
-    SI.Time Tr "Residence time";
-    Real dM_dt;
-    Real dE_dt;
-    replaceable Thermal.HT thermalPort "Internal surface of metal wall"
-      annotation (Dialog(enable=false), Placement(transformation(extent={{-24,
-              50},{24,64}}, rotation=0)));
-  equation
-    // Set fluid properties
-    fluidState = Medium.setState_phX(p, h);
-    T = Medium.temperature(fluidState);
-
-    M = V*Medium.density(fluidState) "Fluid mass";
-    E = M*h - p*V "Fluid energy";
-    dM_dt = V*(Medium.density_derp_h(fluidState)*der(p) + Medium.density_derh_p(
-      fluidState)*der(h));
-    dE_dt = h*dM_dt + M*der(h) - V*der(p);
-    dM_dt = inlet.m_flow + outlet.m_flow "Fluid mass balance";
-    dE_dt = inlet.m_flow*hi + outlet.m_flow*ho + gamma*S*(Tm - T) + thermalPort.Q_flow
-      "Fluid energy balance";
-    if Cm > 0 and gamma > 0 then
-      Cm*der(Tm) = gamma*S*(T - Tm) "Energy balance of the built-in wall model";
-    else
-      Tm = T "Trivial equation for metal temperature";
-    end if;
-
-    // Boundary conditions
-    hi = homotopy(if not allowFlowReversal then inStream(inlet.h_outflow) else
-      actualStream(inlet.h_outflow), inStream(inlet.h_outflow));
-    ho = homotopy(if not allowFlowReversal then h else actualStream(outlet.h_outflow),
-      h);
-    inlet.h_outflow = h;
-    outlet.h_outflow = h;
-    inlet.p = p + Medium.density(fluidState)*Modelica.Constants.g_n*H;
-    outlet.p = p;
-    thermalPort.T = T;
-
-    Tr = noEvent(M/max(abs(inlet.m_flow), Modelica.Constants.eps))
-      "Residence time";
-  initial equation
-    // Initial conditions
-    if initOpt == Choices.Init.Options.noInit then
-      // do nothing
-    elseif initOpt == Choices.Init.Options.fixedState then
-      if not noInitialPressure then
-        p = pstart;
-      end if;
-      if not noInitialEnthalpy then
-        h = hstart;
-      end if;
-      if (Cm > 0 and gamma > 0) then
-        Tm = Tmstart;
-      end if;
-    elseif initOpt == Choices.Init.Options.steadyState then
-      if not noInitialEnthalpy then
-        der(h) = 0;
-      end if;
-      if (not Medium.singleState and not noInitialPressure) then
-        der(p) = 0;
-      end if;
-      if (Cm > 0 and gamma > 0) then
-        der(Tm) = 0;
-      end if;
-    elseif initOpt == Choices.Init.Options.steadyStateNoP then
-      if not noInitialEnthalpy then
-        der(h) = 0;
-      end if;
-      if (Cm > 0 and gamma > 0) then
-        der(Tm) = 0;
-      end if;
-    else
-      assert(false, "Unsupported initialisation option");
-    end if;
-    annotation (
-      Icon(graphics),
-      Documentation(info="<HTML>
+      "),
+      Diagram(graphics));
+  end PressDrop;
+
+  model Header "Header with metal walls for water/steam flows"
+    extends Icons.Water.Header;
+    replaceable package Medium = StandardWater constrainedby Modelica.Media.Interfaces.PartialMedium "Medium model" annotation(
+       choicesAllMatching = true);
+    Medium.ThermodynamicState fluidState "Thermodynamic state of the fluid";
+    parameter SI.Volume V "Inner volume";
+    parameter SI.Area S = 0 "Internal surface";
+    parameter SI.Position H = 0 "Elevation of outlet over inlet" annotation(
+      Evaluate = true);
+    parameter SI.CoefficientOfHeatTransfer gamma = 0 "Heat Transfer Coefficient" annotation(
+      Evaluate = true);
+    parameter SI.HeatCapacity Cm = 0 "Metal Heat Capacity" annotation(
+      Evaluate = true);
+    parameter Boolean allowFlowReversal = system.allowFlowReversal "= true to allow flow reversal, false restricts to design direction" annotation(
+      Evaluate = true);
+    outer ThermoPower.System system "System wide properties";
+    parameter Choices.FluidPhase.FluidPhases FluidPhaseStart = Choices.FluidPhase.FluidPhases.Liquid "Fluid phase (only for initialization!)" annotation(
+      Dialog(tab = "Initialisation"));
+    parameter Medium.AbsolutePressure pstart "Pressure start value" annotation(
+      Dialog(tab = "Initialisation"));
+    parameter Medium.SpecificEnthalpy hstart = if FluidPhaseStart == Choices.FluidPhase.FluidPhases.Liquid then 1e5 else if FluidPhaseStart == Choices.FluidPhase.FluidPhases.Steam then 3e6 else 1e6 "Specific enthalpy start value" annotation(
+      Dialog(tab = "Initialisation"));
+    parameter Medium.Temperature Tmstart = 300 "Metal wall temperature start value" annotation(
+      Dialog(tab = "Initialisation"));
+    parameter Choices.Init.Options initOpt = system.initOpt "Initialisation option" annotation(
+      Dialog(tab = "Initialisation"));
+    parameter Boolean noInitialPressure = false "Remove initial equation on pressure" annotation(
+      Dialog(tab = "Initialisation"),
+      choices(checkBox = true));
+    parameter Boolean noInitialEnthalpy = false "Remove initial equation on enthalpy" annotation(
+      Dialog(tab = "Initialisation"),
+      choices(checkBox = true));
+    FlangeA inlet(h_outflow(start = hstart), redeclare package Medium = Medium, m_flow(min = if allowFlowReversal then -Modelica.Constants.inf else 0)) annotation(
+      Placement(transformation(extent = {{-122, -20}, {-80, 20}}, rotation = 0)));
+    FlangeB outlet(h_outflow(start = hstart), redeclare package Medium = Medium, m_flow(max = if allowFlowReversal then +Modelica.Constants.inf else 0)) annotation(
+      Placement(transformation(extent = {{80, -20}, {120, 20}}, rotation = 0)));
+    Medium.AbsolutePressure p(start = pstart, stateSelect = if Medium.singleState then StateSelect.avoid else StateSelect.prefer) "Fluid pressure at the outlet";
+    Medium.SpecificEnthalpy h(start = hstart, stateSelect = StateSelect.prefer) "Fluid specific enthalpy";
+    Medium.SpecificEnthalpy hi "Inlet specific enthalpy";
+    Medium.SpecificEnthalpy ho "Outlet specific enthalpy";
+    SI.Mass M "Fluid mass";
+    SI.Energy E "Fluid energy";
+    Medium.Temperature T "Fluid temperature";
+    Medium.Temperature Tm(start = Tmstart) "Wall temperature";
+    SI.Time Tr "Residence time";
+    Real dM_dt;
+    Real dE_dt;
+    replaceable Thermal.HT thermalPort "Internal surface of metal wall" annotation(
+      Dialog(enable = false),
+      Placement(transformation(extent = {{-24, 50}, {24, 64}}, rotation = 0)));
+  equation
+// Set fluid properties
+    fluidState = Medium.setState_phX(p, h);
+    T = Medium.temperature(fluidState);
+    M = V * Medium.density(fluidState) "Fluid mass";
+    E = M * h - p * V "Fluid energy";
+    dM_dt = V * (Medium.density_derp_h(fluidState) * der(p) + Medium.density_derh_p(fluidState) * der(h));
+    dE_dt = h * dM_dt + M * der(h) - V * der(p);
+    dM_dt = inlet.m_flow + outlet.m_flow "Fluid mass balance";
+    dE_dt = inlet.m_flow * hi + outlet.m_flow * ho + gamma * S * (Tm - T) + thermalPort.Q_flow "Fluid energy balance";
+    if Cm > 0 and gamma > 0 then
+      Cm * der(Tm) = gamma * S * (T - Tm) "Energy balance of the built-in wall model";
+    else
+      Tm = T "Trivial equation for metal temperature";
+    end if;
+// Boundary conditions
+    hi = homotopy(if not allowFlowReversal then inStream(inlet.h_outflow) else actualStream(inlet.h_outflow), inStream(inlet.h_outflow));
+    ho = homotopy(if not allowFlowReversal then h else actualStream(outlet.h_outflow), h);
+    inlet.h_outflow = h;
+    outlet.h_outflow = h;
+    inlet.p = p + Medium.density(fluidState) * Modelica.Constants.g_n * H;
+    outlet.p = p;
+    thermalPort.T = T;
+    Tr = noEvent(M / max(abs(inlet.m_flow), Modelica.Constants.eps)) "Residence time";
+  initial equation
+// Initial conditions
+    if initOpt == Choices.Init.Options.noInit then
+// do nothing
+    elseif initOpt == Choices.Init.Options.fixedState then
+      if not noInitialPressure then
+        p = pstart;
+      end if;
+      if not noInitialEnthalpy then
+        h = hstart;
+      end if;
+      if Cm > 0 and gamma > 0 then
+        Tm = Tmstart;
+      end if;
+    elseif initOpt == Choices.Init.Options.steadyState then
+      if not noInitialEnthalpy then
+        der(h) = 0;
+      end if;
+      if not Medium.singleState and not noInitialPressure then
+        der(p) = 0;
+      end if;
+      if Cm > 0 and gamma > 0 then
+        der(Tm) = 0;
+      end if;
+    elseif initOpt == Choices.Init.Options.steadyStateNoP then
+      if not noInitialEnthalpy then
+        der(h) = 0;
+      end if;
+      if Cm > 0 and gamma > 0 then
+        der(Tm) = 0;
+      end if;
+    else
+      assert(false, "Unsupported initialisation option");
+    end if;
+    annotation(
+      Icon(graphics),
+      Documentation(info = "<HTML>
 <p>This model describes a constant volume header with metal walls. The fluid can be water, steam, or a two-phase mixture.
 <p>It is possible to take into account the heat storage and transfer in the metal wall in two ways:
 <ul>
@@ -854,7 +693,7 @@
 </li>
 </ul>
 <p>The model can represent an actual header when connected to the model of a bank of tubes (e.g., <tt>Flow1D</tt> with <tt>Nt>1</tt>).</p>
-</HTML>", revisions="<html>
+</HTML>", revisions = "<html>
 <ul>
 <li><i>30 May 2005</i>
     by <a href=\"mailto:francesco.casella@polimi.it\">Francesco Casella</a>:<br>
@@ -879,155 +718,124 @@
        First release.</li>
 </ul>
 </html>
-"),   Diagram(graphics));
-  end Header;
-
-  model Mixer "Mixer with metal walls for water/steam flows"
-    extends Icons.Water.Mixer;
-    replaceable package Medium = StandardWater constrainedby
-      Modelica.Media.Interfaces.PartialMedium "Medium model"
-      annotation(choicesAllMatching = true);
-    Medium.ThermodynamicState fluidState "Thermodynamic state of the fluid";
-    parameter SI.Volume V "Internal volume";
-    parameter SI.Area S=0 "Internal surface";
-    parameter SI.CoefficientOfHeatTransfer gamma=0
-      "Internal Heat Transfer Coefficient" annotation (Evaluate=true);
-    parameter SI.HeatCapacity Cm=0 "Metal Heat Capacity" annotation (Evaluate=true);
-    parameter Boolean allowFlowReversal=system.allowFlowReversal
-      "= true to allow flow reversal, false restricts to design direction"
-      annotation(Evaluate=true);
-    outer ThermoPower.System system "System wide properties";
-    parameter Choices.FluidPhase.FluidPhases FluidPhaseStart=Choices.FluidPhase.FluidPhases.Liquid
-      "Fluid phase (only for initialization!)"
-      annotation (Dialog(tab="Initialisation"));
-    parameter Medium.AbsolutePressure pstart "Pressure start value"
-      annotation (Dialog(tab="Initialisation"));
-    parameter Medium.SpecificEnthalpy hstart=if FluidPhaseStart == Choices.FluidPhase.FluidPhases.Liquid
-         then 1e5 else if FluidPhaseStart == Choices.FluidPhase.FluidPhases.Steam
-         then 3e6 else 1e6 "Specific enthalpy start value"
-      annotation (Dialog(tab="Initialisation"));
-    parameter Medium.Temperature Tmstart=300
-      "Metal wall temperature start value"
-      annotation (Dialog(tab="Initialisation"));
-    parameter Choices.Init.Options initOpt=system.initOpt
-      "Initialisation option"
-      annotation (Dialog(tab="Initialisation"));
-    parameter Boolean noInitialPressure=false
-      "Remove initial equation on pressure"
-      annotation (Dialog(tab="Initialisation"),choices(checkBox=true));
-    parameter Boolean noInitialEnthalpy=false
-      "Remove initial equation on enthalpy"
-      annotation (Dialog(tab="Initialisation"),choices(checkBox=true));
-
-    FlangeA in1(
-      h_outflow(start=hstart),
-      redeclare package Medium = Medium,
-      m_flow(min=if allowFlowReversal then -Modelica.Constants.inf else 0))
-      annotation (Placement(transformation(extent={{-100,40},{-60,80}},
-            rotation=0)));
-    FlangeA in2(
-      h_outflow(start=hstart),
-      redeclare package Medium = Medium,
-      m_flow(min=if allowFlowReversal then -Modelica.Constants.inf else 0))
-      annotation (Placement(transformation(extent={{-100,-80},{-60,-40}},
-            rotation=0)));
-    FlangeB out(
-      h_outflow(start=hstart),
-      redeclare package Medium = Medium,
-      m_flow(max=if allowFlowReversal then +Modelica.Constants.inf else 0))
-      annotation (Placement(transformation(extent={{80,-20},{120,20}}, rotation=
-             0)));
-    Medium.AbsolutePressure p(start=pstart, stateSelect=if Medium.singleState then StateSelect.avoid
-           else StateSelect.prefer) "Fluid pressure";
-    Medium.SpecificEnthalpy h(start=hstart, stateSelect=StateSelect.prefer)
-      "Fluid specific enthalpy";
-    Medium.SpecificEnthalpy hi1 "Inlet 1 specific enthalpy";
-    Medium.SpecificEnthalpy hi2 "Inlet 2 specific enthalpy";
-    Medium.SpecificEnthalpy ho "Outlet specific enthalpy";
-    SI.Mass M "Fluid mass";
-    SI.Energy E "Fluid energy";
-    SI.HeatFlowRate Q "Heat flow rate exchanged with the outside";
-    Medium.Temperature T "Fluid temperature";
-    Medium.Temperature Tm(start=Tmstart) "Wall temperature";
-    SI.Time Tr "Residence time";
-    replaceable Thermal.HT thermalPort "Internal surface of metal wall"
-      annotation (Placement(transformation(extent={{-24,66},{24,80}}, rotation=
-              0)));
-  equation
-    // Set fluid properties
-    fluidState = Medium.setState_phX(p, h);
-    T = Medium.temperature(fluidState);
-
-    M = V*Medium.density(fluidState) "Fluid mass";
-    E = M*Medium.specificInternalEnergy(fluidState) "Fluid energy";
-    der(M) = in1.m_flow + in2.m_flow + out.m_flow "Fluid mass balance";
-    der(E) = in1.m_flow*hi1 + in2.m_flow*hi2 + out.m_flow*ho - gamma*S*(T - Tm)
-       + Q "Fluid energy balance";
-    if Cm > 0 and gamma > 0 then
-      Cm*der(Tm) = gamma*S*(T - Tm) "Metal wall energy balance";
-    else
-      Tm = T;
-    end if;
-
-    // Boundary conditions
-    hi1 = homotopy(if not allowFlowReversal then inStream(in1.h_outflow) else
-      actualStream(in1.h_outflow), inStream(in1.h_outflow));
-    hi2 = homotopy(if not allowFlowReversal then inStream(in2.h_outflow) else
-      actualStream(in2.h_outflow), inStream(in2.h_outflow));
-    ho = homotopy(if not allowFlowReversal then h else actualStream(out.h_outflow),
-      h);
-    in1.h_outflow = h;
-    in2.h_outflow = h;
-    out.h_outflow = h;
-    in1.p = p;
-    in2.p = p;
-    out.p = p;
-    thermalPort.Q_flow = Q;
-    thermalPort.T = T;
-
-    Tr = noEvent(M/max(abs(out.m_flow), Modelica.Constants.eps))
-      "Residence time";
-
-  initial equation
-    // Initial conditions
-    if initOpt == Choices.Init.Options.noInit then
-      // do nothing
-    elseif initOpt == Choices.Init.Options.fixedState then
-      if not noInitialPressure then
-        p = pstart;
-      end if;
-      if not noInitialEnthalpy then
-        h = hstart;
-      end if;
-      if (Cm > 0 and gamma > 0) then
-        Tm = Tmstart;
-      end if;
-    elseif initOpt == Choices.Init.Options.steadyState then
-      if not noInitialEnthalpy then
-        der(h) = 0;
-      end if;
-      if (not Medium.singleState and not noInitialPressure) then
-        der(p) = 0;
-      end if;
-      if (Cm > 0 and gamma > 0) then
-        der(Tm) = 0;
-      end if;
-    elseif initOpt == Choices.Init.Options.steadyStateNoP then
-      if not noInitialEnthalpy then
-        der(h) = 0;
-      end if;
-      if (Cm > 0 and gamma > 0) then
-        der(Tm) = 0;
-      end if;
-    else
-      assert(false, "Unsupported initialisation option");
-    end if;
-
-    annotation (
-      Placement(transformation(extent={{80,-20},{120,20}}, rotation=0)),
-      Documentation(info="<HTML>
+      "),
+      Diagram(graphics));
+  end Header;
+
+  model Mixer "Mixer with metal walls for water/steam flows"
+    extends Icons.Water.Mixer;
+    replaceable package Medium = StandardWater constrainedby Modelica.Media.Interfaces.PartialMedium "Medium model" annotation(
+       choicesAllMatching = true);
+    Medium.ThermodynamicState fluidState "Thermodynamic state of the fluid";
+    parameter SI.Volume V "Internal volume";
+    parameter SI.Area S = 0 "Internal surface";
+    parameter SI.CoefficientOfHeatTransfer gamma = 0 "Internal Heat Transfer Coefficient" annotation(
+      Evaluate = true);
+    parameter SI.HeatCapacity Cm = 0 "Metal Heat Capacity" annotation(
+      Evaluate = true);
+    parameter Boolean allowFlowReversal = system.allowFlowReversal "= true to allow flow reversal, false restricts to design direction" annotation(
+      Evaluate = true);
+    outer ThermoPower.System system "System wide properties";
+    parameter Choices.FluidPhase.FluidPhases FluidPhaseStart = Choices.FluidPhase.FluidPhases.Liquid "Fluid phase (only for initialization!)" annotation(
+      Dialog(tab = "Initialisation"));
+    parameter Medium.AbsolutePressure pstart "Pressure start value" annotation(
+      Dialog(tab = "Initialisation"));
+    parameter Medium.SpecificEnthalpy hstart = if FluidPhaseStart == Choices.FluidPhase.FluidPhases.Liquid then 1e5 else if FluidPhaseStart == Choices.FluidPhase.FluidPhases.Steam then 3e6 else 1e6 "Specific enthalpy start value" annotation(
+      Dialog(tab = "Initialisation"));
+    parameter Medium.Temperature Tmstart = 300 "Metal wall temperature start value" annotation(
+      Dialog(tab = "Initialisation"));
+    parameter Choices.Init.Options initOpt = system.initOpt "Initialisation option" annotation(
+      Dialog(tab = "Initialisation"));
+    parameter Boolean noInitialPressure = false "Remove initial equation on pressure" annotation(
+      Dialog(tab = "Initialisation"),
+      choices(checkBox = true));
+    parameter Boolean noInitialEnthalpy = false "Remove initial equation on enthalpy" annotation(
+      Dialog(tab = "Initialisation"),
+      choices(checkBox = true));
+    FlangeA in1(h_outflow(start = hstart), redeclare package Medium = Medium, m_flow(min = if allowFlowReversal then -Modelica.Constants.inf else 0)) annotation(
+      Placement(transformation(extent = {{-100, 40}, {-60, 80}}, rotation = 0)));
+    FlangeA in2(h_outflow(start = hstart), redeclare package Medium = Medium, m_flow(min = if allowFlowReversal then -Modelica.Constants.inf else 0)) annotation(
+      Placement(transformation(extent = {{-100, -80}, {-60, -40}}, rotation = 0)));
+    FlangeB out(h_outflow(start = hstart), redeclare package Medium = Medium, m_flow(max = if allowFlowReversal then +Modelica.Constants.inf else 0)) annotation(
+      Placement(transformation(extent = {{80, -20}, {120, 20}}, rotation = 0)));
+    Medium.AbsolutePressure p(start = pstart, stateSelect = if Medium.singleState then StateSelect.avoid else StateSelect.prefer) "Fluid pressure";
+    Medium.SpecificEnthalpy h(start = hstart, stateSelect = StateSelect.prefer) "Fluid specific enthalpy";
+    Medium.SpecificEnthalpy hi1 "Inlet 1 specific enthalpy";
+    Medium.SpecificEnthalpy hi2 "Inlet 2 specific enthalpy";
+    Medium.SpecificEnthalpy ho "Outlet specific enthalpy";
+    SI.Mass M "Fluid mass";
+    SI.Energy E "Fluid energy";
+    SI.HeatFlowRate Q "Heat flow rate exchanged with the outside";
+    Medium.Temperature T "Fluid temperature";
+    Medium.Temperature Tm(start = Tmstart) "Wall temperature";
+    SI.Time Tr "Residence time";
+    replaceable Thermal.HT thermalPort "Internal surface of metal wall" annotation(
+      Placement(transformation(extent = {{-24, 66}, {24, 80}}, rotation = 0)));
+  equation
+// Set fluid properties
+    fluidState = Medium.setState_phX(p, h);
+    T = Medium.temperature(fluidState);
+    M = V * Medium.density(fluidState) "Fluid mass";
+    E = M * Medium.specificInternalEnergy(fluidState) "Fluid energy";
+    der(M) = in1.m_flow + in2.m_flow + out.m_flow "Fluid mass balance";
+    der(E) = in1.m_flow * hi1 + in2.m_flow * hi2 + out.m_flow * ho - gamma * S * (T - Tm) + Q "Fluid energy balance";
+    if Cm > 0 and gamma > 0 then
+      Cm * der(Tm) = gamma * S * (T - Tm) "Metal wall energy balance";
+    else
+      Tm = T;
+    end if;
+// Boundary conditions
+    hi1 = homotopy(if not allowFlowReversal then inStream(in1.h_outflow) else actualStream(in1.h_outflow), inStream(in1.h_outflow));
+    hi2 = homotopy(if not allowFlowReversal then inStream(in2.h_outflow) else actualStream(in2.h_outflow), inStream(in2.h_outflow));
+    ho = homotopy(if not allowFlowReversal then h else actualStream(out.h_outflow), h);
+    in1.h_outflow = h;
+    in2.h_outflow = h;
+    out.h_outflow = h;
+    in1.p = p;
+    in2.p = p;
+    out.p = p;
+    thermalPort.Q_flow = Q;
+    thermalPort.T = T;
+    Tr = noEvent(M / max(abs(out.m_flow), Modelica.Constants.eps)) "Residence time";
+  initial equation
+// Initial conditions
+    if initOpt == Choices.Init.Options.noInit then
+// do nothing
+    elseif initOpt == Choices.Init.Options.fixedState then
+      if not noInitialPressure then
+        p = pstart;
+      end if;
+      if not noInitialEnthalpy then
+        h = hstart;
+      end if;
+      if Cm > 0 and gamma > 0 then
+        Tm = Tmstart;
+      end if;
+    elseif initOpt == Choices.Init.Options.steadyState then
+      if not noInitialEnthalpy then
+        der(h) = 0;
+      end if;
+      if not Medium.singleState and not noInitialPressure then
+        der(p) = 0;
+      end if;
+      if Cm > 0 and gamma > 0 then
+        der(Tm) = 0;
+      end if;
+    elseif initOpt == Choices.Init.Options.steadyStateNoP then
+      if not noInitialEnthalpy then
+        der(h) = 0;
+      end if;
+      if Cm > 0 and gamma > 0 then
+        der(Tm) = 0;
+      end if;
+    else
+      assert(false, "Unsupported initialisation option");
+    end if;
+    annotation(
+      Placement(transformation(extent = {{80, -20}, {120, 20}}, rotation = 0)),
+      Documentation(info = "<HTML>
 <p>This model describes a constant volume mixer with metal walls. The fluid can be water, steam, or a two-phase mixture. The metal wall temperature and the heat transfer coefficient between the wall and the fluid are uniform. The wall is thermally insulated from the outside.
-</HTML>", revisions="<html>
+</HTML>", revisions = "<html>
 <ul>
 <li><i>23 May 2008</i>
     by <a>Luca Savoldelli</a>:<br>
@@ -1045,102 +853,88 @@
     by <a href=\"mailto:francesco.casella@polimi.it\">Francesco Casella</a>:<br>
        First release.</li>
 </ul>
-</html>"),
-      Icon(graphics),
-      Diagram(graphics));
-  end Mixer;
-
-  model Tank "Open tank with free surface"
-    extends Icons.Water.Tank;
-    replaceable package Medium = StandardWater constrainedby
-      Modelica.Media.Interfaces.PartialMedium "Medium model"
-      annotation(choicesAllMatching = true);
-    Medium.ThermodynamicState liquidState
-      "Thermodynamic state of the liquid";
-    parameter SI.Area A "Cross-sectional area";
-    parameter SI.Volume V0=0 "Volume at zero level";
-    parameter SI.Height y0 = 0 "Height of zero level over inlet and outlet flanges";
-    parameter Boolean allowFlowReversal=system.allowFlowReversal
-      "= true to allow flow reversal, false restricts to design direction"
-      annotation(Evaluate=true);
-    outer ThermoPower.System system "System wide properties";
-    parameter SI.Length ystart "Start level"
-      annotation (Dialog(tab="Initialisation"));
-    parameter Medium.SpecificEnthalpy hstart=1e5
-      annotation (Dialog(tab="Initialisation"));
-    SI.Length y(start=ystart, stateSelect=StateSelect.prefer) "Level";
-    SI.Volume V "Liquid volume";
-    SI.Mass M "Liquid mass";
-    SI.Enthalpy H "Liquid (total) enthalpy";
-    Medium.SpecificEnthalpy h(start=hstart, stateSelect=StateSelect.prefer)
-      "Liquid specific enthalpy";
-    Medium.SpecificEnthalpy hin "Inlet specific enthalpy";
-    Medium.SpecificEnthalpy htop "Top inlet specific enthalpy";
-    Medium.SpecificEnthalpy hout "Outlet specific enthalpy";
-    Medium.AbsolutePressure p(start=system.p_amb) "Bottom pressure";
-    constant SI.Acceleration g=Modelica.Constants.g_n;
-    FlangeA inlet(redeclare package Medium = Medium, m_flow(min=if
-            allowFlowReversal then -Modelica.Constants.inf else 0)) annotation (
-       Placement(transformation(extent={{-100,-80},{-60,-40}}, rotation=0)));
-    FlangeA inletTop(redeclare package Medium = Medium, m_flow(min=0)) annotation (
-       Placement(transformation(extent={{-100,-80},{-60,-40}}, rotation=0),
-          iconTransformation(extent={{-20,60},{20,100}})));
-    FlangeB outlet(redeclare package Medium = Medium, m_flow(max=if
-            allowFlowReversal then +Modelica.Constants.inf else 0)) annotation (
-       Placement(transformation(extent={{60,-80},{100,-40}}, rotation=0)));
-    parameter Choices.Init.Options initOpt=system.initOpt
-      "Initialisation option"
-      annotation (Dialog(tab="Initialisation"));
-    parameter Boolean noInitialPressure=false
-      "Remove initial equation on pressure"
-      annotation (Dialog(tab="Initialisation"),choices(checkBox=true));
-  equation
-    // Set liquid properties
-    liquidState = Medium.setState_phX(system.p_amb, h);
-
-    V = V0 + A*y "Liquid volume";
-    M = V*Medium.density(liquidState) "Liquid mass";
-    H = M*Medium.specificInternalEnergy(liquidState) "Liquid enthalpy";
-    der(M) = inlet.m_flow + inletTop.m_flow + outlet.m_flow "Mass balance";
-    der(H) = inlet.m_flow*hin + inletTop.m_flow*htop + outlet.m_flow*hout "Energy balance";
-    p - system.p_amb = Medium.density(liquidState)*g*(y+y0) "Stevin's law";
-
-    // Boundary conditions
-    hin = homotopy(if not allowFlowReversal then inStream(inlet.h_outflow)
-                     else actualStream(inlet.h_outflow), inStream(inlet.h_outflow));
-    htop = inStream(inletTop.h_outflow);
-    hout = homotopy(if not allowFlowReversal then h else actualStream(outlet.h_outflow),
-      h);
-    inlet.h_outflow = h;
-    inletTop.h_outflow = h "dummy, not used";
-    outlet.h_outflow = h;
-    inlet.p = p;
-    inletTop.p = system.p_amb;
-    outlet.p = p;
-  initial equation
-    if initOpt == Choices.Init.Options.noInit then
-      // do nothing
-    elseif initOpt == Choices.Init.Options.fixedState then
-      if not noInitialPressure then
-        y = ystart;
-      end if;
-      h = hstart;
-    elseif initOpt == Choices.Init.Options.steadyState then
-      if not noInitialPressure then
-        der(y) = 0;
-      end if;
-      der(h) = 0;
-    else
-      assert(false, "Unsupported initialisation option");
-    end if;
-
-    annotation (
-      Icon(graphics={Text(extent={{-100,-90},{100,-116}},
-                                                       textString="%name")}),
-      Documentation(info="<html>
+</html>"),
+      Icon(graphics),
+      Diagram(graphics));
+  end Mixer;
+
+  model Tank "Open tank with free surface"
+    extends Icons.Water.Tank;
+    replaceable package Medium = StandardWater constrainedby Modelica.Media.Interfaces.PartialMedium "Medium model" annotation(
+       choicesAllMatching = true);
+    Medium.ThermodynamicState liquidState "Thermodynamic state of the liquid";
+    parameter SI.Area A "Cross-sectional area";
+    parameter SI.Volume V0 = 0 "Volume at zero level";
+    parameter SI.Height y0 = 0 "Height of zero level over inlet and outlet flanges";
+    parameter Boolean allowFlowReversal = system.allowFlowReversal "= true to allow flow reversal, false restricts to design direction" annotation(
+      Evaluate = true);
+    outer ThermoPower.System system "System wide properties";
+    parameter SI.Length ystart "Start level" annotation(
+      Dialog(tab = "Initialisation"));
+    parameter Medium.SpecificEnthalpy hstart = 1e5 annotation(
+      Dialog(tab = "Initialisation"));
+    SI.Length y(start = ystart, stateSelect = StateSelect.prefer) "Level";
+    SI.Volume V "Liquid volume";
+    SI.Mass M "Liquid mass";
+    SI.Enthalpy H "Liquid (total) enthalpy";
+    Medium.SpecificEnthalpy h(start = hstart, stateSelect = StateSelect.prefer) "Liquid specific enthalpy";
+    Medium.SpecificEnthalpy hin "Inlet specific enthalpy";
+    Medium.SpecificEnthalpy htop "Top inlet specific enthalpy";
+    Medium.SpecificEnthalpy hout "Outlet specific enthalpy";
+    Medium.AbsolutePressure p(start = system.p_amb) "Bottom pressure";
+    constant SI.Acceleration g = Modelica.Constants.g_n;
+    FlangeA inlet(redeclare package Medium = Medium, m_flow(min = if allowFlowReversal then -Modelica.Constants.inf else 0)) annotation(
+      Placement(transformation(extent = {{-100, -80}, {-60, -40}}, rotation = 0)));
+    FlangeA inletTop(redeclare package Medium = Medium, m_flow(min = 0)) annotation(
+      Placement(transformation(extent = {{-100, -80}, {-60, -40}}, rotation = 0), iconTransformation(extent = {{-20, 60}, {20, 100}})));
+    FlangeB outlet(redeclare package Medium = Medium, m_flow(max = if allowFlowReversal then +Modelica.Constants.inf else 0)) annotation(
+      Placement(transformation(extent = {{60, -80}, {100, -40}}, rotation = 0)));
+    parameter Choices.Init.Options initOpt = system.initOpt "Initialisation option" annotation(
+      Dialog(tab = "Initialisation"));
+    parameter Boolean noInitialPressure = false "Remove initial equation on pressure" annotation(
+      Dialog(tab = "Initialisation"),
+      choices(checkBox = true));
+  equation
+// Set liquid properties
+    liquidState = Medium.setState_phX(system.p_amb, h);
+    V = V0 + A * y "Liquid volume";
+    M = V * Medium.density(liquidState) "Liquid mass";
+    H = M * Medium.specificInternalEnergy(liquidState) "Liquid enthalpy";
+    der(M) = inlet.m_flow + inletTop.m_flow + outlet.m_flow "Mass balance";
+    der(H) = inlet.m_flow * hin + inletTop.m_flow * htop + outlet.m_flow * hout "Energy balance";
+    p - system.p_amb = Medium.density(liquidState) * g * (y + y0) "Stevin's law";
+// Boundary conditions
+    hin = homotopy(if not allowFlowReversal then inStream(inlet.h_outflow) else actualStream(inlet.h_outflow), inStream(inlet.h_outflow));
+    htop = inStream(inletTop.h_outflow);
+    hout = homotopy(if not allowFlowReversal then h else actualStream(outlet.h_outflow), h);
+    inlet.h_outflow = h;
+    inletTop.h_outflow = h "dummy, not used";
+    outlet.h_outflow = h;
+    inlet.p = p;
+    inletTop.p = system.p_amb;
+    outlet.p = p;
+  initial equation
+    if initOpt == Choices.Init.Options.noInit then
+// do nothing
+    elseif initOpt == Choices.Init.Options.fixedState then
+      if not noInitialPressure then
+        y = ystart;
+      end if;
+      h = hstart;
+    elseif initOpt == Choices.Init.Options.steadyState then
+      if not noInitialPressure then
+        der(y) = 0;
+      end if;
+      der(h) = 0;
+    else
+      assert(false, "Unsupported initialisation option");
+    end if;
+    annotation(
+      Icon(graphics = {Text(extent = {{-100, -90}, {100, -116}}, textString = "%name")}),
+      Documentation(info = "<html>
 <p>This model describes a simple free-surface cylindrical water tank. The model is based on mass and energy balances, assuming that no heat transfer takes place except through the inlet and outlet flows. </p>
 <p>The pressure at the inlet and outlet ports is the ambient pressure plus the static head due to the level, while the pressure at the inletTop port is the ambient pressure.</p>
-</html>", revisions="<html>
+</html>", revisions = "<html>
 <ul>
 <li><i>29 Jul 2017</i> by <a href=\"mailto:francesco.casella@polimi.it\">Francesco Casella</a>:<br>Added inletTop port.</li>
 <li><i>30 May 2005</i> by <a href=\"mailto:francesco.casella@polimi.it\">Francesco Casella</a>:<br>Initialisation support added.</li>
@@ -1148,233 +942,179 @@
 <li><i>22 Jun 2004</i> by <a href=\"mailto:francesco.casella@polimi.it\">Francesco Casella</a>:<br>Improved equations and adapted to Modelica.Media. </li>
 <li><i>1 Oct 2003</i> by <a href=\"mailto:francesco.casella@polimi.it\">Francesco Casella</a>:<br>First release.</li>
 </ul>
-</html>"),
-      Diagram(graphics));
-  end Tank;
-
-  model Flow1DFV
-    "1-dimensional fluid flow model for water/steam (finite volumes)"
-    extends BaseClasses.Flow1DBase;
-    import ThermoPower.Choices.Flow1D.FFtypes;
-    import ThermoPower.Choices.Flow1D.HCtypes;
-
-    parameter SI.PerUnit wnm = 1e-3 "Maximum fraction of the nominal flow rate allowed as reverse flow";
-    parameter Boolean fixedMassFlowSimplified = false "Fix flow rate = wnom for simplified homotopy model"
-        annotation (Dialog(tab="Initialisation"));
-
-    Medium.ThermodynamicState fluidState[N]
-      "Thermodynamic state of the fluid at the nodes";
-    SI.Length omega_hyd "Wet perimeter (single tube)";
-    SI.Pressure Dpfric "Pressure drop due to friction (total)";
-    SI.Pressure Dpfric1
-      "Pressure drop due to friction (from inlet to capacitance)";
-    SI.Pressure Dpfric2
-      "Pressure drop due to friction (from capacitance to outlet)";
-    SI.Pressure Dpstat "Pressure drop due to static head";
-    Medium.MassFlowRate win "Flow rate at the inlet (single tube)";
-    Medium.MassFlowRate wout "Flow rate at the outlet (single tube)";
-    Real Kf "Hydraulic friction coefficient";
-    Real dwdt "Dynamic momentum term";
-    SI.PerUnit Cf "Fanning friction factor";
-    Medium.AbsolutePressure p(start=pstart,stateSelect=StateSelect.prefer)
-      "Fluid pressure for property calculations";
-    Medium.MassFlowRate w(start=wnom/Nt) "Mass flow rate (single tube)";
-    Medium.MassFlowRate wbar[N - 1](each start=wnom/Nt)
-      "Average flow rate through volumes (single tube)";
-    SI.Power Q_single[N-1] = heatTransfer.Qvol/Nt
-      "Heat flows entering the volumes from the lateral boundary (single tube)";
-  //   MassFlowRate wstar[N];
-    SI.Velocity u[N] "Fluid velocity";
-    Medium.Temperature T[N] "Fluid temperature";
-    Medium.SpecificEnthalpy h[N](start=hstart)
-      "Fluid specific enthalpy at the nodes";
-    Medium.SpecificEnthalpy htilde[N - 1](start=hstart[2:N],each stateSelect=StateSelect.prefer)
-      "Enthalpy state variables";
-    Medium.Density rho[N] "Fluid nodal density";
-    SI.Mass M "Fluid mass (single tube)";
-    SI.Mass Mtot "Fluid mass (total)";
-    SI.MassFlowRate dMdt[N - 1]
-      "Time derivative of mass in each cell between two nodes";
-    replaceable model HeatTransfer = Thermal.HeatTransferFV.IdealHeatTransfer
-      constrainedby ThermoPower.Thermal.BaseClasses.DistributedHeatTransferFV
-      annotation (choicesAllMatching=true);
-    HeatTransfer heatTransfer(
-      redeclare package Medium = Medium,
-      final Nf=N,
-      final Nw=Nw,
-      final Nt=Nt,
-      final L=L,
-      final A=A,
-      final Dhyd=Dhyd,
-      final omega=omega,
-      final wnom=wnom/Nt,
-      final w=w*ones(N),
-      final fluidState=fluidState) "Instantiated heat transfer model";
-
-    ThermoPower.Thermal.DHTVolumes wall(final N=Nw)
-      annotation (Placement(transformation(extent={{-40,40},{40,60}},
-            rotation=0)));
-  protected
-    Medium.Density rhobar[N - 1] "Fluid average density";
-    SI.SpecificVolume vbar[N - 1] "Fluid average specific volume";
-    //HeatFlux phibar[N - 1] "Average heat flux";
-    SI.DerDensityByEnthalpy drdh[N] "Derivative of density by enthalpy";
-    SI.DerDensityByEnthalpy drbdh[N - 1]
-      "Derivative of average density by enthalpy";
-    SI.DerDensityByPressure drdp[N] "Derivative of density by pressure";
-    SI.DerDensityByPressure drbdp[N - 1]
-      "Derivative of average density by pressure";
-  equation
-    //All equations are referred to a single tube
-    // Friction factor selection
-    omega_hyd = 4*A/Dhyd;
-    if FFtype == FFtypes.Kfnom then
-      Kf = Kfnom*Kfc;
-    elseif FFtype == FFtypes.OpPoint then
-      Kf = dpnom*rhonom/(wnom/Nt)^2*Kfc;
-    elseif FFtype == FFtypes.Cfnom then
-      Cf = Cfnom*Kfc;
-    elseif FFtype == FFtypes.Colebrook then
-      Cf = f_colebrook(
-          w,
-          Dhyd/A,
-          e,
-          Medium.dynamicViscosity(fluidState[integer(N/2)]))*Kfc;
-    else  // if FFtype == FFtypes.NoFriction then
-      Cf = 0;
-    end if;
-    Kf = Cf*omega_hyd*L/(2*A^3)
-      "Relationship between friction coefficient and Fanning friction factor";
-    assert(Kf >= 0, "Negative friction coefficient");
-
-    // Dynamic momentum term
-    if DynamicMomentum then
-      dwdt = der(w);
-    else
-      dwdt = 0;
-    end if;
-
-    sum(dMdt) = (infl.m_flow + outfl.m_flow)/Nt "Mass balance";
-    L/A*dwdt + (outfl.p - infl.p) + Dpstat + Dpfric = 0 "Momentum balance";
-    Dpfric = Dpfric1 + Dpfric2 "Total pressure drop due to friction";
-    if FFtype == FFtypes.NoFriction then
-      Dpfric1 = 0;
-      Dpfric2 = 0;
-    elseif HydraulicCapacitance == HCtypes.Middle then
-      //assert((N-1)-integer((N-1)/2)*2 == 0, "N must be odd");
-      Dpfric1 = homotopy(Kf*squareReg(win, wnom/Nt*wnf)*sum(vbar[1:integer((N
-         - 1)/2)])/(N - 1), dpnom/2/(wnom/Nt)*win)
-        "Pressure drop from inlet to capacitance";
-      Dpfric2 = homotopy(Kf*squareReg(wout, wnom/Nt*wnf)*sum(vbar[1 + integer((
-        N - 1)/2):N - 1])/(N - 1), dpnom/2/(wnom/Nt)*wout)
-        "Pressure drop from capacitance to outlet";
-    elseif HydraulicCapacitance == HCtypes.Upstream then
-      Dpfric1 = 0 "Pressure drop from inlet to capacitance";
-      Dpfric2 = homotopy(Kf*squareReg(wout, wnom/Nt*wnf)*sum(vbar)/(N - 1),
-                         dpnom/(wnom/Nt)*wout)
-        "Pressure drop from capacitance to outlet";
-    else // if HydraulicCapacitance == HCtypes.Downstream then
-      Dpfric1 = homotopy(Kf*squareReg(win, wnom/Nt*wnf)*sum(vbar)/(N - 1),
-                         dpnom/(wnom/Nt)*win)
-        "Pressure drop from inlet to capacitance";
-      Dpfric2 = 0 "Pressure drop from capacitance to outlet";
-    end if "Pressure drop due to friction";
-    Dpstat = if abs(dzdx) < 1e-6 then 0 else g*l*dzdx*sum(rhobar)
-      "Pressure drop due to static head";
-    for j in 1:N-1 loop
-      if Medium.singleState then
-        A*l*rhobar[j]*der(htilde[j]) + wbar[j]*(h[j + 1] - h[j]) = Q_single[j]
-          "Energy balance (pressure effects neglected)";
-          //Qvol = l*omega*phibar[j]
-      else
-        A*l*rhobar[j]*der(htilde[j]) + wbar[j]*(h[j + 1] - h[j]) - A*l*der(p) =
-          Q_single[j] "Energy balance";  //Qvol = l*omega*phibar[j]
-      end if;
-      dMdt[j] = A*l*(drbdh[j]*der(htilde[j]) + drbdp[j]*der(p))
-        "Mass derivative for each volume";
-      // Average volume quantities
-      rhobar[j] = (rho[j] + rho[j + 1])/2;
-      drbdp[j] = (drdp[j] + drdp[j + 1])/2;
-      drbdh[j] = (drdh[j] + drdh[j + 1])/2;
-      vbar[j] = 1/rhobar[j];
-      if fixedMassFlowSimplified then
-        wbar[j] = homotopy(infl.m_flow/Nt - sum(dMdt[1:j - 1]) - dMdt[j]/2, wnom/Nt);
-      else
-        wbar[j] = infl.m_flow/Nt - sum(dMdt[1:j - 1]) - dMdt[j]/2;
-      end if;
-    end for;
-
-    // for j in 1:N loop
-    //   wstar[j] = homotopy(infl.m_flow/Nt - sum(dMdt[1:j - 1]) - dMdt[j]/2, wnom/Nt);
-    // end for;
-
-    // Fluid property calculations
-    for j in 1:N loop
-      fluidState[j] = Medium.setState_phX(p, h[j]);
-      T[j] = Medium.temperature(fluidState[j]);
-      rho[j] = Medium.density(fluidState[j]);
-      drdp[j] = if Medium.singleState then 0 else Medium.density_derp_h(
-        fluidState[j]);
-      drdh[j] = Medium.density_derh_p(fluidState[j]);
-      u[j] = w/(rho[j]*A);
-    end for;
-
-    // Boundary conditions
-    win = infl.m_flow/Nt;
-    wout = -outfl.m_flow/Nt;
-    assert(HydraulicCapacitance == HCtypes.Upstream or
-             HydraulicCapacitance == HCtypes.Middle or
-             HydraulicCapacitance == HCtypes.Downstream,
-             "Unsupported HydraulicCapacitance option");
-    if HydraulicCapacitance == HCtypes.Middle then
-      p = infl.p - Dpfric1 - Dpstat/2;
-      w = win;
-    elseif HydraulicCapacitance == HCtypes.Upstream then
-      p = infl.p;
-      w = -outfl.m_flow/Nt;
-    else  // if HydraulicCapacitance == HCtypes.Downstream then
-      p = outfl.p;
-      w = win;
-    end if;
-    infl.h_outflow = h[1];
-    outfl.h_outflow = htilde[N - 1];
-
-     h[1] = inStream(infl.h_outflow);
-     h[2:N] = htilde;
-
-    connect(wall,heatTransfer.wall);
-
-    Q = heatTransfer.Q "Total heat flow through lateral boundary";
-    M = sum(rhobar)*A*l "Fluid mass (single tube)";
-    Mtot = M*Nt "Fluid mass (total)";
-    Tr = noEvent(M/max(win, Modelica.Constants.eps)) "Residence time";
-
-    assert(w > -wnom*wnm, "Reverse flow not allowed, maybe you connected the component with wrong orientation");
-  initial equation
-    if initOpt == Choices.Init.Options.noInit then
-      // do nothing
-    elseif initOpt == Choices.Init.Options.fixedState then
-      if not noInitialPressure then
-        p = pstart;
-      end if;
-      htilde = hstart[2:N];
-    elseif initOpt == Choices.Init.Options.steadyState then
-      der(htilde) = zeros(N - 1);
-      if (not Medium.singleState) and not noInitialPressure then
-        der(p) = 0;
-      end if;
-    elseif initOpt == Choices.Init.Options.steadyStateNoP then
-      der(htilde) = zeros(N - 1);
-      assert(false, "initOpt = steadyStateNoP deprecated, use steadyState and noInitialPressure",AssertionLevel.warning);
-    elseif initOpt == Choices.Init.Options.steadyStateNoT and not Medium.singleState then
-      der(p) = 0;
-    else
-      assert(false, "Unsupported initialisation option");
-    end if;
-    annotation (
-      Diagram(graphics),
-      Icon(graphics={Text(extent={{-100,-60},{100,-100}},textString="%name")}),
-      Documentation(info="<HTML>
+</html>"),
+      Diagram(graphics));
+  end Tank;
+
+  model Flow1DFV "1-dimensional fluid flow model for water/steam (finite volumes)"
+    extends BaseClasses.Flow1DBase;
+    import ThermoPower.Choices.Flow1D.FFtypes;
+    import ThermoPower.Choices.Flow1D.HCtypes;
+    parameter SI.PerUnit wnm = 1e-3 "Maximum fraction of the nominal flow rate allowed as reverse flow";
+    parameter Boolean fixedMassFlowSimplified = false "Fix flow rate = wnom for simplified homotopy model" annotation(
+      Dialog(tab = "Initialisation"));
+    Medium.ThermodynamicState fluidState[N] "Thermodynamic state of the fluid at the nodes";
+    SI.Length omega_hyd "Wet perimeter (single tube)";
+    SI.Pressure Dpfric "Pressure drop due to friction (total)";
+    SI.Pressure Dpfric1 "Pressure drop due to friction (from inlet to capacitance)";
+    SI.Pressure Dpfric2 "Pressure drop due to friction (from capacitance to outlet)";
+    SI.Pressure Dpstat "Pressure drop due to static head";
+    Medium.MassFlowRate win "Flow rate at the inlet (single tube)";
+    Medium.MassFlowRate wout "Flow rate at the outlet (single tube)";
+    Real Kf "Hydraulic friction coefficient";
+    Real dwdt "Dynamic momentum term";
+    SI.PerUnit Cf "Fanning friction factor";
+    Medium.AbsolutePressure p(start = pstart, stateSelect = StateSelect.prefer) "Fluid pressure for property calculations";
+    Medium.MassFlowRate w(start = wnom / Nt) "Mass flow rate (single tube)";
+    Medium.MassFlowRate wbar[N - 1](each start = wnom / Nt) "Average flow rate through volumes (single tube)";
+    SI.Power Q_single[N - 1] = heatTransfer.Qvol / Nt "Heat flows entering the volumes from the lateral boundary (single tube)";
+    //   MassFlowRate wstar[N];
+    SI.Velocity u[N] "Fluid velocity";
+    Medium.Temperature T[N] "Fluid temperature";
+    Medium.SpecificEnthalpy h[N](start = hstart) "Fluid specific enthalpy at the nodes";
+    Medium.SpecificEnthalpy htilde[N - 1](start = hstart[2:N], each stateSelect = StateSelect.prefer) "Enthalpy state variables";
+    Medium.Density rho[N] "Fluid nodal density";
+    SI.Mass M "Fluid mass (single tube)";
+    SI.Mass Mtot "Fluid mass (total)";
+    SI.MassFlowRate dMdt[N - 1] "Time derivative of mass in each cell between two nodes";
+    replaceable model HeatTransfer = Thermal.HeatTransferFV.IdealHeatTransfer constrainedby ThermoPower.Thermal.BaseClasses.DistributedHeatTransferFV annotation(
+       choicesAllMatching = true);
+    HeatTransfer heatTransfer(redeclare package Medium = Medium, final Nf = N, final Nw = Nw, final Nt = Nt, final L = L, final A = A, final Dhyd = Dhyd, final omega = omega, final wnom = wnom / Nt, final w = w * ones(N), final fluidState = fluidState) "Instantiated heat transfer model";
+    ThermoPower.Thermal.DHTVolumes wall(final N = Nw) annotation(
+      Placement(transformation(extent = {{-40, 40}, {40, 60}}, rotation = 0)));
+  protected
+    Medium.Density rhobar[N - 1] "Fluid average density";
+    SI.SpecificVolume vbar[N - 1] "Fluid average specific volume";
+    //HeatFlux phibar[N - 1] "Average heat flux";
+    SI.DerDensityByEnthalpy drdh[N] "Derivative of density by enthalpy";
+    SI.DerDensityByEnthalpy drbdh[N - 1] "Derivative of average density by enthalpy";
+    SI.DerDensityByPressure drdp[N] "Derivative of density by pressure";
+    SI.DerDensityByPressure drbdp[N - 1] "Derivative of average density by pressure";
+  equation
+//All equations are referred to a single tube
+// Friction factor selection
+    omega_hyd = 4 * A / Dhyd;
+    if FFtype == FFtypes.Kfnom then
+      Kf = Kfnom * Kfc;
+    elseif FFtype == FFtypes.OpPoint then
+      Kf = dpnom * rhonom / (wnom / Nt) ^ 2 * Kfc;
+    elseif FFtype == FFtypes.Cfnom then
+      Cf = Cfnom * Kfc;
+    elseif FFtype == FFtypes.Colebrook then
+      Cf = f_colebrook(w, Dhyd / A, e, Medium.dynamicViscosity(fluidState[integer(N / 2)])) * Kfc;
+    else
+// if FFtype == FFtypes.NoFriction then
+      Cf = 0;
+    end if;
+    Kf = Cf * omega_hyd * L / (2 * A ^ 3) "Relationship between friction coefficient and Fanning friction factor";
+    assert(Kf >= 0, "Negative friction coefficient");
+// Dynamic momentum term
+    if DynamicMomentum then
+      dwdt = der(w);
+    else
+      dwdt = 0;
+    end if;
+    sum(dMdt) = (infl.m_flow + outfl.m_flow) / Nt "Mass balance";
+    L / A * dwdt + outfl.p - infl.p + Dpstat + Dpfric = 0 "Momentum balance";
+    Dpfric = Dpfric1 + Dpfric2 "Total pressure drop due to friction";
+    if FFtype == FFtypes.NoFriction then
+      Dpfric1 = 0;
+      Dpfric2 = 0;
+    elseif HydraulicCapacitance == HCtypes.Middle then
+//assert((N-1)-integer((N-1)/2)*2 == 0, "N must be odd");
+      Dpfric1 = homotopy(Kf * squareReg(win, wnom / Nt * wnf) * sum(vbar[1:integer((N - 1) / 2)]) / (N - 1), dpnom / 2 / (wnom / Nt) * win) "Pressure drop from inlet to capacitance";
+      Dpfric2 = homotopy(Kf * squareReg(wout, wnom / Nt * wnf) * sum(vbar[1 + integer((N - 1) / 2):N - 1]) / (N - 1), dpnom / 2 / (wnom / Nt) * wout) "Pressure drop from capacitance to outlet";
+    elseif HydraulicCapacitance == HCtypes.Upstream then
+      Dpfric1 = 0 "Pressure drop from inlet to capacitance";
+      Dpfric2 = homotopy(Kf * squareReg(wout, wnom / Nt * wnf) * sum(vbar) / (N - 1), dpnom / (wnom / Nt) * wout) "Pressure drop from capacitance to outlet";
+    else
+// if HydraulicCapacitance == HCtypes.Downstream then
+      Dpfric1 = homotopy(Kf * squareReg(win, wnom / Nt * wnf) * sum(vbar) / (N - 1), dpnom / (wnom / Nt) * win) "Pressure drop from inlet to capacitance";
+      Dpfric2 = 0 "Pressure drop from capacitance to outlet";
+    end if "Pressure drop due to friction";
+    Dpstat = if abs(dzdx) < 1e-6 then 0 else g * l * dzdx * sum(rhobar) "Pressure drop due to static head";
+    for j in 1:N - 1 loop
+      if Medium.singleState then
+        A * l * rhobar[j] * der(htilde[j]) + wbar[j] * (h[j + 1] - h[j]) = Q_single[j] "Energy balance (pressure effects neglected)";
+//Qvol = l*omega*phibar[j]
+      else
+        A * l * rhobar[j] * der(htilde[j]) + wbar[j] * (h[j + 1] - h[j]) - A * l * der(p) = Q_single[j] "Energy balance";
+//Qvol = l*omega*phibar[j]
+      end if;
+      dMdt[j] = A * l * (drbdh[j] * der(htilde[j]) + drbdp[j] * der(p)) "Mass derivative for each volume";
+// Average volume quantities
+      rhobar[j] = (rho[j] + rho[j + 1]) / 2;
+      drbdp[j] = (drdp[j] + drdp[j + 1]) / 2;
+      drbdh[j] = (drdh[j] + drdh[j + 1]) / 2;
+      vbar[j] = 1 / rhobar[j];
+      if fixedMassFlowSimplified then
+        wbar[j] = homotopy(infl.m_flow / Nt - sum(dMdt[1:j - 1]) - dMdt[j] / 2, wnom / Nt);
+      else
+        wbar[j] = infl.m_flow / Nt - sum(dMdt[1:j - 1]) - dMdt[j] / 2;
+      end if;
+    end for;
+// for j in 1:N loop
+//   wstar[j] = homotopy(infl.m_flow/Nt - sum(dMdt[1:j - 1]) - dMdt[j]/2, wnom/Nt);
+// end for;
+// Fluid property calculations
+    for j in 1:N loop
+      fluidState[j] = Medium.setState_phX(p, h[j]);
+      T[j] = Medium.temperature(fluidState[j]);
+      rho[j] = Medium.density(fluidState[j]);
+      drdp[j] = if Medium.singleState then 0 else Medium.density_derp_h(fluidState[j]);
+      drdh[j] = Medium.density_derh_p(fluidState[j]);
+      u[j] = w / (rho[j] * A);
+    end for;
+// Boundary conditions
+    win = infl.m_flow / Nt;
+    wout = -outfl.m_flow / Nt;
+    assert(HydraulicCapacitance == HCtypes.Upstream or HydraulicCapacitance == HCtypes.Middle or HydraulicCapacitance == HCtypes.Downstream, "Unsupported HydraulicCapacitance option");
+    if HydraulicCapacitance == HCtypes.Middle then
+      p = infl.p - Dpfric1 - Dpstat / 2;
+      w = win;
+    elseif HydraulicCapacitance == HCtypes.Upstream then
+      p = infl.p;
+      w = -outfl.m_flow / Nt;
+    else
+// if HydraulicCapacitance == HCtypes.Downstream then
+      p = outfl.p;
+      w = win;
+    end if;
+    infl.h_outflow = h[1];
+    outfl.h_outflow = htilde[N - 1];
+    h[1] = inStream(infl.h_outflow);
+    h[2:N] = htilde;
+    connect(wall, heatTransfer.wall);
+    Q = heatTransfer.Q "Total heat flow through lateral boundary";
+    M = sum(rhobar) * A * l "Fluid mass (single tube)";
+    Mtot = M * Nt "Fluid mass (total)";
+    Tr = noEvent(M / max(win, Modelica.Constants.eps)) "Residence time";
+    assert(w > (-wnom * wnm), "Reverse flow not allowed, maybe you connected the component with wrong orientation");
+  initial equation
+    if initOpt == Choices.Init.Options.noInit then
+// do nothing
+    elseif initOpt == Choices.Init.Options.fixedState then
+      if not noInitialPressure then
+        p = pstart;
+      end if;
+      htilde = hstart[2:N];
+    elseif initOpt == Choices.Init.Options.steadyState then
+      der(htilde) = zeros(N - 1);
+      if not Medium.singleState and not noInitialPressure then
+        der(p) = 0;
+      end if;
+    elseif initOpt == Choices.Init.Options.steadyStateNoP then
+      der(htilde) = zeros(N - 1);
+      assert(false, "initOpt = steadyStateNoP deprecated, use steadyState and noInitialPressure", AssertionLevel.warning);
+    elseif initOpt == Choices.Init.Options.steadyStateNoT and not Medium.singleState then
+      der(p) = 0;
+    else
+      assert(false, "Unsupported initialisation option");
+    end if;
+    annotation(
+      Diagram(graphics),
+      Icon(graphics = {Text(extent = {{-100, -60}, {100, -100}}, textString = "%name")}),
+      Documentation(info = "<HTML>
 <p>This model describes the flow of water or steam in a rigid tube. The basic modelling assumptions are:
 <ul><li>The fluid state is always one-phase (i.e. subcooled liquid or superheated steam).
 <li>Uniform velocity is assumed on the cross section, leading to a 1-D distributed parameter model.
@@ -1402,7 +1142,7 @@
 <p>Start values for the pressure and flowrate state variables are specified by <tt>pstart</tt>, <tt>wstart</tt>. The start values for the node enthalpies are linearly distributed from <tt>hstartin</tt> at the inlet to <tt>hstartout</tt> at the outlet.
 <p>A bank of <tt>Nt</tt> identical tubes working in parallel can be modelled by setting <tt>Nt > 1</tt>. The geometric parameters always refer to a <i>single</i> tube.
 <p>This models makes the temperature and external heat flow distributions available to connected components through the <tt>wall</tt> connector. If other variables (e.g. the heat transfer coefficient) are needed by external components to compute the actual heat flow, the <tt>wall</tt> connector can be replaced by an extended version of the <tt>DHT</tt> connector.
-</HTML>", revisions="<html>
+</HTML>", revisions = "<html>
 <ul>
 <li><i>16 Sep 2005</i>
     by <a href=\"mailto:francesco.casella@polimi.it\">Francesco Casella</a>:<br>
@@ -1433,360 +1173,255 @@
        First release.</li>
 </ul>
 </html>
-"));
-  end Flow1DFV;
-
-  model Flow1DFV2w "Same as Flow1DFV with two walls and heat transfer models"
-    extends Flow1DFV(
-      Q_single = heatTransfer.Qvol/Nt + heatTransfer2.Qvol/Nt);
-    replaceable model HeatTransfer2 = Thermal.HeatTransferFV.IdealHeatTransfer
-      constrainedby ThermoPower.Thermal.BaseClasses.DistributedHeatTransferFV
-      annotation (choicesAllMatching=true);
-    HeatTransfer heatTransfer2(
-      redeclare package Medium = Medium,
-      final Nf=N,
-      final Nw=Nw,
-      final Nt=Nt,
-      final L=L,
-      final A=A,
-      final Dhyd=Dhyd,
-      final omega=omega,
-      final wnom=wnom/Nt,
-      final w=w*ones(N),
-      final fluidState=fluidState) "Instantiated heat transfer model";
-
-    Thermal.DHTVolumes wall2(final N=Nw)
-      annotation (Placement(transformation(extent={{-60,-60},{60,-40}},
-                                                                      rotation=0)));
-  equation
-    connect(wall2,heatTransfer2.wall);
-    annotation (Diagram(coordinateSystem(preserveAspectRatio=false, extent={{-100,
-              -100},{100,100}}), graphics), Icon(coordinateSystem(
-            preserveAspectRatio=false, extent={{-100,-100},{100,100}})));
-  end Flow1DFV2w;
-
-  model Flow1DFV2ph
-    "1-dimensional fluid flow model for water/steam (finite volumes, 2-phase)"
-    extends BaseClasses.Flow1DBase(redeclare replaceable package Medium =
-          StandardWater                constrainedby
-        Modelica.Media.Interfaces.PartialTwoPhaseMedium
-                        "Medium model",
-        FluidPhaseStart=Choices.FluidPhase.FluidPhases.TwoPhases);
-    replaceable model HeatTransfer = Thermal.HeatTransferFV.IdealHeatTransfer
-      constrainedby ThermoPower.Thermal.BaseClasses.DistributedHeatTransferFV
-      annotation (choicesAllMatching=true);
-    HeatTransfer heatTransfer(
-      redeclare package Medium = Medium,
-      final Nf=N,
-      final Nw=Nw,
-      final Nt=Nt,
-      final L=L,
-      final A=A,
-      final Dhyd=Dhyd,
-      final omega=omega,
-      final wnom=wnom/Nt,
-      final w=w*ones(N),
-      final fluidState=fluidState) "Instantiated heat transfer model";
-
-    ThermoPower.Thermal.DHTVolumes wall(final N=Nw) annotation (Dialog(enable=
-            false), Placement(transformation(extent={{-40,40},{40,60}},
-            rotation=0)));
-    import ThermoPower.Choices.Flow1D.FFtypes;
-    import ThermoPower.Choices.Flow1D.HCtypes;
-    // package SmoothMedium = Medium (final smoothModel=true);
-    constant SI.Pressure pzero=10 "Small deltap for calculations";
-    constant Medium.AbsolutePressure pc=Medium.fluidConstants[1].criticalPressure;
-    constant SI.SpecificEnthalpy hzero=1e-3 "Small value for deltah";
-
-    parameter SI.PerUnit wnm = 1e-3 "Maximum fraction of the nominal flow rate allowed as reverse flow";
-    parameter Boolean fixedMassFlowSimplified = false "Fix flow rate = wnom for simplified homotopy model";
-
-    // SmoothMedium.ThermodynamicState fluidState[N]
-    //   "Thermodynamic state of the fluid at the nodes";
-    Medium.ThermodynamicState fluidState[N]
-      "Thermodynamic state of the fluid at the nodes";
-    Medium.SaturationProperties sat "Properties of saturated fluid";
-    SI.Length omega_hyd "Wet perimeter (single tube)";
-    SI.Pressure Dpfric "Pressure drop due to friction";
-    SI.Pressure Dpstat "Pressure drop due to static head";
-    Real Kf[N - 1] "Friction coefficient";
-    Real Kfl[N - 1] "Linear friction coefficient";
-    Real Cf[N - 1] "Fanning friction factor";
-    Real dwdt "Dynamic momentum term";
-    Medium.AbsolutePressure p(start=pstart)
-      "Fluid pressure for property calculations";
-
-                                          /*, stateSelect=StateSelect.prefer*/
-    SI.Pressure dpf[N - 1] "Pressure drop due to friction between two nodes";
-    Medium.MassFlowRate w(start=wnom/Nt) "Mass flowrate (single tube)";
-    Medium.MassFlowRate wbar[N - 1](each start=wnom/Nt)
-      "Average mass flow rates (single tube)";
-    SI.Power Q_single[N-1] = heatTransfer.Qvol/Nt
-      "Heat flows entering the volumes from the lateral boundary (single tube)";
-    SI.Velocity u[N] "Fluid velocity";
-    Medium.Temperature T[N] "Fluid temperature";
-    Medium.Temperature Ts "Saturated water temperature";
-    Medium.SpecificEnthalpy h[N](start=hstart) "Fluid specific enthalpy";
-    Medium.SpecificEnthalpy htilde[N - 1](start=hstart[2:N])
-      "Enthalpy state variables";                          /*,each stateSelect=StateSelect.prefer*/
-    Medium.SpecificEnthalpy hl "Saturated liquid temperature";
-    Medium.SpecificEnthalpy hv "Saturated vapour temperature";
-    SI.PerUnit x[N] "Steam quality";
-    Medium.Density rho[N] "Fluid density";
-    Units.LiquidDensity rhol "Saturated liquid density";
-    Units.GasDensity rhov "Saturated vapour density";
-    SI.Mass M "Fluid mass";
-  protected
-    SI.DerEnthalpyByPressure dhldp
-      "Derivative of saturated liquid enthalpy by pressure";
-    SI.DerEnthalpyByPressure dhvdp
-      "Derivative of saturated vapour enthalpy by pressure";
-    Medium.Density rhobar[N - 1] "Fluid average density";
-    SI.DerDensityByPressure drdp[N] "Derivative of density by pressure";
-    SI.DerDensityByPressure drbdp[N - 1]
-      "Derivative of average density by pressure";
-    SI.DerDensityByPressure drldp
-      "Derivative of saturated liquid density by pressure";
-    SI.DerDensityByPressure drvdp
-      "Derivative of saturated vapour density by pressure";
-    SI.SpecificVolume vbar[N - 1] "Average specific volume";
-    SI.DerDensityByEnthalpy drdh[N] "Derivative of density by enthalpy";
-    SI.DerDensityByEnthalpy drbdh1[N - 1]
-      "Derivative of average density by left enthalpy";
-    SI.DerDensityByEnthalpy drbdh2[N - 1]
-      "Derivative of average density by right enthalpy";
-    Real AA;
-    Real AA1;
-    SI.MassFlowRate dMdt[N - 1] "Derivative of fluid mass in each volume";
-  equation
-    //All equations are referred to a single tube
-    omega_hyd = 4*A/Dhyd;
-    // Friction factor selection
-    for j in 1:(N - 1) loop
-      if FFtype == FFtypes.Kfnom then
-        Kf[j] = Kfnom*Kfc/(N - 1);
-        Cf[j] = 2*Kf[j]*A^3/(omega_hyd*l);
-      elseif FFtype == FFtypes.OpPoint then
-        Kf[j] = dpnom*rhonom/(wnom/Nt)^2/(N - 1)*Kfc;
-        Cf[j] = 2*Kf[j]*A^3/(omega_hyd*l);
-      elseif FFtype == FFtypes.Cfnom then
-        Kf[j] = Cfnom*omega_hyd*l/(2*A^3)*Kfc;
-        Cf[j] = 2*Kf[j]*A^3/(omega_hyd*l);
-      elseif FFtype == FFtypes.Colebrook then
-        Cf[j] = if noEvent(htilde[j] < hl or htilde[j] > hv) then f_colebrook(
-            w,
-            Dhyd/A,
-            e,
-            Medium.dynamicViscosity(fluidState[j]))*Kfc else f_colebrook_2ph(
-            w,
-            Dhyd/A,
-            e,
-            Medium.dynamicViscosity(Medium.setBubbleState(sat, 1)),
-            Medium.dynamicViscosity(Medium.setDewState(sat, 1)),
-            x[j])*Kfc;
-        Kf[j] = Cf[j]*omega_hyd*l/(2*A^3);
-      elseif FFtype == FFtypes.NoFriction then
-        Cf[j] = 0;
-        Kf[j] = 0;
-      else
-        assert(FFtype <> FFtypes.NoFriction, "Unsupported FFtype");
-        Cf[j] = 0;
-        Kf[j] = 0;
-      end if;
-      assert(Kf[j] >= 0, "Negative friction coefficient");
-      Kfl[j] = wnom/Nt*wnf*Kf[j];
-    end for;
-
-    // Dynamic momentum term
-    if DynamicMomentum then
-      dwdt = der(w);
-    else
-      dwdt = 0;
-    end if;
-
-    sum(dMdt) = (infl.m_flow/Nt + outfl.m_flow/Nt) "Mass balance";
-    sum(dpf) = Dpfric "Total pressure drop due to friction";
-    Dpstat = if abs(dzdx) < 1e-6 then 0 else g*l*dzdx*sum(rhobar)
-      "Pressure drop due to static head";
-    L/A*dwdt + (outfl.p - infl.p) + Dpstat + Dpfric = 0 "Momentum balance";
-    for j in 1:(N - 1) loop
-      A*l*rhobar[j]*der(htilde[j]) + wbar[j]*(h[j + 1] - h[j]) - A*l*der(p) = Q_single[j]
-        "Energy balance";
-      dMdt[j] = A*l*(drbdh1[j]*der(h[j]) + drbdh2[j]*der(h[j + 1]) + drbdp[j]*
-        der(p)) "Mass balance for each volume";
-      // Average volume quantities
-      vbar[j] = 1/rhobar[j] "Average specific volume";
-      if fixedMassFlowSimplified then
-        wbar[j] = homotopy(infl.m_flow/Nt - sum(dMdt[1:j - 1]) - dMdt[j]/2, wnom/Nt);
-      else
-        wbar[j] = infl.m_flow/Nt - sum(dMdt[1:j - 1]) - dMdt[j]/2;
-      end if;
-      dpf[j] = (if FFtype == FFtypes.NoFriction then 0 else homotopy(smooth(1,
-        Kf[j]*squareReg(w, wnom/Nt*wnf))*vbar[j], dpnom/(N - 1)/(wnom/Nt)*w));
-      if avoidInletEnthalpyDerivative and j == 1 then
-        // first volume properties computed by the outlet properties
-        rhobar[j] = rho[j + 1];
-        drbdp[j] = drdp[j + 1];
-        drbdh1[j] = 0;
-        drbdh2[j] = drdh[j + 1];
-      elseif noEvent((h[j] < hl and h[j + 1] < hl) or (h[j] > hv and h[j + 1]
-           > hv) or p >= (pc - pzero) or abs(h[j + 1] - h[j]) < hzero) then
-        // 1-phase or almost uniform properties
-        rhobar[j] = (rho[j] + rho[j + 1])/2;
-        drbdp[j] = (drdp[j] + drdp[j + 1])/2;
-        drbdh1[j] = drdh[j]/2;
-        drbdh2[j] = drdh[j + 1]/2;
-      elseif noEvent(h[j] >= hl and h[j] <= hv and h[j + 1] >= hl and h[j + 1]
-           <= hv) then
-        // 2-phase
-        rhobar[j] = AA*log(rho[j]/rho[j + 1])/(h[j + 1] - h[j]);
-        drbdp[j] = (AA1*log(rho[j]/rho[j + 1]) + AA*(1/rho[j]*drdp[j] - 1/rho[j
-           + 1]*drdp[j + 1]))/(h[j + 1] - h[j]);
-        drbdh1[j] = (rhobar[j] - rho[j])/(h[j + 1] - h[j]);
-        drbdh2[j] = (rho[j + 1] - rhobar[j])/(h[j + 1] - h[j]);
-      elseif noEvent(h[j] < hl and h[j + 1] >= hl and h[j + 1] <= hv) then
-        // liquid/2-phase
-        rhobar[j] = ((rho[j] + rhol)*(hl - h[j])/2 + AA*log(rhol/rho[j + 1]))/(
-          h[j + 1] - h[j]);
-        drbdp[j] = ((drdp[j] + drldp)*(hl - h[j])/2 + (rho[j] + rhol)/2*dhldp
-           + AA1*log(rhol/rho[j + 1]) + AA*(1/rhol*drldp - 1/rho[j + 1]*drdp[j
-           + 1]))/(h[j + 1] - h[j]);
-        drbdh1[j] = (rhobar[j] - (rho[j] + rhol)/2 + drdh[j]*(hl - h[j])/2)/(h[
-          j + 1] - h[j]);
-        drbdh2[j] = (rho[j + 1] - rhobar[j])/(h[j + 1] - h[j]);
-      elseif noEvent(h[j] >= hl and h[j] <= hv and h[j + 1] > hv) then
-        // 2-phase/vapour
-        rhobar[j] = (AA*log(rho[j]/rhov) + (rhov + rho[j + 1])*(h[j + 1] - hv)/
-          2)/(h[j + 1] - h[j]);
-        drbdp[j] = (AA1*log(rho[j]/rhov) + AA*(1/rho[j]*drdp[j] - 1/rhov*drvdp)
-           + (drvdp + drdp[j + 1])*(h[j + 1] - hv)/2 - (rhov + rho[j + 1])/2*
-          dhvdp)/(h[j + 1] - h[j]);
-        drbdh1[j] = (rhobar[j] - rho[j])/(h[j + 1] - h[j]);
-        drbdh2[j] = ((rhov + rho[j + 1])/2 - rhobar[j] + drdh[j + 1]*(h[j + 1]
-           - hv)/2)/(h[j + 1] - h[j]);
-      elseif noEvent(h[j] < hl and h[j + 1] > hv) then
-        // liquid/2-phase/vapour
-        rhobar[j] = ((rho[j] + rhol)*(hl - h[j])/2 + AA*log(rhol/rhov) + (rhov
-           + rho[j + 1])*(h[j + 1] - hv)/2)/(h[j + 1] - h[j]);
-        drbdp[j] = ((drdp[j] + drldp)*(hl - h[j])/2 + (rho[j] + rhol)/2*dhldp
-           + AA1*log(rhol/rhov) + AA*(1/rhol*drldp - 1/rhov*drvdp) + (drvdp +
-          drdp[j + 1])*(h[j + 1] - hv)/2 - (rhov + rho[j + 1])/2*dhvdp)/(h[j +
-          1] - h[j]);
-        drbdh1[j] = (rhobar[j] - (rho[j] + rhol)/2 + drdh[j]*(hl - h[j])/2)/(h[
-          j + 1] - h[j]);
-        drbdh2[j] = ((rhov + rho[j + 1])/2 - rhobar[j] + drdh[j + 1]*(h[j + 1]
-           - hv)/2)/(h[j + 1] - h[j]);
-      elseif noEvent(h[j] >= hl and h[j] <= hv and h[j + 1] < hl) then
-        // 2-phase/liquid
-        rhobar[j] = (AA*log(rho[j]/rhol) + (rhol + rho[j + 1])*(h[j + 1] - hl)/
-          2)/(h[j + 1] - h[j]);
-        drbdp[j] = (AA1*log(rho[j]/rhol) + AA*(1/rho[j]*drdp[j] - 1/rhol*drldp)
-           + (drldp + drdp[j + 1])*(h[j + 1] - hl)/2 - (rhol + rho[j + 1])/2*
-          dhldp)/(h[j + 1] - h[j]);
-        drbdh1[j] = (rhobar[j] - rho[j])/(h[j + 1] - h[j]);
-        drbdh2[j] = ((rhol + rho[j + 1])/2 - rhobar[j] + drdh[j + 1]*(h[j + 1]
-           - hl)/2)/(h[j + 1] - h[j]);
-      elseif noEvent(h[j] > hv and h[j + 1] < hl) then
-        // vapour/2-phase/liquid
-        rhobar[j] = ((rho[j] + rhov)*(hv - h[j])/2 + AA*log(rhov/rhol) + (rhol
-           + rho[j + 1])*(h[j + 1] - hl)/2)/(h[j + 1] - h[j]);
-        drbdp[j] = ((drdp[j] + drvdp)*(hv - h[j])/2 + (rho[j] + rhov)/2*dhvdp
-           + AA1*log(rhov/rhol) + AA*(1/rhov*drvdp - 1/rhol*drldp) + (drldp +
-          drdp[j + 1])*(h[j + 1] - hl)/2 - (rhol + rho[j + 1])/2*dhldp)/(h[j +
-          1] - h[j]);
-        drbdh1[j] = (rhobar[j] - (rho[j] + rhov)/2 + drdh[j]*(hv - h[j])/2)/(h[
-          j + 1] - h[j]);
-        drbdh2[j] = ((rhol + rho[j + 1])/2 - rhobar[j] + drdh[j + 1]*(h[j + 1]
-           - hl)/2)/(h[j + 1] - h[j]);
-      else
-        // vapour/2-phase
-        rhobar[j] = ((rho[j] + rhov)*(hv - h[j])/2 + AA*log(rhov/rho[j + 1]))/(
-          h[j + 1] - h[j]);
-        drbdp[j] = ((drdp[j] + drvdp)*(hv - h[j])/2 + (rho[j] + rhov)/2*dhvdp
-           + AA1*log(rhov/rho[j + 1]) + AA*(1/rhov*drvdp - 1/rho[j + 1]*drdp[j
-           + 1]))/(h[j + 1] - h[j]);
-        drbdh1[j] = (rhobar[j] - (rho[j] + rhov)/2 + drdh[j]*(hv - h[j])/2)/(h[
-          j + 1] - h[j]);
-        drbdh2[j] = (rho[j + 1] - rhobar[j])/(h[j + 1] - h[j]);
-      end if;
-    end for;
-
-    // Saturated fluid property calculations
-    sat = Medium.setSat_p(p);
-    Ts = sat.Tsat;
-    rhol = Medium.bubbleDensity(sat);
-    rhov = Medium.dewDensity(sat);
-    hl = Medium.bubbleEnthalpy(sat);
-    hv = Medium.dewEnthalpy(sat);
-    drldp = Medium.dBubbleDensity_dPressure(sat);
-    drvdp = Medium.dDewDensity_dPressure(sat);
-    dhldp = Medium.dBubbleEnthalpy_dPressure(sat);
-    dhvdp = Medium.dDewEnthalpy_dPressure(sat);
-    AA = (hv - hl)/(1/rhov - 1/rhol);
-    AA1 = ((dhvdp - dhldp)*(rhol - rhov)*rhol*rhov - (hv - hl)*(rhov^2*drldp -
-      rhol^2*drvdp))/(rhol - rhov)^2;
-
-    // Fluid property calculations
-    for j in 1:N loop
-      fluidState[j] = Medium.setState_phX(p, h[j]);
-      T[j] = Medium.temperature(fluidState[j]);
-      rho[j] = Medium.density(fluidState[j]);
-      drdp[j] = Medium.density_derp_h(fluidState[j]);
-      drdh[j] = Medium.density_derh_p(fluidState[j]);
-      u[j] = w/(rho[j]*A);
-      x[j] = noEvent(if h[j] <= hl then 0 else if h[j] >= hv then 1 else (h[j]
-         - hl)/(hv - hl));
-    end for;
-
-    // Selection of representative pressure and flow rate variables
-    if HydraulicCapacitance == HCtypes.Upstream then
-      p = infl.p;
-      w = -outfl.m_flow/Nt;
-    else
-      p = outfl.p;
-      w = infl.m_flow/Nt;
-    end if;
-
-    // Boundary conditions
-    infl.h_outflow = htilde[1];
-    outfl.h_outflow = htilde[N - 1];
-    h[1] = inStream(infl.h_outflow);
-    h[2:N] = htilde;
-
-    connect(wall,heatTransfer.wall);
-
-    Q = heatTransfer.Q "Total heat flow through lateral boundary";
-    M = sum(rhobar)*A*l "Fluid mass (single tube)";
-    Tr = noEvent(M/max(infl.m_flow/Nt, Modelica.Constants.eps))
-      "Residence time";
-
-    assert(infl.m_flow > -wnom*wnm, "Reverse flow not allowed, maybe you connected the component with wrong orientation");
-  initial equation
-    if initOpt == Choices.Init.Options.noInit then
-      // do nothing
-    elseif initOpt == Choices.Init.Options.fixedState then
-      if not noInitialPressure then
-        p = pstart;
-      end if;
-      htilde = hstart[2:N];
-    elseif initOpt == Choices.Init.Options.steadyState then
-      der(htilde) = zeros(N - 1);
-      if (not Medium.singleState) and not noInitialPressure then
-        der(p) = 0;
-      end if;
-    elseif initOpt == Choices.Init.Options.steadyStateNoP then
-      der(htilde) = zeros(N - 1);
-      assert(false, "initOpt = steadyStateNoP deprecated, use steadyState and noInitialPressure",AssertionLevel.warning);
-    elseif initOpt == Choices.Init.Options.steadyStateNoT and not Medium.singleState then
-      der(p) = 0;
-    else
-      assert(false, "Unsupported initialisation option");
-    end if;
-
-    annotation (
-      Diagram(graphics),
-      Icon(graphics={Text(extent={{-100,-60},{100,-100}},textString="%name")}),
-      Documentation(info="<HTML>
+      "));
+  end Flow1DFV;
+
+  model Flow1DFV2w "Same as Flow1DFV with two walls and heat transfer models"
+    extends Flow1DFV(Q_single = heatTransfer.Qvol / Nt + heatTransfer2.Qvol / Nt);
+    replaceable model HeatTransfer2 = Thermal.HeatTransferFV.IdealHeatTransfer constrainedby ThermoPower.Thermal.BaseClasses.DistributedHeatTransferFV annotation(
+       choicesAllMatching = true);
+    HeatTransfer heatTransfer2(redeclare package Medium = Medium, final Nf = N, final Nw = Nw, final Nt = Nt, final L = L, final A = A, final Dhyd = Dhyd, final omega = omega, final wnom = wnom / Nt, final w = w * ones(N), final fluidState = fluidState) "Instantiated heat transfer model";
+    Thermal.DHTVolumes wall2(final N = Nw) annotation(
+      Placement(transformation(extent = {{-60, -60}, {60, -40}}, rotation = 0)));
+  equation
+    connect(wall2, heatTransfer2.wall);
+    annotation(
+      Diagram(coordinateSystem(preserveAspectRatio = false, extent = {{-100, -100}, {100, 100}}), graphics),
+      Icon(coordinateSystem(preserveAspectRatio = false, extent = {{-100, -100}, {100, 100}})));
+  end Flow1DFV2w;
+
+  model Flow1DFV2ph "1-dimensional fluid flow model for water/steam (finite volumes, 2-phase)"
+    extends BaseClasses.Flow1DBase(redeclare replaceable package Medium = StandardWater constrainedby Modelica.Media.Interfaces.PartialTwoPhaseMedium "Medium model", FluidPhaseStart = Choices.FluidPhase.FluidPhases.TwoPhases);
+    replaceable model HeatTransfer = Thermal.HeatTransferFV.IdealHeatTransfer constrainedby ThermoPower.Thermal.BaseClasses.DistributedHeatTransferFV annotation(
+       choicesAllMatching = true);
+    HeatTransfer heatTransfer(redeclare package Medium = Medium, final Nf = N, final Nw = Nw, final Nt = Nt, final L = L, final A = A, final Dhyd = Dhyd, final omega = omega, final wnom = wnom / Nt, final w = w * ones(N), final fluidState = fluidState) "Instantiated heat transfer model";
+    ThermoPower.Thermal.DHTVolumes wall(final N = Nw) annotation(
+      Dialog(enable = false),
+      Placement(transformation(extent = {{-40, 40}, {40, 60}}, rotation = 0)));
+    import ThermoPower.Choices.Flow1D.FFtypes;
+    import ThermoPower.Choices.Flow1D.HCtypes;
+    // package SmoothMedium = Medium (final smoothModel=true);
+    constant SI.Pressure pzero = 10 "Small deltap for calculations";
+    constant Medium.AbsolutePressure pc = Medium.fluidConstants[1].criticalPressure;
+    constant SI.SpecificEnthalpy hzero = 1e-3 "Small value for deltah";
+    parameter SI.PerUnit wnm = 1e-3 "Maximum fraction of the nominal flow rate allowed as reverse flow";
+    parameter Boolean fixedMassFlowSimplified = false "Fix flow rate = wnom for simplified homotopy model";
+    // SmoothMedium.ThermodynamicState fluidState[N]
+    //   "Thermodynamic state of the fluid at the nodes";
+    Medium.ThermodynamicState fluidState[N] "Thermodynamic state of the fluid at the nodes";
+    Medium.SaturationProperties sat "Properties of saturated fluid";
+    SI.Length omega_hyd "Wet perimeter (single tube)";
+    SI.Pressure Dpfric "Pressure drop due to friction";
+    SI.Pressure Dpstat "Pressure drop due to static head";
+    Real Kf[N - 1] "Friction coefficient";
+    Real Kfl[N - 1] "Linear friction coefficient";
+    Real Cf[N - 1] "Fanning friction factor";
+    Real dwdt "Dynamic momentum term";
+    Medium.AbsolutePressure p(start = pstart) "Fluid pressure for property calculations";
+    /*, stateSelect=StateSelect.prefer*/
+    SI.Pressure dpf[N - 1] "Pressure drop due to friction between two nodes";
+    Medium.MassFlowRate w(start = wnom / Nt) "Mass flowrate (single tube)";
+    Medium.MassFlowRate wbar[N - 1](each start = wnom / Nt) "Average mass flow rates (single tube)";
+    SI.Power Q_single[N - 1] = heatTransfer.Qvol / Nt "Heat flows entering the volumes from the lateral boundary (single tube)";
+    SI.Velocity u[N] "Fluid velocity";
+    Medium.Temperature T[N] "Fluid temperature";
+    Medium.Temperature Ts "Saturated water temperature";
+    Medium.SpecificEnthalpy h[N](start = hstart) "Fluid specific enthalpy";
+    Medium.SpecificEnthalpy htilde[N - 1](start = hstart[2:N]) "Enthalpy state variables";
+    /*,each stateSelect=StateSelect.prefer*/
+    Medium.SpecificEnthalpy hl "Saturated liquid temperature";
+    Medium.SpecificEnthalpy hv "Saturated vapour temperature";
+    SI.PerUnit x[N] "Steam quality";
+    Medium.Density rho[N] "Fluid density";
+    Units.LiquidDensity rhol "Saturated liquid density";
+    Units.GasDensity rhov "Saturated vapour density";
+    SI.Mass M "Fluid mass";
+  protected
+    SI.DerEnthalpyByPressure dhldp "Derivative of saturated liquid enthalpy by pressure";
+    SI.DerEnthalpyByPressure dhvdp "Derivative of saturated vapour enthalpy by pressure";
+    Medium.Density rhobar[N - 1] "Fluid average density";
+    SI.DerDensityByPressure drdp[N] "Derivative of density by pressure";
+    SI.DerDensityByPressure drbdp[N - 1] "Derivative of average density by pressure";
+    SI.DerDensityByPressure drldp "Derivative of saturated liquid density by pressure";
+    SI.DerDensityByPressure drvdp "Derivative of saturated vapour density by pressure";
+    SI.SpecificVolume vbar[N - 1] "Average specific volume";
+    SI.DerDensityByEnthalpy drdh[N] "Derivative of density by enthalpy";
+    SI.DerDensityByEnthalpy drbdh1[N - 1] "Derivative of average density by left enthalpy";
+    SI.DerDensityByEnthalpy drbdh2[N - 1] "Derivative of average density by right enthalpy";
+    Real AA;
+    Real AA1;
+    SI.MassFlowRate dMdt[N - 1] "Derivative of fluid mass in each volume";
+  equation
+//All equations are referred to a single tube
+    omega_hyd = 4 * A / Dhyd;
+// Friction factor selection
+    for j in 1:N - 1 loop
+      if FFtype == FFtypes.Kfnom then
+        Kf[j] = Kfnom * Kfc / (N - 1);
+        Cf[j] = 2 * Kf[j] * A ^ 3 / (omega_hyd * l);
+      elseif FFtype == FFtypes.OpPoint then
+        Kf[j] = dpnom * rhonom / (wnom / Nt) ^ 2 / (N - 1) * Kfc;
+        Cf[j] = 2 * Kf[j] * A ^ 3 / (omega_hyd * l);
+      elseif FFtype == FFtypes.Cfnom then
+        Kf[j] = Cfnom * omega_hyd * l / (2 * A ^ 3) * Kfc;
+        Cf[j] = 2 * Kf[j] * A ^ 3 / (omega_hyd * l);
+      elseif FFtype == FFtypes.Colebrook then
+        Cf[j] = if noEvent(htilde[j] < hl or htilde[j] > hv) then f_colebrook(w, Dhyd / A, e, Medium.dynamicViscosity(fluidState[j])) * Kfc else f_colebrook_2ph(w, Dhyd / A, e, Medium.dynamicViscosity(Medium.setBubbleState(sat, 1)), Medium.dynamicViscosity(Medium.setDewState(sat, 1)), x[j]) * Kfc;
+        Kf[j] = Cf[j] * omega_hyd * l / (2 * A ^ 3);
+      elseif FFtype == FFtypes.NoFriction then
+        Cf[j] = 0;
+        Kf[j] = 0;
+      else
+        assert(FFtype <> FFtypes.NoFriction, "Unsupported FFtype");
+        Cf[j] = 0;
+        Kf[j] = 0;
+      end if;
+      assert(Kf[j] >= 0, "Negative friction coefficient");
+      Kfl[j] = wnom / Nt * wnf * Kf[j];
+    end for;
+// Dynamic momentum term
+    if DynamicMomentum then
+      dwdt = der(w);
+    else
+      dwdt = 0;
+    end if;
+    sum(dMdt) = infl.m_flow / Nt + outfl.m_flow / Nt "Mass balance";
+    sum(dpf) = Dpfric "Total pressure drop due to friction";
+    Dpstat = if abs(dzdx) < 1e-6 then 0 else g * l * dzdx * sum(rhobar) "Pressure drop due to static head";
+    L / A * dwdt + outfl.p - infl.p + Dpstat + Dpfric = 0 "Momentum balance";
+    for j in 1:N - 1 loop
+      A * l * rhobar[j] * der(htilde[j]) + wbar[j] * (h[j + 1] - h[j]) - A * l * der(p) = Q_single[j] "Energy balance";
+      dMdt[j] = A * l * (drbdh1[j] * der(h[j]) + drbdh2[j] * der(h[j + 1]) + drbdp[j] * der(p)) "Mass balance for each volume";
+// Average volume quantities
+      vbar[j] = 1 / rhobar[j] "Average specific volume";
+      if fixedMassFlowSimplified then
+        wbar[j] = homotopy(infl.m_flow / Nt - sum(dMdt[1:j - 1]) - dMdt[j] / 2, wnom / Nt);
+      else
+        wbar[j] = infl.m_flow / Nt - sum(dMdt[1:j - 1]) - dMdt[j] / 2;
+      end if;
+      dpf[j] = if FFtype == FFtypes.NoFriction then 0 else homotopy(smooth(1, Kf[j] * squareReg(w, wnom / Nt * wnf)) * vbar[j], dpnom / (N - 1) / (wnom / Nt) * w);
+      if avoidInletEnthalpyDerivative and j == 1 then
+// first volume properties computed by the outlet properties
+        rhobar[j] = rho[j + 1];
+        drbdp[j] = drdp[j + 1];
+        drbdh1[j] = 0;
+        drbdh2[j] = drdh[j + 1];
+      elseif noEvent(h[j] < hl and h[j + 1] < hl or h[j] > hv and h[j + 1] > hv or p >= pc - pzero or abs(h[j + 1] - h[j]) < hzero) then
+// 1-phase or almost uniform properties
+        rhobar[j] = (rho[j] + rho[j + 1]) / 2;
+        drbdp[j] = (drdp[j] + drdp[j + 1]) / 2;
+        drbdh1[j] = drdh[j] / 2;
+        drbdh2[j] = drdh[j + 1] / 2;
+      elseif noEvent(h[j] >= hl and h[j] <= hv and h[j + 1] >= hl and h[j + 1] <= hv) then
+// 2-phase
+        rhobar[j] = AA * log(rho[j] / rho[j + 1]) / (h[j + 1] - h[j]);
+        drbdp[j] = (AA1 * log(rho[j] / rho[j + 1]) + AA * (1 / rho[j] * drdp[j] - 1 / rho[j + 1] * drdp[j + 1])) / (h[j + 1] - h[j]);
+        drbdh1[j] = (rhobar[j] - rho[j]) / (h[j + 1] - h[j]);
+        drbdh2[j] = (rho[j + 1] - rhobar[j]) / (h[j + 1] - h[j]);
+      elseif noEvent(h[j] < hl and h[j + 1] >= hl and h[j + 1] <= hv) then
+// liquid/2-phase
+        rhobar[j] = ((rho[j] + rhol) * (hl - h[j]) / 2 + AA * log(rhol / rho[j + 1])) / (h[j + 1] - h[j]);
+        drbdp[j] = ((drdp[j] + drldp) * (hl - h[j]) / 2 + (rho[j] + rhol) / 2 * dhldp + AA1 * log(rhol / rho[j + 1]) + AA * (1 / rhol * drldp - 1 / rho[j + 1] * drdp[j + 1])) / (h[j + 1] - h[j]);
+        drbdh1[j] = (rhobar[j] - (rho[j] + rhol) / 2 + drdh[j] * (hl - h[j]) / 2) / (h[j + 1] - h[j]);
+        drbdh2[j] = (rho[j + 1] - rhobar[j]) / (h[j + 1] - h[j]);
+      elseif noEvent(h[j] >= hl and h[j] <= hv and h[j + 1] > hv) then
+// 2-phase/vapour
+        rhobar[j] = (AA * log(rho[j] / rhov) + (rhov + rho[j + 1]) * (h[j + 1] - hv) / 2) / (h[j + 1] - h[j]);
+        drbdp[j] = (AA1 * log(rho[j] / rhov) + AA * (1 / rho[j] * drdp[j] - 1 / rhov * drvdp) + (drvdp + drdp[j + 1]) * (h[j + 1] - hv) / 2 - (rhov + rho[j + 1]) / 2 * dhvdp) / (h[j + 1] - h[j]);
+        drbdh1[j] = (rhobar[j] - rho[j]) / (h[j + 1] - h[j]);
+        drbdh2[j] = ((rhov + rho[j + 1]) / 2 - rhobar[j] + drdh[j + 1] * (h[j + 1] - hv) / 2) / (h[j + 1] - h[j]);
+      elseif noEvent(h[j] < hl and h[j + 1] > hv) then
+// liquid/2-phase/vapour
+        rhobar[j] = ((rho[j] + rhol) * (hl - h[j]) / 2 + AA * log(rhol / rhov) + (rhov + rho[j + 1]) * (h[j + 1] - hv) / 2) / (h[j + 1] - h[j]);
+        drbdp[j] = ((drdp[j] + drldp) * (hl - h[j]) / 2 + (rho[j] + rhol) / 2 * dhldp + AA1 * log(rhol / rhov) + AA * (1 / rhol * drldp - 1 / rhov * drvdp) + (drvdp + drdp[j + 1]) * (h[j + 1] - hv) / 2 - (rhov + rho[j + 1]) / 2 * dhvdp) / (h[j + 1] - h[j]);
+        drbdh1[j] = (rhobar[j] - (rho[j] + rhol) / 2 + drdh[j] * (hl - h[j]) / 2) / (h[j + 1] - h[j]);
+        drbdh2[j] = ((rhov + rho[j + 1]) / 2 - rhobar[j] + drdh[j + 1] * (h[j + 1] - hv) / 2) / (h[j + 1] - h[j]);
+      elseif noEvent(h[j] >= hl and h[j] <= hv and h[j + 1] < hl) then
+// 2-phase/liquid
+        rhobar[j] = (AA * log(rho[j] / rhol) + (rhol + rho[j + 1]) * (h[j + 1] - hl) / 2) / (h[j + 1] - h[j]);
+        drbdp[j] = (AA1 * log(rho[j] / rhol) + AA * (1 / rho[j] * drdp[j] - 1 / rhol * drldp) + (drldp + drdp[j + 1]) * (h[j + 1] - hl) / 2 - (rhol + rho[j + 1]) / 2 * dhldp) / (h[j + 1] - h[j]);
+        drbdh1[j] = (rhobar[j] - rho[j]) / (h[j + 1] - h[j]);
+        drbdh2[j] = ((rhol + rho[j + 1]) / 2 - rhobar[j] + drdh[j + 1] * (h[j + 1] - hl) / 2) / (h[j + 1] - h[j]);
+      elseif noEvent(h[j] > hv and h[j + 1] < hl) then
+// vapour/2-phase/liquid
+        rhobar[j] = ((rho[j] + rhov) * (hv - h[j]) / 2 + AA * log(rhov / rhol) + (rhol + rho[j + 1]) * (h[j + 1] - hl) / 2) / (h[j + 1] - h[j]);
+        drbdp[j] = ((drdp[j] + drvdp) * (hv - h[j]) / 2 + (rho[j] + rhov) / 2 * dhvdp + AA1 * log(rhov / rhol) + AA * (1 / rhov * drvdp - 1 / rhol * drldp) + (drldp + drdp[j + 1]) * (h[j + 1] - hl) / 2 - (rhol + rho[j + 1]) / 2 * dhldp) / (h[j + 1] - h[j]);
+        drbdh1[j] = (rhobar[j] - (rho[j] + rhov) / 2 + drdh[j] * (hv - h[j]) / 2) / (h[j + 1] - h[j]);
+        drbdh2[j] = ((rhol + rho[j + 1]) / 2 - rhobar[j] + drdh[j + 1] * (h[j + 1] - hl) / 2) / (h[j + 1] - h[j]);
+      else
+// vapour/2-phase
+        rhobar[j] = ((rho[j] + rhov) * (hv - h[j]) / 2 + AA * log(rhov / rho[j + 1])) / (h[j + 1] - h[j]);
+        drbdp[j] = ((drdp[j] + drvdp) * (hv - h[j]) / 2 + (rho[j] + rhov) / 2 * dhvdp + AA1 * log(rhov / rho[j + 1]) + AA * (1 / rhov * drvdp - 1 / rho[j + 1] * drdp[j + 1])) / (h[j + 1] - h[j]);
+        drbdh1[j] = (rhobar[j] - (rho[j] + rhov) / 2 + drdh[j] * (hv - h[j]) / 2) / (h[j + 1] - h[j]);
+        drbdh2[j] = (rho[j + 1] - rhobar[j]) / (h[j + 1] - h[j]);
+      end if;
+    end for;
+// Saturated fluid property calculations
+    sat = Medium.setSat_p(p);
+    Ts = sat.Tsat;
+    rhol = Medium.bubbleDensity(sat);
+    rhov = Medium.dewDensity(sat);
+    hl = Medium.bubbleEnthalpy(sat);
+    hv = Medium.dewEnthalpy(sat);
+    drldp = Medium.dBubbleDensity_dPressure(sat);
+    drvdp = Medium.dDewDensity_dPressure(sat);
+    dhldp = Medium.dBubbleEnthalpy_dPressure(sat);
+    dhvdp = Medium.dDewEnthalpy_dPressure(sat);
+    AA = (hv - hl) / (1 / rhov - 1 / rhol);
+    AA1 = ((dhvdp - dhldp) * (rhol - rhov) * rhol * rhov - (hv - hl) * (rhov ^ 2 * drldp - rhol ^ 2 * drvdp)) / (rhol - rhov) ^ 2;
+// Fluid property calculations
+    for j in 1:N loop
+      fluidState[j] = Medium.setState_phX(p, h[j]);
+      T[j] = Medium.temperature(fluidState[j]);
+      rho[j] = Medium.density(fluidState[j]);
+      drdp[j] = Medium.density_derp_h(fluidState[j]);
+      drdh[j] = Medium.density_derh_p(fluidState[j]);
+      u[j] = w / (rho[j] * A);
+      x[j] = noEvent(if h[j] <= hl then 0 else if h[j] >= hv then 1 else (h[j] - hl) / (hv - hl));
+    end for;
+// Selection of representative pressure and flow rate variables
+    if HydraulicCapacitance == HCtypes.Upstream then
+      p = infl.p;
+      w = -outfl.m_flow / Nt;
+    else
+      p = outfl.p;
+      w = infl.m_flow / Nt;
+    end if;
+// Boundary conditions
+    infl.h_outflow = htilde[1];
+    outfl.h_outflow = htilde[N - 1];
+    h[1] = inStream(infl.h_outflow);
+    h[2:N] = htilde;
+    connect(wall, heatTransfer.wall);
+    Q = heatTransfer.Q "Total heat flow through lateral boundary";
+    M = sum(rhobar) * A * l "Fluid mass (single tube)";
+    Tr = noEvent(M / max(infl.m_flow / Nt, Modelica.Constants.eps)) "Residence time";
+    assert(infl.m_flow > (-wnom * wnm), "Reverse flow not allowed, maybe you connected the component with wrong orientation");
+  initial equation
+    if initOpt == Choices.Init.Options.noInit then
+// do nothing
+    elseif initOpt == Choices.Init.Options.fixedState then
+      if not noInitialPressure then
+        p = pstart;
+      end if;
+      htilde = hstart[2:N];
+    elseif initOpt == Choices.Init.Options.steadyState then
+      der(htilde) = zeros(N - 1);
+      if not Medium.singleState and not noInitialPressure then
+        der(p) = 0;
+      end if;
+    elseif initOpt == Choices.Init.Options.steadyStateNoP then
+      der(htilde) = zeros(N - 1);
+      assert(false, "initOpt = steadyStateNoP deprecated, use steadyState and noInitialPressure", AssertionLevel.warning);
+    elseif initOpt == Choices.Init.Options.steadyStateNoT and not Medium.singleState then
+      der(p) = 0;
+    else
+      assert(false, "Unsupported initialisation option");
+    end if;
+    annotation(
+      Diagram(graphics),
+      Icon(graphics = {Text(extent = {{-100, -60}, {100, -100}}, textString = "%name")}),
+      Documentation(info = "<HTML>
 <p>This model describes the flow of water or steam in a rigid tube. The basic modelling assumptions are:
 <ul><li>The fluid state is either one-phase, or a two-phase mixture.
 <li>In case of two-phase flow, the same velocity is assumed for both phases (homogeneous model).
@@ -1815,7 +1450,7 @@
 <p>Start values for pressure and flowrate are specified by <tt>pstart</tt>, <tt>wstart</tt>. The start values for the node enthalpies are linearly distributed from <tt>hstartin</tt> at the inlet to <tt>hstartout</tt> at the outlet.
 <p>A bank of <tt>Nt</tt> identical tubes working in parallel can be modelled by setting <tt>Nt > 1</tt>. The geometric parameters always refer to a <i>single</i> tube.
 <p>This models makes the temperature and external heat flow distributions visible through the <tt>wall</tt> connector. If other variables (e.g. the heat transfer coefficient) are needed by external components to compute the actual heat flow, the <tt>wall</tt> connector can be replaced by an extended version of the <tt>DHT</tt> connector.
-</HTML>", revisions="<html>
+</HTML>", revisions = "<html>
 <ul>
 <li><i>27 Jul 2007</i>
     by <a href=\"mailto:francesco.casella@polimi.it\">Francesco Casella</a>:<br>
@@ -1846,450 +1481,313 @@
     by <a href=\"mailto:francesco.casella@polimi.it\">Francesco Casella</a>:<br>
        First release.</li>
 </ul>
-</html>"));
-  end Flow1DFV2ph;
-
-  model Flow1DFV2ph2w
-    "Same as Flow1DFV with two walls and heat transfer models"
-    extends Flow1DFV2ph(
-      Q_single = heatTransfer.Qvol/Nt + heatTransfer2.Qvol/Nt);
-    replaceable model HeatTransfer2 = Thermal.HeatTransferFV.IdealHeatTransfer
-      constrainedby ThermoPower.Thermal.BaseClasses.DistributedHeatTransferFV
-      annotation (choicesAllMatching=true);
-    HeatTransfer heatTransfer2(
-      redeclare package Medium = Medium,
-      final Nf=N,
-      final Nw=Nw,
-      final Nt=Nt,
-      final L=L,
-      final A=A,
-      final Dhyd=Dhyd,
-      final omega=omega,
-      final wnom=wnom/Nt,
-      final w=w*ones(N),
-      final fluidState=fluidState) "Instantiated heat transfer model";
-
-    Thermal.DHTVolumes wall2(final N=Nw)
-      annotation (Placement(transformation(extent={{-60,-60},{60,-40}},rotation=0)));
-  equation
-    connect(wall2,heatTransfer2.wall);
-    annotation (Diagram(coordinateSystem(preserveAspectRatio=false, extent={{-100,
-              -100},{100,100}}), graphics), Icon(coordinateSystem(
-            preserveAspectRatio=false, extent={{-100,-100},{100,100}}), graphics));
-  end Flow1DFV2ph2w;
-
-  model Flow1DFEM
-    "1-dimensional fluid flow model for water/steam (finite elements)"
-    extends BaseClasses.Flow1DBase(Nw = N);
-    replaceable model HeatTransfer = Thermal.HeatTransferFEM.IdealHeatTransfer
-      constrainedby ThermoPower.Thermal.BaseClasses.DistributedHeatTransferFEM
-      annotation (choicesAllMatching=true);
-    HeatTransfer heatTransfer(
-      redeclare package Medium = Medium,
-      final Nf=N,
-      final Nw=Nw,
-      final Nt=Nt,
-      final L=L,
-      final A=A,
-      final Dhyd=Dhyd,
-      final omega=omega,
-      final wnom=wnom/Nt,
-      final w=w,
-      final fluidState=fluidState) "Instantiated heat transfer model";
-    ThermoPower.Thermal.DHTNodes wall(N=N) annotation (Dialog(enable=
-            false), Placement(transformation(extent={{-40,40},{40,60}},
-            rotation=0)));
-    import ThermoPower.Choices.Flow1D.FFtypes;
-    import ThermoPower.Choices.Flow1D.HCtypes;
-    Medium.ThermodynamicState fluidState[N]
-      "Thermodynamic state of the fluid at the nodes";
-    parameter SI.PerUnit alpha(
-      min=0,
-      max=1) = 1 "Numerical stabilization coefficient";
-    parameter SI.PerUnit ML(
-      min=0,
-      max=1) = 0 "Mass Lumping Coefficient";
-    parameter SI.PerUnit wnf_bc=0.01
-      "Fraction of the nominal total mass flow rate for boundary condition FEM regularization";
-    parameter SI.PerUnit wnf_alpha = 0.01
-      "Fraction of the nominal total mass flow rate for stabilization parameter regularization";
-    parameter Boolean regularizeBoundaryConditions = false
-      "Regularize boundary condition matrices";
-    parameter Boolean idealGasDensityDistribution = false
-      "Assume ideal-gas-type density distributions for mass balances";
-    constant SI.Acceleration g=Modelica.Constants.g_n;
-    final parameter Boolean evenN=(div(N, 2)*2 == N)
-      "The number of nodes is even";
-    SI.Length omega_hyd "Hydraulic perimeter (single tube)";
-    Real Kf[N] "Friction coefficients";
-    Real Cf[N] "Fanning friction factors";
-    Real dwdt "Dynamic momentum term";
-    Medium.AbsolutePressure p(start=pstart) "Fluid pressure";
-    SI.Pressure Dpfric "Pressure drop due to friction (total)";
-    SI.Pressure Dpfric1
-      "Pressure drop due to friction (from inlet to capacitance)";
-    SI.Pressure Dpfric2
-      "Pressure drop due to friction (from capacitance to outlet)";
-    SI.Pressure Dpstat "Pressure drop due to static head";
-    Medium.MassFlowRate w[N](each start=wnom/Nt) "Mass flowrate (single tube)";
-    SI.Velocity u[N] "Fluid velocity";
-    SI.HeatFlux phi[N] "Heat flux entering the fluid";
-    Medium.Temperature T[N] "Fluid temperature";
-    Medium.SpecificEnthalpy h[N](start=hstart) "Fluid specific enthalpy";
-    Medium.Density rho[N] "Fluid density";
-    SI.SpecificVolume v[N] "Fluid specific volume";
-    SI.Mass Mtot "Total mass of fluid";
-  protected
-    SI.DerDensityByEnthalpy drdh[N] "Derivative of density by enthalpy";
-    SI.DerDensityByPressure drdp[N] "Derivative of density by pressure";
-    Real dvdt[N] "Time derivatives of specific volume";
-
-    Real Y[N, N];
-    Real M[N, N];
-    Real D[N];
-    Real D1[N];
-    Real D2[N];
-    Real G[N];
-    Real B[N, N];
-    Real C[N, N];
-    Real K[N, N];
-
-    Real alpha_sgn[N];
-
-    Real YY[N, N];
-
-  equation
-    //All equations are referred to a single tube
-
-    // Selection of representative pressure variable
-    if HydraulicCapacitance == HCtypes.Middle then
-      p = infl.p - Dpfric1 - Dpstat/2;
-    elseif HydraulicCapacitance == HCtypes.Upstream then
-      p = infl.p;
-    elseif HydraulicCapacitance == HCtypes.Downstream then
-      p = outfl.p;
-    else
-      assert(false, "Unsupported HydraulicCapacitance option");
-    end if;
-
-    //Friction factor selection
-    omega_hyd = 4*A/Dhyd;
-    for i in 1:N loop
-      if FFtype == FFtypes.Kfnom then
-        Kf[i] = Kfnom*Kfc;
-      elseif FFtype == FFtypes.OpPoint then
-        Kf[i] = dpnom*rhonom/(wnom/Nt)^2*Kfc;
-      elseif FFtype == FFtypes.Cfnom then
-        Cf[i] = Cfnom*Kfc;
-      elseif FFtype == FFtypes.Colebrook then
-        Cf[i] = f_colebrook(
-            w[i],
-            Dhyd/A,
-            e,
-            Medium.dynamicViscosity(fluidState[i]))*Kfc;
-      elseif FFtype == FFtypes.NoFriction then
-        Cf[i] = 0;
-      end if;
-      assert(Kf[i] >= 0, "Negative friction coefficient");
-      Kf[i] = Cf[i]*omega_hyd*L/(2*A^3)
-        "Relationship between friction coefficient and Fanning friction factor";
-    end for;
-
-    //Dynamic Momentum [not] accounted for
-    if DynamicMomentum then
-      if HydraulicCapacitance == HCtypes.Upstream then
-        dwdt = der(w[N]);
-      elseif HydraulicCapacitance == HCtypes.Downstream then
-        dwdt = der(w[1]);
-      else
-        assert(false,
-          "DynamicMomentum == true requires either Upstream or Downstream capacitance");
-      end if;
-    else
-      dwdt = 0;
-    end if;
-
-    L/A*dwdt + (outfl.p - infl.p) + Dpstat + Dpfric = 0
-      "Momentum balance equation";
-
-    w[1] = infl.m_flow/Nt "Inlet flow rate - single tube";
-    w[N] = -outfl.m_flow/Nt "Outlet flow rate - single tube";
-
-    Dpfric = Dpfric1 + Dpfric2 "Total pressure drop due to friction";
-
-    if FFtype == FFtypes.NoFriction then
-      Dpfric1 = 0;
-      Dpfric2 = 0;
-    else
-      Dpfric1 = homotopy(sum(Kf[i]/L*squareReg(w[i], wnom/Nt*wnf)*D1[i]/rho[i]
-        for i in 1:N), dpnom/2/(wnom/Nt)*w[1])
-        "Pressure drop from inlet to capacitance";
-      Dpfric2 = homotopy(sum(Kf[i]/L*squareReg(w[i], wnom/Nt*wnf)*D2[i]/rho[i]
-        for i in 1:N), dpnom/2/(wnom/Nt)*w[N])
-        "Pressure drop from capacitance to outlet";
-    end if "Pressure drop due to friction";
-
-    Dpstat = if abs(dzdx) < 1e-6 then 0 else g*dzdx*rho*D
-      "Pressure drop due to static head";
-    ((1 - ML)*Y + ML*YY)*der(h) + B/A*h + C*h/A = der(p)*G + M*(omega/A)*phi +
-      K*w/A "Energy balance equation";
-
-    // Fluid property calculations
-    for j in 1:N loop
-      fluidState[j] = Medium.setState_phX(p, h[j]);
-      T[j] = Medium.temperature(fluidState[j]);
-      rho[j] = Medium.density(fluidState[j]);
-      drdp[j] = if Medium.singleState then 0 else Medium.density_derp_h(
-        fluidState[j]);
-      drdh[j] = Medium.density_derh_p(fluidState[j]);
-      dvdt[j] = -1/rho[j]^2*(drdp[j]*der(p) + drdh[j]*der(h[j]));
-      v[j] = 1/rho[j];
-      u[j] = w[j]/(rho[j]*A);
-    end for;
-
-    //Boundary Values of outflowing fluid enthalpies
-    h[1] = infl.h_outflow;
-    h[N] = outfl.h_outflow;
-
-    // Boundary values of heat flux
-    phi = heatTransfer.phi_f;
-
-    // Stabilization parameters depending of flow direction
-    for i in 1:N loop
-      alpha_sgn[i] = alpha*tanh(w[i]/(wnf_alpha*wnom/Nt));
-    end for;
-
-    for i in 1:N - 1 loop
-      if idealGasDensityDistribution then
-        (w[i + 1] - w[i]) = noEvent(
-          if abs((v[i+1]-v[i])/v[i]) < 1e-7 then
-             2*A*l/(v[i]+v[i+1])^2*(dvdt[i]+dvdt[i+1])
-          else
-             -A*l/(v[i+1]-v[i])*(
-              (dvdt[i+1]*v[i]-dvdt[i]*v[i+1])/(v[i+1]*v[i]) -
-              (dvdt[i+1]-dvdt[i])/(v[i+1]-v[i])*log(v[i+1]/v[i])))
-          "Mass balance equations";
-      else
-      (w[i + 1] - w[i]) = -A*l*(
-        der(p)*1/2*(drdp[i + 1] + drdp[i]) +
-        1/6*(der(h[i])*(2*drdh[i] + drdh[i + 1]) +
-             der(h[i + 1])*(drdh[i] + 2*drdh[i + 1]))) "Mass balance equations";
-      end if;
-    end for;
-
-    // Energy equation FEM matrices
-    Y[1, 1] =   rho[1]*  (l/12)*(3 - 2*alpha_sgn[1]) +
-                rho[2]*  (l/12)*(1 - alpha_sgn[1]);
-    Y[1, 2] =   rho[1]*  (l/12)*(1 - alpha_sgn[1]) +
-                rho[2]*  (l/12)*(1 - 2*alpha_sgn[1]);
-    Y[N, N-1] = rho[N-1]*(l/12)*(1 + 2*alpha_sgn[N]) +
-                rho[N]*  (l/12)*(1 + alpha_sgn[N]);
-    Y[N, N] =   rho[N-1]*(l/12)*(1 + alpha_sgn[N]) +
-                rho[N]*  (l/12)*(3 + 2*alpha_sgn[N]);
-    if N > 2 then
-      for i in 2:N - 1 loop
-        Y[i, i-1] = rho[i-1]*(l/12)*(1 + 2*alpha_sgn[i]) +
-                    rho[i]*  (l/12)*(1 + alpha_sgn[i]);
-        Y[i, i]   = rho[i-1]*(l/12)*(1 + alpha_sgn[i]) +
-                    rho[i]*  (l/12)*6 +
-                    rho[i+1]*(l/12)*(1 - alpha_sgn[i]);
-        Y[i, i+1] = rho[i]*  (l/12)*(1 - alpha_sgn[i]) +
-                    rho[i+1]*(l/12)*(1 - 2*alpha_sgn[i]);
-        Y[1, i+1] = 0;
-        Y[N, i-1] = 0;
-        for j in 1:(i - 2) loop
-          Y[i, j] = 0;
-        end for;
-        for j in (i + 2):N loop
-          Y[i, j] = 0;
-        end for;
-      end for;
-    end if;
-
-    for i in 1:N loop
-      for j in 1:N loop
-        YY[i, j] = if (i <> j) then 0 else sum(Y[:, j]);
-      end for;
-    end for;
-
-    M[1, 1]   = (4 - 3*alpha_sgn[1])*l/12;
-    M[1, 2]   = (2 - 3*alpha_sgn[1])*l/12;
-    M[N, N-1] = (2 + 3*alpha_sgn[N])*l/12;
-    M[N, N]   = (4 + 3*alpha_sgn[N])*l/12;
-    if N > 2 then
-      for i in 2:N - 1 loop
-        M[i, i-1] = (2 + 3*alpha_sgn[i])*l/12;
-        M[i, i]   = 8*l/12;
-        M[i, i+1] = (2 - 3*alpha_sgn[i])*l/12;
-        M[1, i+1] = 0;
-        M[N, i-1] = 0;
-        for j in 1:(i - 2) loop
-          M[i, j] = 0;
-        end for;
-        for j in (i + 2):N loop
-          M[i, j] = 0;
-        end for;
-      end for;
-    end if;
-
-    B[1, 1] =   (w[1]*   (3*alpha_sgn[1] - 4) + w[2]*(3*alpha_sgn[1] - 2))/12;
-    B[1, 2] =   (w[1]*   (4 - 3*alpha_sgn[1]) + w[2]*(2 - 3*alpha_sgn[1]))/12;
-    B[N, N] =   (w[N-1]* (2 + 3*alpha_sgn[N]) + w[N]*(4 + 3*alpha_sgn[N]))/12;
-    B[N, N-1] = (-w[N-1]*(2 + 3*alpha_sgn[N]) - w[N]*(4 + 3*alpha_sgn[N]))/12;
-    if N > 2 then
-      for i in 2:N - 1 loop
-        B[i, i-1] = (-w[i-1]*(2 + 3*alpha_sgn[i])  - w[i]*(4 + 3*alpha_sgn[i]))/12;
-        B[i, i]   = (w[i-1] *(2 + 3* alpha_sgn[i]) + w[i]*6*alpha_sgn[i] +
-                     w[i+1] *(3*alpha_sgn[i] - 2))/12;
-        B[i, i+1] = (w[i]*(4 - 3*alpha_sgn[i]) + w[i+1]*(2 - 3*alpha_sgn[i]))/12;
-        B[1, i+1] = 0;
-        B[N, i-1] = 0;
-        for j in 1:(i - 2) loop
-          B[i, j] = 0;
-        end for;
-        for j in (i + 2):N loop
-          B[i, j] = 0;
-        end for;
-      end for;
-    end if;
-
-    if Medium.singleState then
-      G = zeros(N) "No influence of pressure";
-    else
-      G[1] = l/2*(1 - alpha_sgn[1]);
-      G[N] = l/2*(1 + alpha_sgn[1]);
-      if N > 2 then
-        for i in 2:N - 1 loop
-          G[i] = l;
-        end for;
-      end if;
-    end if;
-
-    // boundary condition matrices
-    if regularizeBoundaryConditions then
-      C[1, 1] = Functions.stepReg(
-        infl.m_flow - wnom*wnf_bc,
-        (1 - alpha_sgn[1]/2)*w[1],
-        0,
-        wnom*wnf_bc);
-      C[N, N] = Functions.stepReg(
-        outfl.m_flow - wnom*wnf_bc,
-        -(1 + alpha_sgn[N]/2)*w[N],
-        0,
-        wnom*wnf_bc);
-    else
-      C[1, 1] = noEvent(if infl.m_flow >= 0 then (1 - alpha_sgn[1]/2)*w[1] else 0);
-      C[N, N] = noEvent(if outfl.m_flow >= 0 then -(1 + alpha_sgn[N]/2)*w[N] else 0);
-    end if;
-    C[N, 1] = 0;
-    C[1, N] = 0;
-    if (N > 2) then
-      for i in 2:(N - 1) loop
-        C[1, i] = 0;
-        C[N, i] = 0;
-        for j in 1:N loop
-          C[i, j] = 0;
-        end for;
-      end for;
-    end if;
-
-    if regularizeBoundaryConditions then
-      K[1, 1] = Functions.stepReg(
-        infl.m_flow - wnom*wnf_bc,
-        (1 - alpha_sgn[1]/2)*inStream(infl.h_outflow),
-        0,
-        wnom*wnf_bc);
-      K[N, N] = Functions.stepReg(
-        outfl.m_flow - wnom*wnf_bc,
-        -(1 + alpha_sgn[N]/2)*inStream(outfl.h_outflow),
-        0,
-        wnom*wnf_bc);
-    else
-      K[1, 1] = noEvent(if infl.m_flow >= 0 then (1 - alpha_sgn[1]/2)*inStream(infl.h_outflow) else 0);
-      K[N, N] = noEvent(if outfl.m_flow >= 0 then -(1 + alpha_sgn[N]/2)*inStream(outfl.h_outflow) else 0);
-    end if;
-    K[N, 1] = 0;
-    K[1, N] = 0;
-    if (N > 2) then
-      for i in 2:(N - 1) loop
-        K[1, i] = 0;
-        K[N, i] = 0;
-        for j in 1:N loop
-          K[i, j] = 0;
-        end for;
-      end for;
-    end if;
-
-    // Momentum and Mass balance equation matrices
-    D[1] = l/2;
-    D[N] = l/2;
-    for i in 2:N - 1 loop
-      D[i] = l;
-    end for;
-    if HydraulicCapacitance == HCtypes.Middle then
-      D1 = l*(if N == 2 then {3/8,1/8} else if evenN then cat(
-          1,
-          {1/2},
-          ones(max(0, div(N, 2) - 2)),
-          {7/8,1/8},
-          zeros(div(N, 2) - 1)) else cat(
-          1,
-          {1/2},
-          ones(div(N, 2) - 1),
-          {1/2},
-          zeros(div(N, 2))));
-      D2 = l*(if N == 2 then {1/8,3/8} else if evenN then cat(
-          1,
-          zeros(div(N, 2) - 1),
-          {1/8,7/8},
-          ones(max(div(N, 2) - 2, 0)),
-          {1/2}) else cat(
-          1,
-          zeros(div(N, 2)),
-          {1/2},
-          ones(div(N, 2) - 1),
-          {1/2}));
-    elseif HydraulicCapacitance == HCtypes.Upstream then
-      D1 = zeros(N);
-      D2 = D;
-    elseif HydraulicCapacitance == HCtypes.Downstream then
-      D1 = D;
-      D2 = zeros(N);
-    else
-      assert(false, "Unsupported HydraulicCapacitance option");
-    end if;
-
-    connect(wall,heatTransfer.wall);
-
-    Q = Nt*omega*D*phi "Total heat flow through lateral boundary";
-    Mtot = Nt*D*rho*A "Total mass of fluid";
-    Tr = noEvent(Mtot/max(abs(infl.m_flow), Modelica.Constants.eps))
-      "Residence time";
-  initial equation
-    if initOpt == Choices.Init.Options.noInit then
-      // do nothing
-    elseif initOpt == Choices.Init.Options.fixedState then
-      if not noInitialPressure then
-        p = pstart;
-      end if;
-      h = hstart;
-    elseif initOpt == Choices.Init.Options.steadyState then
-      der(h) = zeros(N);
-      if (not Medium.singleState) and not noInitialPressure then
-        der(p) = 0;
-      end if;
-    elseif initOpt == Choices.Init.Options.steadyStateNoP then
-      der(h) = zeros(N);
-      assert(false, "initOpt = steadyStateNoP deprecated, use steadyState and noInitialPressure",AssertionLevel.warning);
-    elseif initOpt == Choices.Init.Options.steadyStateNoT and not Medium.singleState then
-      der(p) = 0;
-    else
-      assert(false, "Unsupported initialisation option");
-    end if;
-    annotation (
-      Diagram(graphics),
-      Icon(graphics={Text(extent={{-100,-60},{100,-100}},textString="%name")}),
-      Documentation(info="<HTML>
+</html>"));
+  end Flow1DFV2ph;
+
+  model Flow1DFV2ph2w "Same as Flow1DFV with two walls and heat transfer models"
+    extends Flow1DFV2ph(Q_single = heatTransfer.Qvol / Nt + heatTransfer2.Qvol / Nt);
+    replaceable model HeatTransfer2 = Thermal.HeatTransferFV.IdealHeatTransfer constrainedby ThermoPower.Thermal.BaseClasses.DistributedHeatTransferFV annotation(
+       choicesAllMatching = true);
+    HeatTransfer heatTransfer2(redeclare package Medium = Medium, final Nf = N, final Nw = Nw, final Nt = Nt, final L = L, final A = A, final Dhyd = Dhyd, final omega = omega, final wnom = wnom / Nt, final w = w * ones(N), final fluidState = fluidState) "Instantiated heat transfer model";
+    Thermal.DHTVolumes wall2(final N = Nw) annotation(
+      Placement(transformation(extent = {{-60, -60}, {60, -40}}, rotation = 0)));
+  equation
+    connect(wall2, heatTransfer2.wall);
+    annotation(
+      Diagram(coordinateSystem(preserveAspectRatio = false, extent = {{-100, -100}, {100, 100}}), graphics),
+      Icon(coordinateSystem(preserveAspectRatio = false, extent = {{-100, -100}, {100, 100}}), graphics));
+  end Flow1DFV2ph2w;
+
+  model Flow1DFEM "1-dimensional fluid flow model for water/steam (finite elements)"
+    extends BaseClasses.Flow1DBase(Nw = N);
+    replaceable model HeatTransfer = Thermal.HeatTransferFEM.IdealHeatTransfer constrainedby ThermoPower.Thermal.BaseClasses.DistributedHeatTransferFEM annotation(
+       choicesAllMatching = true);
+    HeatTransfer heatTransfer(redeclare package Medium = Medium, final Nf = N, final Nw = Nw, final Nt = Nt, final L = L, final A = A, final Dhyd = Dhyd, final omega = omega, final wnom = wnom / Nt, final w = w, final fluidState = fluidState) "Instantiated heat transfer model";
+    ThermoPower.Thermal.DHTNodes wall(N = N) annotation(
+      Dialog(enable = false),
+      Placement(transformation(extent = {{-40, 40}, {40, 60}}, rotation = 0)));
+    import ThermoPower.Choices.Flow1D.FFtypes;
+    import ThermoPower.Choices.Flow1D.HCtypes;
+    Medium.ThermodynamicState fluidState[N] "Thermodynamic state of the fluid at the nodes";
+    parameter SI.PerUnit alpha(min = 0, max = 1) = 1 "Numerical stabilization coefficient";
+    parameter SI.PerUnit ML(min = 0, max = 1) = 0 "Mass Lumping Coefficient";
+    parameter SI.PerUnit wnf_bc = 0.01 "Fraction of the nominal total mass flow rate for boundary condition FEM regularization";
+    parameter SI.PerUnit wnf_alpha = 0.01 "Fraction of the nominal total mass flow rate for stabilization parameter regularization";
+    parameter Boolean regularizeBoundaryConditions = false "Regularize boundary condition matrices";
+    parameter Boolean idealGasDensityDistribution = false "Assume ideal-gas-type density distributions for mass balances";
+    constant SI.Acceleration g = Modelica.Constants.g_n;
+    final parameter Boolean evenN = div(N, 2) * 2 == N "The number of nodes is even";
+    SI.Length omega_hyd "Hydraulic perimeter (single tube)";
+    Real Kf[N] "Friction coefficients";
+    Real Cf[N] "Fanning friction factors";
+    Real dwdt "Dynamic momentum term";
+    Medium.AbsolutePressure p(start = pstart) "Fluid pressure";
+    SI.Pressure Dpfric "Pressure drop due to friction (total)";
+    SI.Pressure Dpfric1 "Pressure drop due to friction (from inlet to capacitance)";
+    SI.Pressure Dpfric2 "Pressure drop due to friction (from capacitance to outlet)";
+    SI.Pressure Dpstat "Pressure drop due to static head";
+    Medium.MassFlowRate w[N](each start = wnom / Nt) "Mass flowrate (single tube)";
+    SI.Velocity u[N] "Fluid velocity";
+    SI.HeatFlux phi[N] "Heat flux entering the fluid";
+    Medium.Temperature T[N] "Fluid temperature";
+    Medium.SpecificEnthalpy h[N](start = hstart) "Fluid specific enthalpy";
+    Medium.Density rho[N] "Fluid density";
+    SI.SpecificVolume v[N] "Fluid specific volume";
+    SI.Mass Mtot "Total mass of fluid";
+  protected
+    SI.DerDensityByEnthalpy drdh[N] "Derivative of density by enthalpy";
+    SI.DerDensityByPressure drdp[N] "Derivative of density by pressure";
+    Real dvdt[N] "Time derivatives of specific volume";
+    Real Y[N, N];
+    Real M[N, N];
+    Real D[N];
+    Real D1[N];
+    Real D2[N];
+    Real G[N];
+    Real B[N, N];
+    Real C[N, N];
+    Real K[N, N];
+    Real alpha_sgn[N];
+    Real YY[N, N];
+  equation
+//All equations are referred to a single tube
+// Selection of representative pressure variable
+    if HydraulicCapacitance == HCtypes.Middle then
+      p = infl.p - Dpfric1 - Dpstat / 2;
+    elseif HydraulicCapacitance == HCtypes.Upstream then
+      p = infl.p;
+    elseif HydraulicCapacitance == HCtypes.Downstream then
+      p = outfl.p;
+    else
+      assert(false, "Unsupported HydraulicCapacitance option");
+    end if;
+//Friction factor selection
+    omega_hyd = 4 * A / Dhyd;
+    for i in 1:N loop
+      if FFtype == FFtypes.Kfnom then
+        Kf[i] = Kfnom * Kfc;
+      elseif FFtype == FFtypes.OpPoint then
+        Kf[i] = dpnom * rhonom / (wnom / Nt) ^ 2 * Kfc;
+      elseif FFtype == FFtypes.Cfnom then
+        Cf[i] = Cfnom * Kfc;
+      elseif FFtype == FFtypes.Colebrook then
+        Cf[i] = f_colebrook(w[i], Dhyd / A, e, Medium.dynamicViscosity(fluidState[i])) * Kfc;
+      elseif FFtype == FFtypes.NoFriction then
+        Cf[i] = 0;
+      end if;
+      assert(Kf[i] >= 0, "Negative friction coefficient");
+      Kf[i] = Cf[i] * omega_hyd * L / (2 * A ^ 3) "Relationship between friction coefficient and Fanning friction factor";
+    end for;
+//Dynamic Momentum [not] accounted for
+    if DynamicMomentum then
+      if HydraulicCapacitance == HCtypes.Upstream then
+        dwdt = der(w[N]);
+      elseif HydraulicCapacitance == HCtypes.Downstream then
+        dwdt = der(w[1]);
+      else
+        assert(false, "DynamicMomentum == true requires either Upstream or Downstream capacitance");
+      end if;
+    else
+      dwdt = 0;
+    end if;
+    L / A * dwdt + outfl.p - infl.p + Dpstat + Dpfric = 0 "Momentum balance equation";
+    w[1] = infl.m_flow / Nt "Inlet flow rate - single tube";
+    w[N] = -outfl.m_flow / Nt "Outlet flow rate - single tube";
+    Dpfric = Dpfric1 + Dpfric2 "Total pressure drop due to friction";
+    if FFtype == FFtypes.NoFriction then
+      Dpfric1 = 0;
+      Dpfric2 = 0;
+    else
+      Dpfric1 = homotopy(sum(Kf[i] / L * squareReg(w[i], wnom / Nt * wnf) * D1[i] / rho[i] for i in 1:N), dpnom / 2 / (wnom / Nt) * w[1]) "Pressure drop from inlet to capacitance";
+      Dpfric2 = homotopy(sum(Kf[i] / L * squareReg(w[i], wnom / Nt * wnf) * D2[i] / rho[i] for i in 1:N), dpnom / 2 / (wnom / Nt) * w[N]) "Pressure drop from capacitance to outlet";
+    end if "Pressure drop due to friction";
+    Dpstat = if abs(dzdx) < 1e-6 then 0 else g * dzdx * rho * D "Pressure drop due to static head";
+    ((1 - ML) * Y + ML * YY) * der(h) + B / A * h + C * h / A = der(p) * G + M * (omega / A) * phi + K * w / A "Energy balance equation";
+// Fluid property calculations
+    for j in 1:N loop
+      fluidState[j] = Medium.setState_phX(p, h[j]);
+      T[j] = Medium.temperature(fluidState[j]);
+      rho[j] = Medium.density(fluidState[j]);
+      drdp[j] = if Medium.singleState then 0 else Medium.density_derp_h(fluidState[j]);
+      drdh[j] = Medium.density_derh_p(fluidState[j]);
+      dvdt[j] = -1 / rho[j] ^ 2 * (drdp[j] * der(p) + drdh[j] * der(h[j]));
+      v[j] = 1 / rho[j];
+      u[j] = w[j] / (rho[j] * A);
+    end for;
+//Boundary Values of outflowing fluid enthalpies
+    h[1] = infl.h_outflow;
+    h[N] = outfl.h_outflow;
+// Boundary values of heat flux
+    phi = heatTransfer.phi_f;
+// Stabilization parameters depending of flow direction
+    for i in 1:N loop
+      alpha_sgn[i] = alpha * tanh(w[i] / (wnf_alpha * wnom / Nt));
+    end for;
+    for i in 1:N - 1 loop
+      if idealGasDensityDistribution then
+        w[i + 1] - w[i] = noEvent(if abs((v[i + 1] - v[i]) / v[i]) < 1e-7 then 2 * A * l / (v[i] + v[i + 1]) ^ 2 * (dvdt[i] + dvdt[i + 1]) else -A * l / (v[i + 1] - v[i]) * ((dvdt[i + 1] * v[i] - dvdt[i] * v[i + 1]) / (v[i + 1] * v[i]) - (dvdt[i + 1] - dvdt[i]) / (v[i + 1] - v[i]) * log(v[i + 1] / v[i]))) "Mass balance equations";
+      else
+        w[i + 1] - w[i] = -A * l * (der(p) * 1 / 2 * (drdp[i + 1] + drdp[i]) + 1 / 6 * (der(h[i]) * (2 * drdh[i] + drdh[i + 1]) + der(h[i + 1]) * (drdh[i] + 2 * drdh[i + 1]))) "Mass balance equations";
+      end if;
+    end for;
+// Energy equation FEM matrices
+    Y[1, 1] = rho[1] * (l / 12) * (3 - 2 * alpha_sgn[1]) + rho[2] * (l / 12) * (1 - alpha_sgn[1]);
+    Y[1, 2] = rho[1] * (l / 12) * (1 - alpha_sgn[1]) + rho[2] * (l / 12) * (1 - 2 * alpha_sgn[1]);
+    Y[N, N - 1] = rho[N - 1] * (l / 12) * (1 + 2 * alpha_sgn[N]) + rho[N] * (l / 12) * (1 + alpha_sgn[N]);
+    Y[N, N] = rho[N - 1] * (l / 12) * (1 + alpha_sgn[N]) + rho[N] * (l / 12) * (3 + 2 * alpha_sgn[N]);
+    if N > 2 then
+      for i in 2:N - 1 loop
+        Y[i, i - 1] = rho[i - 1] * (l / 12) * (1 + 2 * alpha_sgn[i]) + rho[i] * (l / 12) * (1 + alpha_sgn[i]);
+        Y[i, i] = rho[i - 1] * (l / 12) * (1 + alpha_sgn[i]) + rho[i] * (l / 12) * 6 + rho[i + 1] * (l / 12) * (1 - alpha_sgn[i]);
+        Y[i, i + 1] = rho[i] * (l / 12) * (1 - alpha_sgn[i]) + rho[i + 1] * (l / 12) * (1 - 2 * alpha_sgn[i]);
+        Y[1, i + 1] = 0;
+        Y[N, i - 1] = 0;
+        for j in 1:i - 2 loop
+          Y[i, j] = 0;
+        end for;
+        for j in i + 2:N loop
+          Y[i, j] = 0;
+        end for;
+      end for;
+    end if;
+    for i in 1:N loop
+      for j in 1:N loop
+        YY[i, j] = if i <> j then 0 else sum(Y[:, j]);
+      end for;
+    end for;
+    M[1, 1] = (4 - 3 * alpha_sgn[1]) * l / 12;
+    M[1, 2] = (2 - 3 * alpha_sgn[1]) * l / 12;
+    M[N, N - 1] = (2 + 3 * alpha_sgn[N]) * l / 12;
+    M[N, N] = (4 + 3 * alpha_sgn[N]) * l / 12;
+    if N > 2 then
+      for i in 2:N - 1 loop
+        M[i, i - 1] = (2 + 3 * alpha_sgn[i]) * l / 12;
+        M[i, i] = 8 * l / 12;
+        M[i, i + 1] = (2 - 3 * alpha_sgn[i]) * l / 12;
+        M[1, i + 1] = 0;
+        M[N, i - 1] = 0;
+        for j in 1:i - 2 loop
+          M[i, j] = 0;
+        end for;
+        for j in i + 2:N loop
+          M[i, j] = 0;
+        end for;
+      end for;
+    end if;
+    B[1, 1] = (w[1] * (3 * alpha_sgn[1] - 4) + w[2] * (3 * alpha_sgn[1] - 2)) / 12;
+    B[1, 2] = (w[1] * (4 - 3 * alpha_sgn[1]) + w[2] * (2 - 3 * alpha_sgn[1])) / 12;
+    B[N, N] = (w[N - 1] * (2 + 3 * alpha_sgn[N]) + w[N] * (4 + 3 * alpha_sgn[N])) / 12;
+    B[N, N - 1] = ((-w[N - 1] * (2 + 3 * alpha_sgn[N])) - w[N] * (4 + 3 * alpha_sgn[N])) / 12;
+    if N > 2 then
+      for i in 2:N - 1 loop
+        B[i, i - 1] = ((-w[i - 1] * (2 + 3 * alpha_sgn[i])) - w[i] * (4 + 3 * alpha_sgn[i])) / 12;
+        B[i, i] = (w[i - 1] * (2 + 3 * alpha_sgn[i]) + w[i] * 6 * alpha_sgn[i] + w[i + 1] * (3 * alpha_sgn[i] - 2)) / 12;
+        B[i, i + 1] = (w[i] * (4 - 3 * alpha_sgn[i]) + w[i + 1] * (2 - 3 * alpha_sgn[i])) / 12;
+        B[1, i + 1] = 0;
+        B[N, i - 1] = 0;
+        for j in 1:i - 2 loop
+          B[i, j] = 0;
+        end for;
+        for j in i + 2:N loop
+          B[i, j] = 0;
+        end for;
+      end for;
+    end if;
+    if Medium.singleState then
+      G = zeros(N) "No influence of pressure";
+    else
+      G[1] = l / 2 * (1 - alpha_sgn[1]);
+      G[N] = l / 2 * (1 + alpha_sgn[1]);
+      if N > 2 then
+        for i in 2:N - 1 loop
+          G[i] = l;
+        end for;
+      end if;
+    end if;
+// boundary condition matrices
+    if regularizeBoundaryConditions then
+      C[1, 1] = Functions.stepReg(infl.m_flow - wnom * wnf_bc, (1 - alpha_sgn[1] / 2) * w[1], 0, wnom * wnf_bc);
+      C[N, N] = Functions.stepReg(outfl.m_flow - wnom * wnf_bc, -(1 + alpha_sgn[N] / 2) * w[N], 0, wnom * wnf_bc);
+    else
+      C[1, 1] = noEvent(if infl.m_flow >= 0 then (1 - alpha_sgn[1] / 2) * w[1] else 0);
+      C[N, N] = noEvent(if outfl.m_flow >= 0 then -(1 + alpha_sgn[N] / 2) * w[N] else 0);
+    end if;
+    C[N, 1] = 0;
+    C[1, N] = 0;
+    if N > 2 then
+      for i in 2:N - 1 loop
+        C[1, i] = 0;
+        C[N, i] = 0;
+        for j in 1:N loop
+          C[i, j] = 0;
+        end for;
+      end for;
+    end if;
+    if regularizeBoundaryConditions then
+      K[1, 1] = Functions.stepReg(infl.m_flow - wnom * wnf_bc, (1 - alpha_sgn[1] / 2) * inStream(infl.h_outflow), 0, wnom * wnf_bc);
+      K[N, N] = Functions.stepReg(outfl.m_flow - wnom * wnf_bc, -(1 + alpha_sgn[N] / 2) * inStream(outfl.h_outflow), 0, wnom * wnf_bc);
+    else
+      K[1, 1] = noEvent(if infl.m_flow >= 0 then (1 - alpha_sgn[1] / 2) * inStream(infl.h_outflow) else 0);
+      K[N, N] = noEvent(if outfl.m_flow >= 0 then -(1 + alpha_sgn[N] / 2) * inStream(outfl.h_outflow) else 0);
+    end if;
+    K[N, 1] = 0;
+    K[1, N] = 0;
+    if N > 2 then
+      for i in 2:N - 1 loop
+        K[1, i] = 0;
+        K[N, i] = 0;
+        for j in 1:N loop
+          K[i, j] = 0;
+        end for;
+      end for;
+    end if;
+// Momentum and Mass balance equation matrices
+    D[1] = l / 2;
+    D[N] = l / 2;
+    for i in 2:N - 1 loop
+      D[i] = l;
+    end for;
+    if HydraulicCapacitance == HCtypes.Middle then
+      D1 = l * (if N == 2 then {3 / 8, 1 / 8} else if evenN then cat(1, {1 / 2}, ones(max(0, div(N, 2) - 2)), {7 / 8, 1 / 8}, zeros(div(N, 2) - 1)) else cat(1, {1 / 2}, ones(div(N, 2) - 1), {1 / 2}, zeros(div(N, 2))));
+      D2 = l * (if N == 2 then {1 / 8, 3 / 8} else if evenN then cat(1, zeros(div(N, 2) - 1), {1 / 8, 7 / 8}, ones(max(div(N, 2) - 2, 0)), {1 / 2}) else cat(1, zeros(div(N, 2)), {1 / 2}, ones(div(N, 2) - 1), {1 / 2}));
+    elseif HydraulicCapacitance == HCtypes.Upstream then
+      D1 = zeros(N);
+      D2 = D;
+    elseif HydraulicCapacitance == HCtypes.Downstream then
+      D1 = D;
+      D2 = zeros(N);
+    else
+      assert(false, "Unsupported HydraulicCapacitance option");
+    end if;
+    connect(wall, heatTransfer.wall);
+    Q = Nt * omega * D * phi "Total heat flow through lateral boundary";
+    Mtot = Nt * D * rho * A "Total mass of fluid";
+    Tr = noEvent(Mtot / max(abs(infl.m_flow), Modelica.Constants.eps)) "Residence time";
+  initial equation
+    if initOpt == Choices.Init.Options.noInit then
+// do nothing
+    elseif initOpt == Choices.Init.Options.fixedState then
+      if not noInitialPressure then
+        p = pstart;
+      end if;
+      h = hstart;
+    elseif initOpt == Choices.Init.Options.steadyState then
+      der(h) = zeros(N);
+      if not Medium.singleState and not noInitialPressure then
+        der(p) = 0;
+      end if;
+    elseif initOpt == Choices.Init.Options.steadyStateNoP then
+      der(h) = zeros(N);
+      assert(false, "initOpt = steadyStateNoP deprecated, use steadyState and noInitialPressure", AssertionLevel.warning);
+    elseif initOpt == Choices.Init.Options.steadyStateNoT and not Medium.singleState then
+      der(p) = 0;
+    else
+      assert(false, "Unsupported initialisation option");
+    end if;
+    annotation(
+      Diagram(graphics),
+      Icon(graphics = {Text(extent = {{-100, -60}, {100, -100}}, textString = "%name")}),
+      Documentation(info = "<HTML>
 <p>This model describes the flow of water or steam in a rigid tube. The basic modelling assumptions are:
 <ul><li>The fluid state is always one-phase (i.e. subcooled liquid or superheated steam).
 <li>Uniform velocity is assumed on the cross section, leading to a 1-D distributed parameter model.
@@ -2317,7 +1815,7 @@
 <p>Start values for pressure and flowrate are specified by <tt>pstart</tt>, <tt>wstart</tt>. The start values for the node enthalpies are linearly distributed from <tt>hstartin</tt> at the inlet to <tt>hstartout</tt> at the outlet.
 <p>A bank of <tt>Nt</tt> identical tubes working in parallel can be modelled by setting <tt>Nt > 1</tt>. The geometric parameters always refer to a <i>single</i> tube.
 <p>This models makes the temperature and external heat flow distributions visible through the <tt>wall</tt> connector. If other variables (e.g. the heat transfer coefficient) are needed by external components to compute the actual heat flow, the <tt>wall</tt> connector can be replaced by an extended version of the <tt>DHT</tt> connector.
-</HTML>", revisions="<html>
+</HTML>", revisions = "<html>
 <ul>
 <li><i>24 Mar 2005</i>
     by <a href=\"mailto:francesco.casella@polimi.it\">Francesco Casella</a>:<br>
@@ -2347,730 +1845,526 @@
     by <a href=\"mailto:francesco.schiavo@polimi.it\">Francesco Schiavo</a>:<br>
        First release.</li>
 </ul>
-</html>"));
-  end Flow1DFEM;
-
-  model Flow1DFEM2ph
-    "1-dimensional fluid flow model for water/steam (finite elements)"
-    extends BaseClasses.Flow1DBase(
-      Nw = N,
-      redeclare replaceable package Medium = StandardWater
-        constrainedby Modelica.Media.Interfaces.PartialTwoPhaseMedium
-                                                           "Medium model");
-      replaceable model HeatTransfer =
-        Thermal.HeatTransferFEM.IdealHeatTransfer
-      constrainedby ThermoPower.Thermal.BaseClasses.DistributedHeatTransferFEM
-      annotation (choicesAllMatching=true);
-    HeatTransfer heatTransfer(
-      redeclare package Medium = Medium,
-      final Nf=N,
-      final Nw=Nw,
-      final Nt=Nt,
-      final L=L,
-      final A=A,
-      final Dhyd=Dhyd,
-      final omega=omega,
-      final wnom=wnom/Nt,
-      final w=w,
-      final fluidState=fluidState) "Instantiated heat transfer model";
-
-    ThermoPower.Thermal.DHTNodes wall(N=N) annotation (Dialog(enable=
-            false), Placement(transformation(extent={{-40,40},{40,60}},
-            rotation=0)));
-
-    import ThermoPower.Choices.Flow1D.FFtypes;
-    import ThermoPower.Choices.Flow1D.HCtypes;
-
-    parameter Real alpha(
-      min=0,
-      max=2) = 1 "Numerical stabilization coefficient";
-    parameter Real ML(
-      min=0,
-      max=1) = 0.2 "Mass Lumping Coefficient";
-    constant SI.Acceleration g = Modelica.Constants.g_n;
-    final parameter Boolean evenN=(div(N, 2)*2 == N)
-      "The number of nodes is even";
-    constant SI.Pressure pzero=10 "Small deltap for calculations";
-    constant Medium.AbsolutePressure pc=Medium.fluidConstants[1].criticalPressure;
-    constant SI.SpecificEnthalpy hzero=1e-3;
-
-    Medium.ThermodynamicState fluidState[N]
-      "Thermodynamic state of the fluid at the nodes";
-    Medium.SaturationProperties sat "Properties of saturated fluid";
-    Medium.ThermodynamicState dew "Thermodynamic state at dewpoint";
-    Medium.ThermodynamicState bubble "Thermodynamic state at bubblepoint";
-    SI.Length omega_hyd "Hydraulic perimeter (single tube)";
-    Real dwdt "Dynamic momentum term";
-    Medium.AbsolutePressure p "Fluid pressure";
-    SI.Pressure Dpfric "Pressure drop due to friction";
-    SI.Pressure Dpfric1
-      "Pressure drop due to friction (from inlet to capacitance)";
-    SI.Pressure Dpfric2
-      "Pressure drop due to friction (from capacitance to outlet)";
-    SI.Pressure Dpstat "Pressure drop due to static head";
-    Medium.MassFlowRate w[N](start=wnom*ones(N)) "Mass flowrate (single tube)";
-    SI.Velocity u[N] "Fluid velocity";
-    SI.HeatFlux phi[N] "External heat flux";
-    Medium.Temperature T[N] "Fluid temperature";
-    Medium.SpecificEnthalpy h[N](start=hstart) "Fluid specific enthalpy";
-    Medium.Density rho[N] "Fluid density";
-    SI.SpecificVolume v[N] "Fluid specific volume";
-
-    Medium.Temperature Ts "Saturation temperature";
-    Medium.SpecificEnthalpy hl(start=Medium.bubbleEnthalpy(Medium.setSat_p(
-          pstart))) "Saturated liquid specific enthalpy";
-    Medium.SpecificEnthalpy hv(start=Medium.dewEnthalpy(Medium.setSat_p(pstart)))
-      "Saturated vapour specific enthalpy";
-    Real x[N] "Steam quality";
-    Units.LiquidDensity rhol "Saturated liquid density";
-    Units.GasDensity rhov "Saturated vapour density";
-
-    Real Kf[N] "Friction coefficient";
-    Real Cf[N] "Fanning friction factor";
-    Real Phi[N] "Two-phase friction multiplier";
-  protected
-    SI.DerDensityByEnthalpy drdh[N] "Derivative of density by enthalpy";
-    SI.DerDensityByPressure drdp[N] "Derivative of density by pressure";
-
-    SI.DerDensityByPressure drl_dp
-      "Derivative of liquid density by pressure just before saturation";
-    SI.DerDensityByPressure drv_dp
-      "Derivative of vapour density by pressure just before saturation";
-    SI.DerDensityByEnthalpy drl_dh
-      "Derivative of liquid density by enthalpy just before saturation";
-    SI.DerDensityByEnthalpy drv_dh
-      "Derivative of vapour density by enthalpy just before saturation";
-
-    Real dhl "Derivative of saturated liquid enthalpy by pressure";
-    Real dhv "Derivative of saturated vapour enthalpy by pressure";
-
-    Real drl "Derivative of saturatd liquid density by pressure";
-    Real drv "Derivative of saturated vapour density by pressure";
-
-    SI.Density rhos[N - 1];
-    Medium.MassFlowRate ws[N - 1];
-    Real rs[N - 1];
-
-    Real Y[N, N];
-    Real YY[N, N];
-
-    Real Y2ph[N, N];
-    Real M[N, N];
-    Real D[N];
-    Real D1[N];
-    Real D2[N];
-    Real G[N];
-    Real B[N, N];
-    Real B2ph[N, N];
-    Real C[N, N];
-    Real K[N, N];
-
-    Real by[8, N];
-    Real beta[8, N];
-    //coefficients matrix for 2-phases augmented FEM matrices
-    Real alpha_sgn;
-
-    Real gamma_rho[N - 1];
-    Real gamma_w[N - 1];
-    //coefficients for gamma functions
-
-    Real a;
-    Real b;
-    Real betap;
-    Real c;
-    Real d;
-    Real ee[N - 1];
-    Real f[N - 1];
-
-    Real dMbif[N - 1];
-    Real dMmono[N - 1];
-
-  equation
-    //All equations are referred to a single tube
-
-    // Selection of representative pressure variable
-    if HydraulicCapacitance == HCtypes.Middle then
-      p = infl.p - Dpfric1 - Dpstat/2;
-    elseif HydraulicCapacitance == HCtypes.Upstream then
-      p = infl.p;
-    elseif HydraulicCapacitance == HCtypes.Downstream then
-      p = outfl.p;
-    else
-      assert(false, "Unsupported HydraulicCapacitance option");
-    end if;
-
-    //Friction factor calculation
-    omega_hyd = 4*A/Dhyd;
-    for i in 1:N loop
-      if FFtype == FFtypes.NoFriction then
-        Cf[i] = 0;
-      elseif FFtype == FFtypes.Cfnom then
-        Cf[i] = Cfnom*Kfc;
-      else
-        assert(true, "Unsupported friction factor selection");
-      end if;
-      Kf[i] = Cf[i]*omega_hyd*L/(2*A^3)
-        "Relationship between friction coefficient and Fanning friction factor";
-    end for;
-
-    //Dynamic Momentum [not] accounted for
-    if DynamicMomentum then
-      if HydraulicCapacitance == HCtypes.Upstream then
-        dwdt = -der(outfl.m_flow)/Nt;
-      else
-        dwdt = der(infl.m_flow)/Nt;
-      end if;
-
-    else
-      dwdt = 0;
-    end if;
-
-    //Momentum balance equation
-    L/A*dwdt + (outfl.p - infl.p) + Dpstat + Dpfric = 0;
-
-    w[1] = infl.m_flow/Nt;
-    w[N] = -outfl.m_flow/Nt;
-
-    Dpfric = Dpfric1 + Dpfric2 "Total pressure drop due to friction";
-
-    if FFtype == FFtypes.NoFriction then
-      Dpfric1 = 0;
-      Dpfric2 = 0;
-    else
-      Dpfric1 = homotopy(sum(Kf[i]/L*squareReg(w[i], wnom/Nt*wnf)*D1[i]/rho[i]*
-        Phi[i] for i in 1:N), dpnom/2/(wnom/Nt)*w[1])
-        "Pressure drop from inlet to capacitance";
-      Dpfric2 = homotopy(sum(Kf[i]/L*squareReg(w[i], wnom/Nt*wnf)*D2[i]/rho[i]*
-        Phi[i] for i in 1:N), dpnom/2/(wnom/Nt)*w[N])
-        "Pressure drop from capacitance to outlet";
-    end if "Pressure drop due to friction";
-
-    for i in 1:N loop
-      if FFtype == FFtypes.NoFriction or noEvent(h[i] <= hl or h[i] >= hv) then
-        Phi[i] = 1;
-      else
-        // Chisholm-Laird formulation of Martinelli-Lockhart correlation for turbulent-turbulent flow
-        // Phi_l^2 = 1 + 20/Xtt + 1/Xtt^2
-        // same fixed Fanning friction factor Cfnom is assumed for liquid and vapour, so Xtt = (rhov/rhol)^0.5 * (1-x)/x
-        Phi[i] = rho[i]/rhol*((1 - x[i])^2 + 20*sqrt(rhol/rhov)*x[i]*(1 - x[i])
-           + rhol/rhov*x[i]^2);
-      end if;
-    end for;
-
-    Dpstat = if abs(dzdx) < 1e-6 then 0 else g*dzdx*rho*D
-      "Pressure drop due to static head";
-
-    //Energy balance equations
-    l/12*((1 - ML)*Y + ML*YY + 0*Y2ph)*der(h) + (1/A)*(B + 0*B2ph)*h + C*h/A =
-      der(p)*G + M*(omega/A)*phi + K*w/A;
-
-    //  (Ts,rhol,rhov,hl,hv,drl_dp,drv_dp,drl_dh,drv_dh,dhl,dhv,drl,drv) =
-    //  propsat_p_2der(noEvent(min(p, pc - pzero)));
-
-    sat = Medium.setSat_p(p);
-    Ts = Medium.saturationTemperature_sat(sat);
-    bubble = Medium.setBubbleState(sat);
-    dew = Medium.setDewState(sat);
-    rhol = Medium.bubbleDensity(sat);
-    rhov = Medium.dewDensity(sat);
-    hl = Medium.bubbleEnthalpy(sat);
-    hv = Medium.dewEnthalpy(sat);
-    drl = Medium.dBubbleDensity_dPressure(sat);
-    drv = Medium.dDewDensity_dPressure(sat);
-    dhl = Medium.dBubbleEnthalpy_dPressure(sat);
-    dhv = Medium.dDewEnthalpy_dPressure(sat);
-    drl_dp = Medium.density_derp_h(bubble);
-    drv_dp = Medium.density_derp_h(dew);
-    drl_dh = Medium.density_derh_p(bubble);
-    drv_dh = Medium.density_derh_p(dew);
-
-    a = ((hv - hl)*(rhol^2*drv + rhov^2*drl) + rhov*rhol*(rhol - rhov)*(dhv -
-      dhl))/(rhol - rhov)^2;
-    betap = ((rhol - rhov)*(rhov*dhv - rhol*dhl) + (hv - hl)*(rhol*drv - rhov*
-      drl))/(rhol - rhov)^2;
-    b = a*c + d*betap;
-    c = (rhov*hv - rhol*hl)/(rhol - rhov);
-    d = -rhol*rhov*(hv - hl)/(rhol - rhov);
-
-    //Computation of fluid properties
-    for j in 1:N loop
-      fluidState[j] = Medium.setState_phX(p, h[j]);
-      T[j] = Medium.temperature(fluidState[j]);
-      rho[j] = Medium.density(fluidState[j]);
-      drdp[j] = if Medium.singleState then 0 else Medium.density_derp_h(
-        fluidState[j]);
-      drdh[j] = Medium.density_derh_p(fluidState[j]);
-      v[j] = 1/rho[j];
-      u[j] = w[j]/(rho[j]*A);
-      x[j] = noEvent(min(max((h[j] - hl)/(hv - hl), 0), 1));
-    end for;
-
-    //Boundary Values
-    h[1] = infl.h_outflow;
-    h[N] = outfl.h_outflow;
-    phi = heatTransfer.phi_f;
-    connect(wall, heatTransfer.wall);
-
-    alpha_sgn = alpha*sign(infl.m_flow - outfl.m_flow);
-
-    //phase change determination
-    for i in 1:N - 1 loop
-      (w[i] - w[i + 1]) = dMmono[i] + dMbif[i];
-      if noEvent(abs(h[i + 1] - h[i]) < hzero) then
-
-        rs[i] = 0;
-        rhos[i] = 0;
-        gamma_rho[i] = 0;
-
-        gamma_w[i] = 0;
-        ws[i] = 0;
-
-        dMmono[i] = A*l*(der(p)*1/2*(drdp[i + 1] + drdp[i]) + 1/6*(der(h[i])*(2
-          *drdh[i] + drdh[i + 1]) + der(h[i + 1])*(drdh[i] + 2*drdh[i + 1])));
-
-        dMbif[i] = 0;
-
-        ee[i] = 0;
-        f[i] = 0;
-
-      elseif noEvent((h[i] < hl) and (h[i + 1] >= hl) and (h[i + 1] <= hv)) then
-        //liquid - two phase
-
-        rs[i] = (hl - h[i])/(h[i + 1] - h[i]);
-        rhos[i] = rhol;
-        gamma_rho[i] = (rhos[i] - rho[i]*(1 - rs[i]) - rho[i + 1]*rs[i]);
-
-        gamma_w[i] = (ws[i] - w[i]*(1 - rs[i]) - w[i + 1]*rs[i]);
-
-        (w[i] - ws[i]) = dMmono[i];
-
-        dMmono[i] = A*rs[i]*l*(der(p)*1/2*(drl_dp + drdp[i]) + 1/6*(der(h[i])*(
-          2*drdh[i] + drl_dh) + (der(h[i])*(1 - rs[i]) + der(h[i + 1])*rs[i])*(
-          drdh[i] + 2*drl_dh)));
-
-        dMbif[i] = A*(1 - rs[i])*l/(h[i + 1] - hl)*(der(p)*((b - a*c)*(h[i + 1]
-           - hl)/((c + h[i + 1])*(c + hl)) + a*log((c + h[i + 1])/(c + hl))) +
-          ((d*f[i] - d*c*ee[i])*(h[i + 1] - hl)/((c + h[i + 1])*(c + hl)) + d*
-          ee[i]*log((c + h[i + 1])/(c + hl))));
-
-        ee[i] = (der(h[i + 1]) - (der(h[i + 1])*rs[i] + der(h[i])*(1 - rs[i])))
-          /(h[i + 1] - hl);
-        f[i] = ((der(h[i + 1])*rs[i] + der(h[i])*(1 - rs[i]))*h[i + 1] - der(h[
-          i + 1])*hl)/(h[i + 1] - hl);
-
-      elseif noEvent((h[i] >= hl) and (h[i] <= hv) and (h[i + 1] < hl)) then
-        //two phase-liquid
-
-        rs[i] = (hl - h[i])/(h[i + 1] - h[i]);
-        rhos[i] = rhol;
-        gamma_rho[i] = (rhos[i] - rho[i]*(1 - rs[i]) - rho[i + 1]*rs[i]);
-
-        gamma_w[i] = (ws[i] - w[i]*(1 - rs[i]) - w[i + 1]*rs[i]);
-
-        (w[i] - ws[i]) = dMbif[i];
-
-        dMmono[i] = A*(1 - rs[i])*l*(der(p)*1/2*(drdp[i + 1] + drl_dp) + 1/6*(
-          der(h[i])*(2*drl_dh + drdh[i + 1]) + (der(h[i + 1])*rs[i] + der(h[i])
-          *(1 - rs[i]))*(drl_dh + 2*drdh[i + 1])));
-
-        dMbif[i] = A*rs[i]*l/(hl - h[i])*(der(p)*((b - a*c)*(hl - h[i])/((c +
-          hl)*(c + h[i])) + a*log((c + hl)/(c + h[i]))) + ((d*f[i] - d*c*ee[i])
-          *(hl - h[i])/((c + hl)*(c + h[i])) + d*ee[i]*log((c + hl)/(c + h[i]))));
-
-        ee[i] = ((der(h[i + 1])*rs[i] + der(h[i])*(1 - rs[i])) - der(h[i]))/(hl
-           - h[i]);
-        f[i] = (der(h[i])*hl - (der(h[i + 1])*rs[i] + der(h[i])*(1 - rs[i]))*h[
-          i])/(hl - h[i]);
-
-      elseif noEvent((h[i] >= hl) and (h[i] <= hv) and (h[i + 1] > hv)) then
-        //two phase - vapour
-
-        rs[i] = (hv - h[i])/(h[i + 1] - h[i]);
-        rhos[i] = rhov;
-        gamma_rho[i] = (rhos[i] - rho[i]*(1 - rs[i]) - rho[i + 1]*rs[i]);
-
-        gamma_w[i] = (ws[i] - w[i]*(1 - rs[i]) - w[i + 1]*rs[i]);
-        (w[i] - ws[i]) = dMbif[i];
-
-        dMmono[i] = A*(1 - rs[i])*l*(der(p)*1/2*(drdp[i + 1] + drv_dp) + 1/6*(
-          der(h[i])*(2*drv_dh + drdh[i + 1]) + (der(h[i + 1])*rs[i] + der(h[i])
-          *(1 - rs[i]))*(drv_dh + 2*drdh[i + 1])));
-
-        dMbif[i] = A*rs[i]*l/(hv - h[i])*(der(p)*((b - a*c)*(hv - h[i])/((c +
-          hv)*(c + h[i])) + a*log((c + hv)/(c + h[i]))) + ((d*f[i] - d*c*ee[i])
-          *(hv - h[i])/((c + hv)*(c + h[i])) + d*ee[i]*log((c + hv)/(c + h[i]))));
-
-        ee[i] = ((der(h[i + 1])*rs[i] + der(h[i])*(1 - rs[i])) - der(h[i]))/(hv
-           - h[i]);
-        f[i] = (der(h[i])*hv - (der(h[i + 1])*rs[i] + der(h[i])*(1 - rs[i]))*h[
-          i])/(hv - h[i]);
-
-      elseif noEvent((h[i] > hv) and (h[i + 1] >= hl) and (h[i + 1] <= hv)) then
-        // vapour - two phase
-
-        rs[i] = (hv - h[i])/(h[i + 1] - h[i]);
-        rhos[i] = rhov;
-        gamma_rho[i] = (rhos[i] - rho[i]*(1 - rs[i]) - rho[i + 1]*rs[i]);
-
-        gamma_w[i] = (ws[i] - w[i]*(1 - rs[i]) - w[i + 1]*rs[i]);
-        (w[i] - ws[i]) = dMmono[i];
-
-        dMmono[i] = A*rs[i]*l*(der(p)*1/2*(drv_dp + drdp[i]) + 1/6*(der(h[i])*(
-          2*drdh[i] + drv_dh) + (der(h[i])*(1 - rs[i]) + der(h[i + 1])*rs[i])*(
-          drdh[i] + 2*drv_dh)));
-
-        dMbif[i] = A*(1 - rs[i])*(der(p)*((b - a*c)*(h[i + 1] - hv)/((c + h[i
-           + 1])*(c + hv)) + a*log((c + h[i + 1])/(c + hv))) + ((d*f[i] - d*c*
-          ee[i])*(h[i + 1] - hv)/((c + h[i + 1])*(c + hv)) + d*ee[i]*log((c + h[
-          i + 1])/(c + hv))));
-
-        ee[i] = (der(h[i + 1]) - (der(h[i + 1])*rs[i] + der(h[i])*(1 - rs[i])))
-          /(h[i + 1] - hv);
-        f[i] = ((der(h[i + 1])*rs[i] + der(h[i])*(1 - rs[i]))*h[i + 1] - der(h[
-          i + 1])*hv)/(h[i + 1] - hv);
-
-      elseif noEvent((h[i] >= hl) and (h[i] <= hv) and (h[i + 1] >= hl) and (h[
-          i + 1] <= hv)) then
-        //two phase
-
-        rs[i] = 0;
-        rhos[i] = 0;
-        gamma_rho[i] = 0;
-
-        gamma_w[i] = 0;
-
-        ws[i] = 0;
-
-        dMmono[i] = 0;
-
-        dMbif[i] = A*l/(h[i + 1] - h[i])*(der(p)*((b - a*c)*(h[i + 1] - h[i])/(
-          (c + h[i + 1])*(c + h[i])) + a*log((c + h[i + 1])/(c + h[i]))) + ((d*
-          f[i] - d*c*ee[i])*(h[i + 1] - h[i])/((c + h[i + 1])*(c + h[i])) + d*
-          ee[i]*log((c + h[i + 1])/(c + h[i]))));
-
-        ee[i] = (der(h[i + 1]) - der(h[i]))/(h[i + 1] - h[i]);
-        f[i] = (der(h[i])*h[i + 1] - der(h[i + 1])*h[i])/(h[i + 1] - h[i]);
-
-      elseif noEvent(((h[i] < hl) and (h[i + 1] < hl)) or ((h[i] > hv) and (h[i
-           + 1] > hv))) then
-        //single-phase
-
-        rs[i] = 0;
-        rhos[i] = 0;
-        gamma_rho[i] = 0;
-
-        gamma_w[i] = 0;
-        ws[i] = 0;
-
-        dMmono[i] = A*l*(der(p)*1/2*(drdp[i + 1] + drdp[i]) + 1/6*(der(h[i])*(2
-          *drdh[i] + drdh[i + 1]) + der(h[i + 1])*(drdh[i] + 2*drdh[i + 1])));
-        dMbif[i] = 0;
-
-        ee[i] = 0;
-        f[i] = 0;
-      else
-        //double transition (not supported!)
-        assert(0 > 1,
-          "Error: two phase transitions between two adiacent nodes. Try increasing the number of nodes");
-        rs[i] = 0;
-        rhos[i] = 0;
-        gamma_rho[i] = 0;
-
-        gamma_w[i] = 0;
-        ws[i] = 0;
-
-        dMmono[i] = 0;
-        dMbif[i] = 0;
-
-        ee[i] = 0;
-        f[i] = 0;
-      end if;
-    end for;
-
-    // Energy equation FEM matrices
-
-    Y[1, 1] = rho[1]*(3 - 2*alpha_sgn) + rho[2]*(1 - alpha_sgn);
-    Y[1, 2] = rho[1]*(1 - alpha_sgn) + rho[2]*(1 - 2*alpha_sgn);
-    Y[N, N] = rho[N - 1]*(alpha_sgn + 1) + rho[N]*(3 + 2*alpha_sgn);
-    Y[N, N - 1] = rho[N - 1]*(1 + 2*alpha_sgn) + rho[N]*(1 + alpha_sgn);
-    if N > 2 then
-      for i in 2:N - 1 loop
-        Y[i, i - 1] = rho[i - 1]*(1 + 2*alpha_sgn) + rho[i]*(1 + alpha_sgn);
-        Y[i, i] = rho[i - 1]*(1 + alpha_sgn) + rho[i]*6 + rho[i + 1]*(1 -
-          alpha_sgn);
-        Y[i, i + 1] = rho[i]*(1 - alpha_sgn) + rho[i + 1]*(1 - 2*alpha_sgn);
-        Y[1, i + 1] = 0;
-        Y[N, i - 1] = 0;
-        for j in 1:(i - 2) loop
-          Y[i, j] = 0;
-        end for;
-        for j in (i + 2):N loop
-          Y[i, j] = 0;
-        end for;
-      end for;
-    end if;
-
-    for i in 1:N loop
-      for j in 1:N loop
-        YY[i, j] = if (i <> j) then 0 else sum(Y[:, j]);
-      end for;
-    end for;
-
-    M[1, 1] = l/3 - l*alpha_sgn/4;
-    M[N, N] = l/3 + l*alpha_sgn/4;
-    M[1, 2] = l/6 - l*alpha_sgn/4;
-    M[N, (N - 1)] = l/6 + l*alpha_sgn/4;
-    if N > 2 then
-      for i in 2:N - 1 loop
-        M[i, i - 1] = l/6 + l*alpha_sgn/4;
-        M[i, i] = 2*l/3;
-        M[i, i + 1] = l/6 - l*alpha_sgn/4;
-        M[1, i + 1] = 0;
-        M[N, i - 1] = 0;
-        for j in 1:(i - 2) loop
-          M[i, j] = 0;
-        end for;
-        for j in (i + 2):N loop
-          M[i, j] = 0;
-        end for;
-      end for;
-    end if;
-
-    B[1, 1] = (-1/3 + alpha_sgn/4)*w[1] + (-1/6 + alpha_sgn/4)*w[2];
-    B[1, 2] = (1/3 - alpha_sgn/4)*w[1] + (1/6 - alpha_sgn/4)*w[2];
-    B[N, N] = (1/6 + alpha_sgn/4)*w[N - 1] + (1/3 + alpha_sgn/4)*w[N];
-    B[N, N - 1] = (-1/6 - alpha_sgn/4)*w[N - 1] + (-1/3 - alpha_sgn/4)*w[N];
-    if N > 2 then
-      for i in 2:N - 1 loop
-        B[i, i - 1] = (-1/6 - alpha_sgn/4)*w[i - 1] + (-1/3 - alpha_sgn/4)*w[i];
-        B[i, i] = (1/6 + alpha_sgn/4)*w[i - 1] + (alpha_sgn/2)*w[i] + (-1/6 +
-          alpha_sgn/4)*w[i + 1];
-        B[i, i + 1] = (1/3 - alpha_sgn/4)*w[i] + (1/6 - alpha_sgn/4)*w[i + 1];
-        B[1, i + 1] = 0;
-        B[N, i - 1] = 0;
-        for j in 1:(i - 2) loop
-          B[i, j] = 0;
-        end for;
-        for j in (i + 2):N loop
-          B[i, j] = 0;
-        end for;
-      end for;
-    end if;
-
-    G[1] = l/2*(1 - alpha_sgn);
-    G[N] = l/2*(1 + alpha_sgn);
-    if N > 2 then
-      for i in 2:N - 1 loop
-        G[i] = l;
-      end for;
-    end if;
-
-    //boundary conditions
-
-    C[1, 1] = if noEvent(infl.m_flow >= 0) then (1 - alpha_sgn/2)*w[1] else 0;
-    C[N, N] = if noEvent(outfl.m_flow >= 0) then -(1 + alpha_sgn/2)*w[N] else 0;
-    C[N, 1] = 0;
-    C[1, N] = 0;
-    if (N > 2) then
-      for i in 2:(N - 1) loop
-        C[1, i] = 0;
-        C[N, i] = 0;
-        for j in 1:N loop
-          C[i, j] = 0;
-        end for;
-      end for;
-    end if;
-
-    K[1, 1] = if noEvent(infl.m_flow >= 0) then (1 - alpha_sgn/2)*inStream(infl.h_outflow)
-       else 0;
-    K[N, N] = if noEvent(outfl.m_flow >= 0) then -(1 + alpha_sgn/2)*inStream(
-      outfl.h_outflow) else 0;
-    K[N, 1] = 0;
-    K[1, N] = 0;
-    if (N > 2) then
-      for i in 2:(N - 1) loop
-        K[1, i] = 0;
-        K[N, i] = 0;
-        for j in 1:N loop
-          K[i, j] = 0;
-        end for;
-      end for;
-    end if;
-
-    // Momentum and Mass balance equation matrices
-    D[1] = l/2;
-    D[N] = l/2;
-    for i in 2:N - 1 loop
-      D[i] = l;
-    end for;
-    if HydraulicCapacitance == HCtypes.Middle then
-      D1 = l*(if N == 2 then {3/8,1/8} else if evenN then cat(
-          1,
-          {1/2},
-          ones(max(0, div(N, 2) - 2)),
-          {7/8,1/8},
-          zeros(div(N, 2) - 1)) else cat(
-          1,
-          {1/2},
-          ones(div(N, 2) - 1),
-          {1/2},
-          zeros(div(N, 2))));
-      D2 = l*(if N == 2 then {1/8,3/8} else if evenN then cat(
-          1,
-          zeros(div(N, 2) - 1),
-          {1/8,7/8},
-          ones(max(div(N, 2) - 2, 0)),
-          {1/2}) else cat(
-          1,
-          zeros(div(N, 2)),
-          {1/2},
-          ones(div(N, 2) - 1),
-          {1/2}));
-    elseif HydraulicCapacitance == HCtypes.Upstream then
-      D1 = zeros(N);
-      D2 = D;
-    elseif HydraulicCapacitance == HCtypes.Downstream then
-      D1 = D;
-      D2 = zeros(N);
-    else
-      assert(false, "Unsupported HydraulicCapacitance option");
-    end if;
-
-    by[1, 1] = 0;
-    by[2, 1] = 0;
-    by[3, 1] = l/12*rs[1]*(6 - 8*rs[1] + 3*rs[1]^2 + alpha_sgn*(2*rs[1] - 3));
-    by[4, 1] = -l/12*(1 - rs[1])^2*(2*alpha_sgn + 3*rs[1] - 3);
-    by[5, 1] = -l/12*rs[1]^2*(2*alpha_sgn + 3*rs[1] - 4);
-    by[6, 1] = -l/12*(1 - rs[1])*(3*rs[1]^2 - 2*rs[1] + 2*alpha_sgn*rs[1] +
-      alpha_sgn - 1);
-    by[7, 1] = 0;
-    by[8, 1] = 0;
-    by[1, N] = l/12*rs[N - 1]^2*(2*alpha_sgn + 3*rs[N - 1]);
-    by[2, N] = l/12*(1 - rs[N - 1])*(1 + alpha_sgn + 2*rs[N - 1] + 2*alpha_sgn*
-      rs[N - 1] + 3*rs[N - 1]^2);
-    by[3, N] = 0;
-    by[4, N] = 0;
-    by[5, N] = 0;
-    by[6, N] = 0;
-    by[7, N] = l/12*rs[N - 1]*(alpha_sgn*(3 - 2*rs[N - 1]) + rs[N - 1]*(4 - 3*
-      rs[N - 1]));
-    by[8, N] = l/12*(1 - rs[N - 1])^2*(2*alpha_sgn + 3*rs[N - 1] + 1);
-    if N > 2 then
-      for i in 2:N - 1 loop
-        by[1, i] = l/12*rs[i - 1]^2*(2*alpha_sgn + 3*rs[i - 1]);
-        by[2, i] = l/12*(1 - rs[i - 1])*(1 + alpha_sgn + 2*rs[i - 1] + 2*
-          alpha_sgn*rs[i - 1] + 3*rs[i - 1]^2);
-        by[3, i] = l/12*rs[i]*(6 - 8*rs[i] + 3*rs[i]^2 + alpha_sgn*(2*rs[i] - 3));
-        by[4, i] = -l/12*(1 - rs[i])^2*(2*alpha_sgn + 3*rs[i] - 3);
-        by[5, i] = -l/12*rs[i]^2*(2*alpha_sgn + 3*rs[i] - 4);
-        by[6, i] = -l/12*(1 - rs[i])*(3*rs[i]^2 - 2*rs[i] + 2*alpha_sgn*rs[i]
-           + alpha_sgn - 1);
-        by[7, i] = l/12*rs[i - 1]*(alpha_sgn*(3 - 2*rs[i - 1]) + rs[i - 1]*(4
-           - 3*rs[i - 1]));
-        by[8, i] = l/12*(1 - rs[i - 1])^2*(2*alpha_sgn + 3*rs[i - 1] + 1);
-      end for;
-    end if;
-
-    //additional 2 phases Y-matrix
-    Y2ph[1, 1] = (gamma_rho[1]*by[3, 1] + gamma_rho[1]*by[4, 1]);
-    Y2ph[1, 2] = (gamma_rho[1]*by[5, 1] + gamma_rho[1]*by[6, 1]);
-    Y2ph[N, N] = (gamma_rho[N - 1]*by[1, N] + gamma_rho[N - 1]*by[2, N]);
-    Y2ph[N, N - 1] = (gamma_rho[N - 1]*by[7, N] + gamma_rho[N - 1]*by[8, N]);
-    if N > 2 then
-      for i in 2:N - 1 loop
-        Y2ph[i, i - 1] = (gamma_rho[i - 1]*by[7, i] + gamma_rho[i - 1]*by[8, i]);
-        Y2ph[i, i] = (gamma_rho[i - 1]*by[1, i] + gamma_rho[i - 1]*by[2, i]) +
-          (gamma_rho[i]*by[3, i] + gamma_rho[i]*by[4, i]);
-        Y2ph[i, i + 1] = (gamma_rho[i]*by[5, i] + gamma_rho[i]*by[6, i]);
-        Y2ph[1, i + 1] = 0;
-        Y2ph[N, i - 1] = 0;
-        for j in 1:(i - 2) loop
-          Y2ph[i, j] = 0;
-        end for;
-        for j in (i + 2):N loop
-          Y2ph[i, j] = 0;
-        end for;
-      end for;
-    end if;
-
-    //computation of beta functions for additional matrices
-    beta[1, 1] = 0;
-    beta[2, 1] = 0;
-    beta[3, 1] = 1/12*rs[1]*(3*alpha_sgn + 4*rs[1] - 6);
-    beta[4, 1] = 1/12*(1 - rs[1])*(3*alpha_sgn + 4*rs[1] - 4);
-    beta[5, 1] = -beta[3, 1];
-    beta[6, 1] = -beta[4, 1];
-    beta[7, 1] = 0;
-    beta[8, 1] = 0;
-    beta[1, N] = 1/12*rs[N - 1]*(3*alpha_sgn + 4*rs[N - 1]);
-    beta[2, N] = 1/12*(1 - rs[N - 1])*(3*alpha_sgn + 4*rs[N - 1] + 2);
-    beta[3, N] = 0;
-    beta[4, N] = 0;
-    beta[5, N] = 0;
-    beta[6, N] = 0;
-    beta[7, N] = -beta[1, N];
-    beta[8, N] = -beta[2, N];
-    if N > 2 then
-      for i in 2:N - 1 loop
-        beta[1, i] = 1/12*rs[i - 1]*(3*alpha_sgn + 4*rs[i - 1]);
-        beta[2, i] = 1/12*(1 - rs[i - 1])*(3*alpha_sgn + 4*rs[i - 1] + 2);
-        beta[3, i] = 1/12*rs[i]*(3*alpha_sgn + 4*rs[i] - 6);
-        beta[4, i] = 1/12*(1 - rs[i])*(3*alpha_sgn + 4*rs[i] - 4);
-        beta[5, i] = -beta[3, i];
-        beta[6, i] = -beta[4, i];
-        beta[7, i] = -beta[1, i];
-        beta[8, i] = -beta[2, i];
-      end for;
-    end if;
-
-    //additional 2 phases B-matrix
-    B2ph[1, 1] = (gamma_w[1]*beta[3, 1] + gamma_w[1]*beta[4, 1]);
-    B2ph[1, 2] = (gamma_w[1]*beta[5, 1] + gamma_w[1]*beta[6, 1]);
-    B2ph[N, N] = (gamma_w[N - 1]*beta[1, N] + gamma_w[N - 1]*beta[2, N]);
-    B2ph[N, N - 1] = (gamma_w[N - 1]*beta[7, N] + gamma_w[N - 1]*beta[8, N]);
-    if N > 2 then
-      for i in 2:N - 1 loop
-        B2ph[i, i - 1] = (gamma_w[i - 1]*beta[7, i] + gamma_w[i - 1]*beta[8, i]);
-        B2ph[i, i] = (gamma_w[i - 1]*beta[1, i] + gamma_w[i - 1]*beta[2, i]) +
-          (gamma_w[i]*beta[3, i] + gamma_w[i]*beta[4, i]);
-        B2ph[i, i + 1] = (gamma_w[i]*beta[5, i] + gamma_w[i]*beta[6, i]);
-        B2ph[1, i + 1] = 0;
-        B2ph[N, i - 1] = 0;
-        for j in 1:(i - 2) loop
-          B2ph[i, j] = 0;
-        end for;
-        for j in (i + 2):N loop
-          B2ph[i, j] = 0;
-        end for;
-      end for;
-    end if;
-    Q = Nt*omega*D*phi "Total heat flow through lateral boundary";
-    Tr = noEvent(sum(rho)*A*l/max(infl.m_flow/Nt, Modelica.Constants.eps));
-  initial equation
-    if initOpt == Choices.Init.Options.noInit then
-      // do nothing
-    elseif initOpt == Choices.Init.Options.fixedState then
-      if not noInitialPressure then
-        p = pstart;
-      end if;
-      h = hstart;
-    elseif initOpt == Choices.Init.Options.steadyState then
-      der(h) = zeros(N);
-      if (not Medium.singleState) and not noInitialPressure then
-        der(p) = 0;
-      end if;
-    elseif initOpt == Choices.Init.Options.steadyStateNoP then
-      der(h) = zeros(N);
-      assert(false, "initOpt = steadyStateNoP deprecated, use steadyState and noInitialPressure",AssertionLevel.warning);
-    elseif initOpt == Choices.Init.Options.steadyStateNoT and not Medium.singleState then
-      der(p) = 0;
-    else
-      assert(false, "Unsupported initialisation option");
-    end if;
-    annotation (
-      Diagram(graphics),
-      Icon(graphics={Text(extent={{-100,-40},{100,-80}}, textString="%name")}),
-      Documentation(info="<HTML>
+</html>"));
+  end Flow1DFEM;
+
+  model Flow1DFEM2ph "1-dimensional fluid flow model for water/steam (finite elements)"
+    extends BaseClasses.Flow1DBase(Nw = N, redeclare replaceable package Medium = StandardWater constrainedby Modelica.Media.Interfaces.PartialTwoPhaseMedium "Medium model");
+    replaceable model HeatTransfer = Thermal.HeatTransferFEM.IdealHeatTransfer constrainedby ThermoPower.Thermal.BaseClasses.DistributedHeatTransferFEM annotation(
+       choicesAllMatching = true);
+    HeatTransfer heatTransfer(redeclare package Medium = Medium, final Nf = N, final Nw = Nw, final Nt = Nt, final L = L, final A = A, final Dhyd = Dhyd, final omega = omega, final wnom = wnom / Nt, final w = w, final fluidState = fluidState) "Instantiated heat transfer model";
+    ThermoPower.Thermal.DHTNodes wall(N = N) annotation(
+      Dialog(enable = false),
+      Placement(transformation(extent = {{-40, 40}, {40, 60}}, rotation = 0)));
+    import ThermoPower.Choices.Flow1D.FFtypes;
+    import ThermoPower.Choices.Flow1D.HCtypes;
+    parameter Real alpha(min = 0, max = 2) = 1 "Numerical stabilization coefficient";
+    parameter Real ML(min = 0, max = 1) = 0.2 "Mass Lumping Coefficient";
+    constant SI.Acceleration g = Modelica.Constants.g_n;
+    final parameter Boolean evenN = div(N, 2) * 2 == N "The number of nodes is even";
+    constant SI.Pressure pzero = 10 "Small deltap for calculations";
+    constant Medium.AbsolutePressure pc = Medium.fluidConstants[1].criticalPressure;
+    constant SI.SpecificEnthalpy hzero = 1e-3;
+    Medium.ThermodynamicState fluidState[N] "Thermodynamic state of the fluid at the nodes";
+    Medium.SaturationProperties sat "Properties of saturated fluid";
+    Medium.ThermodynamicState dew "Thermodynamic state at dewpoint";
+    Medium.ThermodynamicState bubble "Thermodynamic state at bubblepoint";
+    SI.Length omega_hyd "Hydraulic perimeter (single tube)";
+    Real dwdt "Dynamic momentum term";
+    Medium.AbsolutePressure p "Fluid pressure";
+    SI.Pressure Dpfric "Pressure drop due to friction";
+    SI.Pressure Dpfric1 "Pressure drop due to friction (from inlet to capacitance)";
+    SI.Pressure Dpfric2 "Pressure drop due to friction (from capacitance to outlet)";
+    SI.Pressure Dpstat "Pressure drop due to static head";
+    Medium.MassFlowRate w[N](start = wnom * ones(N)) "Mass flowrate (single tube)";
+    SI.Velocity u[N] "Fluid velocity";
+    SI.HeatFlux phi[N] "External heat flux";
+    Medium.Temperature T[N] "Fluid temperature";
+    Medium.SpecificEnthalpy h[N](start = hstart) "Fluid specific enthalpy";
+    Medium.Density rho[N] "Fluid density";
+    SI.SpecificVolume v[N] "Fluid specific volume";
+    Medium.Temperature Ts "Saturation temperature";
+    Medium.SpecificEnthalpy hl(start = Medium.bubbleEnthalpy(Medium.setSat_p(pstart))) "Saturated liquid specific enthalpy";
+    Medium.SpecificEnthalpy hv(start = Medium.dewEnthalpy(Medium.setSat_p(pstart))) "Saturated vapour specific enthalpy";
+    Real x[N] "Steam quality";
+    Units.LiquidDensity rhol "Saturated liquid density";
+    Units.GasDensity rhov "Saturated vapour density";
+    Real Kf[N] "Friction coefficient";
+    Real Cf[N] "Fanning friction factor";
+    Real Phi[N] "Two-phase friction multiplier";
+  protected
+    SI.DerDensityByEnthalpy drdh[N] "Derivative of density by enthalpy";
+    SI.DerDensityByPressure drdp[N] "Derivative of density by pressure";
+    SI.DerDensityByPressure drl_dp "Derivative of liquid density by pressure just before saturation";
+    SI.DerDensityByPressure drv_dp "Derivative of vapour density by pressure just before saturation";
+    SI.DerDensityByEnthalpy drl_dh "Derivative of liquid density by enthalpy just before saturation";
+    SI.DerDensityByEnthalpy drv_dh "Derivative of vapour density by enthalpy just before saturation";
+    Real dhl "Derivative of saturated liquid enthalpy by pressure";
+    Real dhv "Derivative of saturated vapour enthalpy by pressure";
+    Real drl "Derivative of saturatd liquid density by pressure";
+    Real drv "Derivative of saturated vapour density by pressure";
+    SI.Density rhos[N - 1];
+    Medium.MassFlowRate ws[N - 1];
+    Real rs[N - 1];
+    Real Y[N, N];
+    Real YY[N, N];
+    Real Y2ph[N, N];
+    Real M[N, N];
+    Real D[N];
+    Real D1[N];
+    Real D2[N];
+    Real G[N];
+    Real B[N, N];
+    Real B2ph[N, N];
+    Real C[N, N];
+    Real K[N, N];
+    Real by[8, N];
+    Real beta[8, N];
+    //coefficients matrix for 2-phases augmented FEM matrices
+    Real alpha_sgn;
+    Real gamma_rho[N - 1];
+    Real gamma_w[N - 1];
+    //coefficients for gamma functions
+    Real a;
+    Real b;
+    Real betap;
+    Real c;
+    Real d;
+    Real ee[N - 1];
+    Real f[N - 1];
+    Real dMbif[N - 1];
+    Real dMmono[N - 1];
+  equation
+//All equations are referred to a single tube
+// Selection of representative pressure variable
+    if HydraulicCapacitance == HCtypes.Middle then
+      p = infl.p - Dpfric1 - Dpstat / 2;
+    elseif HydraulicCapacitance == HCtypes.Upstream then
+      p = infl.p;
+    elseif HydraulicCapacitance == HCtypes.Downstream then
+      p = outfl.p;
+    else
+      assert(false, "Unsupported HydraulicCapacitance option");
+    end if;
+//Friction factor calculation
+    omega_hyd = 4 * A / Dhyd;
+    for i in 1:N loop
+      if FFtype == FFtypes.NoFriction then
+        Cf[i] = 0;
+      elseif FFtype == FFtypes.Cfnom then
+        Cf[i] = Cfnom * Kfc;
+      else
+        assert(true, "Unsupported friction factor selection");
+      end if;
+      Kf[i] = Cf[i] * omega_hyd * L / (2 * A ^ 3) "Relationship between friction coefficient and Fanning friction factor";
+    end for;
+//Dynamic Momentum [not] accounted for
+    if DynamicMomentum then
+      if HydraulicCapacitance == HCtypes.Upstream then
+        dwdt = -der(outfl.m_flow) / Nt;
+      else
+        dwdt = der(infl.m_flow) / Nt;
+      end if;
+    else
+      dwdt = 0;
+    end if;
+//Momentum balance equation
+    L / A * dwdt + outfl.p - infl.p + Dpstat + Dpfric = 0;
+    w[1] = infl.m_flow / Nt;
+    w[N] = -outfl.m_flow / Nt;
+    Dpfric = Dpfric1 + Dpfric2 "Total pressure drop due to friction";
+    if FFtype == FFtypes.NoFriction then
+      Dpfric1 = 0;
+      Dpfric2 = 0;
+    else
+      Dpfric1 = homotopy(sum(Kf[i] / L * squareReg(w[i], wnom / Nt * wnf) * D1[i] / rho[i] * Phi[i] for i in 1:N), dpnom / 2 / (wnom / Nt) * w[1]) "Pressure drop from inlet to capacitance";
+      Dpfric2 = homotopy(sum(Kf[i] / L * squareReg(w[i], wnom / Nt * wnf) * D2[i] / rho[i] * Phi[i] for i in 1:N), dpnom / 2 / (wnom / Nt) * w[N]) "Pressure drop from capacitance to outlet";
+    end if "Pressure drop due to friction";
+    for i in 1:N loop
+      if FFtype == FFtypes.NoFriction or noEvent(h[i] <= hl or h[i] >= hv) then
+        Phi[i] = 1;
+      else
+// Chisholm-Laird formulation of Martinelli-Lockhart correlation for turbulent-turbulent flow
+// Phi_l^2 = 1 + 20/Xtt + 1/Xtt^2
+// same fixed Fanning friction factor Cfnom is assumed for liquid and vapour, so Xtt = (rhov/rhol)^0.5 * (1-x)/x
+        Phi[i] = rho[i] / rhol * ((1 - x[i]) ^ 2 + 20 * sqrt(rhol / rhov) * x[i] * (1 - x[i]) + rhol / rhov * x[i] ^ 2);
+      end if;
+    end for;
+    Dpstat = if abs(dzdx) < 1e-6 then 0 else g * dzdx * rho * D "Pressure drop due to static head";
+//Energy balance equations
+    l / 12 * ((1 - ML) * Y + ML * YY + 0 * Y2ph) * der(h) + 1 / A * (B + 0 * B2ph) * h + C * h / A = der(p) * G + M * (omega / A) * phi + K * w / A;
+//  (Ts,rhol,rhov,hl,hv,drl_dp,drv_dp,drl_dh,drv_dh,dhl,dhv,drl,drv) =
+//  propsat_p_2der(noEvent(min(p, pc - pzero)));
+    sat = Medium.setSat_p(p);
+    Ts = Medium.saturationTemperature_sat(sat);
+    bubble = Medium.setBubbleState(sat);
+    dew = Medium.setDewState(sat);
+    rhol = Medium.bubbleDensity(sat);
+    rhov = Medium.dewDensity(sat);
+    hl = Medium.bubbleEnthalpy(sat);
+    hv = Medium.dewEnthalpy(sat);
+    drl = Medium.dBubbleDensity_dPressure(sat);
+    drv = Medium.dDewDensity_dPressure(sat);
+    dhl = Medium.dBubbleEnthalpy_dPressure(sat);
+    dhv = Medium.dDewEnthalpy_dPressure(sat);
+    drl_dp = Medium.density_derp_h(bubble);
+    drv_dp = Medium.density_derp_h(dew);
+    drl_dh = Medium.density_derh_p(bubble);
+    drv_dh = Medium.density_derh_p(dew);
+    a = ((hv - hl) * (rhol ^ 2 * drv + rhov ^ 2 * drl) + rhov * rhol * (rhol - rhov) * (dhv - dhl)) / (rhol - rhov) ^ 2;
+    betap = ((rhol - rhov) * (rhov * dhv - rhol * dhl) + (hv - hl) * (rhol * drv - rhov * drl)) / (rhol - rhov) ^ 2;
+    b = a * c + d * betap;
+    c = (rhov * hv - rhol * hl) / (rhol - rhov);
+    d = -rhol * rhov * (hv - hl) / (rhol - rhov);
+//Computation of fluid properties
+    for j in 1:N loop
+      fluidState[j] = Medium.setState_phX(p, h[j]);
+      T[j] = Medium.temperature(fluidState[j]);
+      rho[j] = Medium.density(fluidState[j]);
+      drdp[j] = if Medium.singleState then 0 else Medium.density_derp_h(fluidState[j]);
+      drdh[j] = Medium.density_derh_p(fluidState[j]);
+      v[j] = 1 / rho[j];
+      u[j] = w[j] / (rho[j] * A);
+      x[j] = noEvent(min(max((h[j] - hl) / (hv - hl), 0), 1));
+    end for;
+//Boundary Values
+    h[1] = infl.h_outflow;
+    h[N] = outfl.h_outflow;
+    phi = heatTransfer.phi_f;
+    connect(wall, heatTransfer.wall);
+    alpha_sgn = alpha * sign(infl.m_flow - outfl.m_flow);
+//phase change determination
+    for i in 1:N - 1 loop
+      w[i] - w[i + 1] = dMmono[i] + dMbif[i];
+      if noEvent(abs(h[i + 1] - h[i]) < hzero) then
+        rs[i] = 0;
+        rhos[i] = 0;
+        gamma_rho[i] = 0;
+        gamma_w[i] = 0;
+        ws[i] = 0;
+        dMmono[i] = A * l * (der(p) * 1 / 2 * (drdp[i + 1] + drdp[i]) + 1 / 6 * (der(h[i]) * (2 * drdh[i] + drdh[i + 1]) + der(h[i + 1]) * (drdh[i] + 2 * drdh[i + 1])));
+        dMbif[i] = 0;
+        ee[i] = 0;
+        f[i] = 0;
+      elseif noEvent(h[i] < hl and h[i + 1] >= hl and h[i + 1] <= hv) then
+//liquid - two phase
+        rs[i] = (hl - h[i]) / (h[i + 1] - h[i]);
+        rhos[i] = rhol;
+        gamma_rho[i] = rhos[i] - rho[i] * (1 - rs[i]) - rho[i + 1] * rs[i];
+        gamma_w[i] = ws[i] - w[i] * (1 - rs[i]) - w[i + 1] * rs[i];
+        w[i] - ws[i] = dMmono[i];
+        dMmono[i] = A * rs[i] * l * (der(p) * 1 / 2 * (drl_dp + drdp[i]) + 1 / 6 * (der(h[i]) * (2 * drdh[i] + drl_dh) + (der(h[i]) * (1 - rs[i]) + der(h[i + 1]) * rs[i]) * (drdh[i] + 2 * drl_dh)));
+        dMbif[i] = A * (1 - rs[i]) * l / (h[i + 1] - hl) * (der(p) * ((b - a * c) * (h[i + 1] - hl) / ((c + h[i + 1]) * (c + hl)) + a * log((c + h[i + 1]) / (c + hl))) + (d * f[i] - d * c * ee[i]) * (h[i + 1] - hl) / ((c + h[i + 1]) * (c + hl)) + d * ee[i] * log((c + h[i + 1]) / (c + hl)));
+        ee[i] = (der(h[i + 1]) - (der(h[i + 1]) * rs[i] + der(h[i]) * (1 - rs[i]))) / (h[i + 1] - hl);
+        f[i] = ((der(h[i + 1]) * rs[i] + der(h[i]) * (1 - rs[i])) * h[i + 1] - der(h[i + 1]) * hl) / (h[i + 1] - hl);
+      elseif noEvent(h[i] >= hl and h[i] <= hv and h[i + 1] < hl) then
+//two phase-liquid
+        rs[i] = (hl - h[i]) / (h[i + 1] - h[i]);
+        rhos[i] = rhol;
+        gamma_rho[i] = rhos[i] - rho[i] * (1 - rs[i]) - rho[i + 1] * rs[i];
+        gamma_w[i] = ws[i] - w[i] * (1 - rs[i]) - w[i + 1] * rs[i];
+        w[i] - ws[i] = dMbif[i];
+        dMmono[i] = A * (1 - rs[i]) * l * (der(p) * 1 / 2 * (drdp[i + 1] + drl_dp) + 1 / 6 * (der(h[i]) * (2 * drl_dh + drdh[i + 1]) + (der(h[i + 1]) * rs[i] + der(h[i]) * (1 - rs[i])) * (drl_dh + 2 * drdh[i + 1])));
+        dMbif[i] = A * rs[i] * l / (hl - h[i]) * (der(p) * ((b - a * c) * (hl - h[i]) / ((c + hl) * (c + h[i])) + a * log((c + hl) / (c + h[i]))) + (d * f[i] - d * c * ee[i]) * (hl - h[i]) / ((c + hl) * (c + h[i])) + d * ee[i] * log((c + hl) / (c + h[i])));
+        ee[i] = (der(h[i + 1]) * rs[i] + der(h[i]) * (1 - rs[i]) - der(h[i])) / (hl - h[i]);
+        f[i] = (der(h[i]) * hl - (der(h[i + 1]) * rs[i] + der(h[i]) * (1 - rs[i])) * h[i]) / (hl - h[i]);
+      elseif noEvent(h[i] >= hl and h[i] <= hv and h[i + 1] > hv) then
+//two phase - vapour
+        rs[i] = (hv - h[i]) / (h[i + 1] - h[i]);
+        rhos[i] = rhov;
+        gamma_rho[i] = rhos[i] - rho[i] * (1 - rs[i]) - rho[i + 1] * rs[i];
+        gamma_w[i] = ws[i] - w[i] * (1 - rs[i]) - w[i + 1] * rs[i];
+        w[i] - ws[i] = dMbif[i];
+        dMmono[i] = A * (1 - rs[i]) * l * (der(p) * 1 / 2 * (drdp[i + 1] + drv_dp) + 1 / 6 * (der(h[i]) * (2 * drv_dh + drdh[i + 1]) + (der(h[i + 1]) * rs[i] + der(h[i]) * (1 - rs[i])) * (drv_dh + 2 * drdh[i + 1])));
+        dMbif[i] = A * rs[i] * l / (hv - h[i]) * (der(p) * ((b - a * c) * (hv - h[i]) / ((c + hv) * (c + h[i])) + a * log((c + hv) / (c + h[i]))) + (d * f[i] - d * c * ee[i]) * (hv - h[i]) / ((c + hv) * (c + h[i])) + d * ee[i] * log((c + hv) / (c + h[i])));
+        ee[i] = (der(h[i + 1]) * rs[i] + der(h[i]) * (1 - rs[i]) - der(h[i])) / (hv - h[i]);
+        f[i] = (der(h[i]) * hv - (der(h[i + 1]) * rs[i] + der(h[i]) * (1 - rs[i])) * h[i]) / (hv - h[i]);
+      elseif noEvent(h[i] > hv and h[i + 1] >= hl and h[i + 1] <= hv) then
+// vapour - two phase
+        rs[i] = (hv - h[i]) / (h[i + 1] - h[i]);
+        rhos[i] = rhov;
+        gamma_rho[i] = rhos[i] - rho[i] * (1 - rs[i]) - rho[i + 1] * rs[i];
+        gamma_w[i] = ws[i] - w[i] * (1 - rs[i]) - w[i + 1] * rs[i];
+        w[i] - ws[i] = dMmono[i];
+        dMmono[i] = A * rs[i] * l * (der(p) * 1 / 2 * (drv_dp + drdp[i]) + 1 / 6 * (der(h[i]) * (2 * drdh[i] + drv_dh) + (der(h[i]) * (1 - rs[i]) + der(h[i + 1]) * rs[i]) * (drdh[i] + 2 * drv_dh)));
+        dMbif[i] = A * (1 - rs[i]) * (der(p) * ((b - a * c) * (h[i + 1] - hv) / ((c + h[i + 1]) * (c + hv)) + a * log((c + h[i + 1]) / (c + hv))) + (d * f[i] - d * c * ee[i]) * (h[i + 1] - hv) / ((c + h[i + 1]) * (c + hv)) + d * ee[i] * log((c + h[i + 1]) / (c + hv)));
+        ee[i] = (der(h[i + 1]) - (der(h[i + 1]) * rs[i] + der(h[i]) * (1 - rs[i]))) / (h[i + 1] - hv);
+        f[i] = ((der(h[i + 1]) * rs[i] + der(h[i]) * (1 - rs[i])) * h[i + 1] - der(h[i + 1]) * hv) / (h[i + 1] - hv);
+      elseif noEvent(h[i] >= hl and h[i] <= hv and h[i + 1] >= hl and h[i + 1] <= hv) then
+//two phase
+        rs[i] = 0;
+        rhos[i] = 0;
+        gamma_rho[i] = 0;
+        gamma_w[i] = 0;
+        ws[i] = 0;
+        dMmono[i] = 0;
+        dMbif[i] = A * l / (h[i + 1] - h[i]) * (der(p) * ((b - a * c) * (h[i + 1] - h[i]) / ((c + h[i + 1]) * (c + h[i])) + a * log((c + h[i + 1]) / (c + h[i]))) + (d * f[i] - d * c * ee[i]) * (h[i + 1] - h[i]) / ((c + h[i + 1]) * (c + h[i])) + d * ee[i] * log((c + h[i + 1]) / (c + h[i])));
+        ee[i] = (der(h[i + 1]) - der(h[i])) / (h[i + 1] - h[i]);
+        f[i] = (der(h[i]) * h[i + 1] - der(h[i + 1]) * h[i]) / (h[i + 1] - h[i]);
+      elseif noEvent(h[i] < hl and h[i + 1] < hl or h[i] > hv and h[i + 1] > hv) then
+//single-phase
+        rs[i] = 0;
+        rhos[i] = 0;
+        gamma_rho[i] = 0;
+        gamma_w[i] = 0;
+        ws[i] = 0;
+        dMmono[i] = A * l * (der(p) * 1 / 2 * (drdp[i + 1] + drdp[i]) + 1 / 6 * (der(h[i]) * (2 * drdh[i] + drdh[i + 1]) + der(h[i + 1]) * (drdh[i] + 2 * drdh[i + 1])));
+        dMbif[i] = 0;
+        ee[i] = 0;
+        f[i] = 0;
+      else
+//double transition (not supported!)
+        assert(0 > 1, "Error: two phase transitions between two adiacent nodes. Try increasing the number of nodes");
+        rs[i] = 0;
+        rhos[i] = 0;
+        gamma_rho[i] = 0;
+        gamma_w[i] = 0;
+        ws[i] = 0;
+        dMmono[i] = 0;
+        dMbif[i] = 0;
+        ee[i] = 0;
+        f[i] = 0;
+      end if;
+    end for;
+// Energy equation FEM matrices
+    Y[1, 1] = rho[1] * (3 - 2 * alpha_sgn) + rho[2] * (1 - alpha_sgn);
+    Y[1, 2] = rho[1] * (1 - alpha_sgn) + rho[2] * (1 - 2 * alpha_sgn);
+    Y[N, N] = rho[N - 1] * (alpha_sgn + 1) + rho[N] * (3 + 2 * alpha_sgn);
+    Y[N, N - 1] = rho[N - 1] * (1 + 2 * alpha_sgn) + rho[N] * (1 + alpha_sgn);
+    if N > 2 then
+      for i in 2:N - 1 loop
+        Y[i, i - 1] = rho[i - 1] * (1 + 2 * alpha_sgn) + rho[i] * (1 + alpha_sgn);
+        Y[i, i] = rho[i - 1] * (1 + alpha_sgn) + rho[i] * 6 + rho[i + 1] * (1 - alpha_sgn);
+        Y[i, i + 1] = rho[i] * (1 - alpha_sgn) + rho[i + 1] * (1 - 2 * alpha_sgn);
+        Y[1, i + 1] = 0;
+        Y[N, i - 1] = 0;
+        for j in 1:i - 2 loop
+          Y[i, j] = 0;
+        end for;
+        for j in i + 2:N loop
+          Y[i, j] = 0;
+        end for;
+      end for;
+    end if;
+    for i in 1:N loop
+      for j in 1:N loop
+        YY[i, j] = if i <> j then 0 else sum(Y[:, j]);
+      end for;
+    end for;
+    M[1, 1] = l / 3 - l * alpha_sgn / 4;
+    M[N, N] = l / 3 + l * alpha_sgn / 4;
+    M[1, 2] = l / 6 - l * alpha_sgn / 4;
+    M[N, N - 1] = l / 6 + l * alpha_sgn / 4;
+    if N > 2 then
+      for i in 2:N - 1 loop
+        M[i, i - 1] = l / 6 + l * alpha_sgn / 4;
+        M[i, i] = 2 * l / 3;
+        M[i, i + 1] = l / 6 - l * alpha_sgn / 4;
+        M[1, i + 1] = 0;
+        M[N, i - 1] = 0;
+        for j in 1:i - 2 loop
+          M[i, j] = 0;
+        end for;
+        for j in i + 2:N loop
+          M[i, j] = 0;
+        end for;
+      end for;
+    end if;
+    B[1, 1] = ((-1 / 3) + alpha_sgn / 4) * w[1] + ((-1 / 6) + alpha_sgn / 4) * w[2];
+    B[1, 2] = (1 / 3 - alpha_sgn / 4) * w[1] + (1 / 6 - alpha_sgn / 4) * w[2];
+    B[N, N] = (1 / 6 + alpha_sgn / 4) * w[N - 1] + (1 / 3 + alpha_sgn / 4) * w[N];
+    B[N, N - 1] = ((-1 / 6) - alpha_sgn / 4) * w[N - 1] + ((-1 / 3) - alpha_sgn / 4) * w[N];
+    if N > 2 then
+      for i in 2:N - 1 loop
+        B[i, i - 1] = ((-1 / 6) - alpha_sgn / 4) * w[i - 1] + ((-1 / 3) - alpha_sgn / 4) * w[i];
+        B[i, i] = (1 / 6 + alpha_sgn / 4) * w[i - 1] + alpha_sgn / 2 * w[i] + ((-1 / 6) + alpha_sgn / 4) * w[i + 1];
+        B[i, i + 1] = (1 / 3 - alpha_sgn / 4) * w[i] + (1 / 6 - alpha_sgn / 4) * w[i + 1];
+        B[1, i + 1] = 0;
+        B[N, i - 1] = 0;
+        for j in 1:i - 2 loop
+          B[i, j] = 0;
+        end for;
+        for j in i + 2:N loop
+          B[i, j] = 0;
+        end for;
+      end for;
+    end if;
+    G[1] = l / 2 * (1 - alpha_sgn);
+    G[N] = l / 2 * (1 + alpha_sgn);
+    if N > 2 then
+      for i in 2:N - 1 loop
+        G[i] = l;
+      end for;
+    end if;
+//boundary conditions
+    C[1, 1] = if noEvent(infl.m_flow >= 0) then (1 - alpha_sgn / 2) * w[1] else 0;
+    C[N, N] = if noEvent(outfl.m_flow >= 0) then -(1 + alpha_sgn / 2) * w[N] else 0;
+    C[N, 1] = 0;
+    C[1, N] = 0;
+    if N > 2 then
+      for i in 2:N - 1 loop
+        C[1, i] = 0;
+        C[N, i] = 0;
+        for j in 1:N loop
+          C[i, j] = 0;
+        end for;
+      end for;
+    end if;
+    K[1, 1] = if noEvent(infl.m_flow >= 0) then (1 - alpha_sgn / 2) * inStream(infl.h_outflow) else 0;
+    K[N, N] = if noEvent(outfl.m_flow >= 0) then -(1 + alpha_sgn / 2) * inStream(outfl.h_outflow) else 0;
+    K[N, 1] = 0;
+    K[1, N] = 0;
+    if N > 2 then
+      for i in 2:N - 1 loop
+        K[1, i] = 0;
+        K[N, i] = 0;
+        for j in 1:N loop
+          K[i, j] = 0;
+        end for;
+      end for;
+    end if;
+// Momentum and Mass balance equation matrices
+    D[1] = l / 2;
+    D[N] = l / 2;
+    for i in 2:N - 1 loop
+      D[i] = l;
+    end for;
+    if HydraulicCapacitance == HCtypes.Middle then
+      D1 = l * (if N == 2 then {3 / 8, 1 / 8} else if evenN then cat(1, {1 / 2}, ones(max(0, div(N, 2) - 2)), {7 / 8, 1 / 8}, zeros(div(N, 2) - 1)) else cat(1, {1 / 2}, ones(div(N, 2) - 1), {1 / 2}, zeros(div(N, 2))));
+      D2 = l * (if N == 2 then {1 / 8, 3 / 8} else if evenN then cat(1, zeros(div(N, 2) - 1), {1 / 8, 7 / 8}, ones(max(div(N, 2) - 2, 0)), {1 / 2}) else cat(1, zeros(div(N, 2)), {1 / 2}, ones(div(N, 2) - 1), {1 / 2}));
+    elseif HydraulicCapacitance == HCtypes.Upstream then
+      D1 = zeros(N);
+      D2 = D;
+    elseif HydraulicCapacitance == HCtypes.Downstream then
+      D1 = D;
+      D2 = zeros(N);
+    else
+      assert(false, "Unsupported HydraulicCapacitance option");
+    end if;
+    by[1, 1] = 0;
+    by[2, 1] = 0;
+    by[3, 1] = l / 12 * rs[1] * (6 - 8 * rs[1] + 3 * rs[1] ^ 2 + alpha_sgn * (2 * rs[1] - 3));
+    by[4, 1] = -l / 12 * (1 - rs[1]) ^ 2 * (2 * alpha_sgn + 3 * rs[1] - 3);
+    by[5, 1] = -l / 12 * rs[1] ^ 2 * (2 * alpha_sgn + 3 * rs[1] - 4);
+    by[6, 1] = -l / 12 * (1 - rs[1]) * (3 * rs[1] ^ 2 - 2 * rs[1] + 2 * alpha_sgn * rs[1] + alpha_sgn - 1);
+    by[7, 1] = 0;
+    by[8, 1] = 0;
+    by[1, N] = l / 12 * rs[N - 1] ^ 2 * (2 * alpha_sgn + 3 * rs[N - 1]);
+    by[2, N] = l / 12 * (1 - rs[N - 1]) * (1 + alpha_sgn + 2 * rs[N - 1] + 2 * alpha_sgn * rs[N - 1] + 3 * rs[N - 1] ^ 2);
+    by[3, N] = 0;
+    by[4, N] = 0;
+    by[5, N] = 0;
+    by[6, N] = 0;
+    by[7, N] = l / 12 * rs[N - 1] * (alpha_sgn * (3 - 2 * rs[N - 1]) + rs[N - 1] * (4 - 3 * rs[N - 1]));
+    by[8, N] = l / 12 * (1 - rs[N - 1]) ^ 2 * (2 * alpha_sgn + 3 * rs[N - 1] + 1);
+    if N > 2 then
+      for i in 2:N - 1 loop
+        by[1, i] = l / 12 * rs[i - 1] ^ 2 * (2 * alpha_sgn + 3 * rs[i - 1]);
+        by[2, i] = l / 12 * (1 - rs[i - 1]) * (1 + alpha_sgn + 2 * rs[i - 1] + 2 * alpha_sgn * rs[i - 1] + 3 * rs[i - 1] ^ 2);
+        by[3, i] = l / 12 * rs[i] * (6 - 8 * rs[i] + 3 * rs[i] ^ 2 + alpha_sgn * (2 * rs[i] - 3));
+        by[4, i] = -l / 12 * (1 - rs[i]) ^ 2 * (2 * alpha_sgn + 3 * rs[i] - 3);
+        by[5, i] = -l / 12 * rs[i] ^ 2 * (2 * alpha_sgn + 3 * rs[i] - 4);
+        by[6, i] = -l / 12 * (1 - rs[i]) * (3 * rs[i] ^ 2 - 2 * rs[i] + 2 * alpha_sgn * rs[i] + alpha_sgn - 1);
+        by[7, i] = l / 12 * rs[i - 1] * (alpha_sgn * (3 - 2 * rs[i - 1]) + rs[i - 1] * (4 - 3 * rs[i - 1]));
+        by[8, i] = l / 12 * (1 - rs[i - 1]) ^ 2 * (2 * alpha_sgn + 3 * rs[i - 1] + 1);
+      end for;
+    end if;
+//additional 2 phases Y-matrix
+    Y2ph[1, 1] = gamma_rho[1] * by[3, 1] + gamma_rho[1] * by[4, 1];
+    Y2ph[1, 2] = gamma_rho[1] * by[5, 1] + gamma_rho[1] * by[6, 1];
+    Y2ph[N, N] = gamma_rho[N - 1] * by[1, N] + gamma_rho[N - 1] * by[2, N];
+    Y2ph[N, N - 1] = gamma_rho[N - 1] * by[7, N] + gamma_rho[N - 1] * by[8, N];
+    if N > 2 then
+      for i in 2:N - 1 loop
+        Y2ph[i, i - 1] = gamma_rho[i - 1] * by[7, i] + gamma_rho[i - 1] * by[8, i];
+        Y2ph[i, i] = gamma_rho[i - 1] * by[1, i] + gamma_rho[i - 1] * by[2, i] + gamma_rho[i] * by[3, i] + gamma_rho[i] * by[4, i];
+        Y2ph[i, i + 1] = gamma_rho[i] * by[5, i] + gamma_rho[i] * by[6, i];
+        Y2ph[1, i + 1] = 0;
+        Y2ph[N, i - 1] = 0;
+        for j in 1:i - 2 loop
+          Y2ph[i, j] = 0;
+        end for;
+        for j in i + 2:N loop
+          Y2ph[i, j] = 0;
+        end for;
+      end for;
+    end if;
+//computation of beta functions for additional matrices
+    beta[1, 1] = 0;
+    beta[2, 1] = 0;
+    beta[3, 1] = 1 / 12 * rs[1] * (3 * alpha_sgn + 4 * rs[1] - 6);
+    beta[4, 1] = 1 / 12 * (1 - rs[1]) * (3 * alpha_sgn + 4 * rs[1] - 4);
+    beta[5, 1] = -beta[3, 1];
+    beta[6, 1] = -beta[4, 1];
+    beta[7, 1] = 0;
+    beta[8, 1] = 0;
+    beta[1, N] = 1 / 12 * rs[N - 1] * (3 * alpha_sgn + 4 * rs[N - 1]);
+    beta[2, N] = 1 / 12 * (1 - rs[N - 1]) * (3 * alpha_sgn + 4 * rs[N - 1] + 2);
+    beta[3, N] = 0;
+    beta[4, N] = 0;
+    beta[5, N] = 0;
+    beta[6, N] = 0;
+    beta[7, N] = -beta[1, N];
+    beta[8, N] = -beta[2, N];
+    if N > 2 then
+      for i in 2:N - 1 loop
+        beta[1, i] = 1 / 12 * rs[i - 1] * (3 * alpha_sgn + 4 * rs[i - 1]);
+        beta[2, i] = 1 / 12 * (1 - rs[i - 1]) * (3 * alpha_sgn + 4 * rs[i - 1] + 2);
+        beta[3, i] = 1 / 12 * rs[i] * (3 * alpha_sgn + 4 * rs[i] - 6);
+        beta[4, i] = 1 / 12 * (1 - rs[i]) * (3 * alpha_sgn + 4 * rs[i] - 4);
+        beta[5, i] = -beta[3, i];
+        beta[6, i] = -beta[4, i];
+        beta[7, i] = -beta[1, i];
+        beta[8, i] = -beta[2, i];
+      end for;
+    end if;
+//additional 2 phases B-matrix
+    B2ph[1, 1] = gamma_w[1] * beta[3, 1] + gamma_w[1] * beta[4, 1];
+    B2ph[1, 2] = gamma_w[1] * beta[5, 1] + gamma_w[1] * beta[6, 1];
+    B2ph[N, N] = gamma_w[N - 1] * beta[1, N] + gamma_w[N - 1] * beta[2, N];
+    B2ph[N, N - 1] = gamma_w[N - 1] * beta[7, N] + gamma_w[N - 1] * beta[8, N];
+    if N > 2 then
+      for i in 2:N - 1 loop
+        B2ph[i, i - 1] = gamma_w[i - 1] * beta[7, i] + gamma_w[i - 1] * beta[8, i];
+        B2ph[i, i] = gamma_w[i - 1] * beta[1, i] + gamma_w[i - 1] * beta[2, i] + gamma_w[i] * beta[3, i] + gamma_w[i] * beta[4, i];
+        B2ph[i, i + 1] = gamma_w[i] * beta[5, i] + gamma_w[i] * beta[6, i];
+        B2ph[1, i + 1] = 0;
+        B2ph[N, i - 1] = 0;
+        for j in 1:i - 2 loop
+          B2ph[i, j] = 0;
+        end for;
+        for j in i + 2:N loop
+          B2ph[i, j] = 0;
+        end for;
+      end for;
+    end if;
+    Q = Nt * omega * D * phi "Total heat flow through lateral boundary";
+    Tr = noEvent(sum(rho) * A * l / max(infl.m_flow / Nt, Modelica.Constants.eps));
+  initial equation
+    if initOpt == Choices.Init.Options.noInit then
+// do nothing
+    elseif initOpt == Choices.Init.Options.fixedState then
+      if not noInitialPressure then
+        p = pstart;
+      end if;
+      h = hstart;
+    elseif initOpt == Choices.Init.Options.steadyState then
+      der(h) = zeros(N);
+      if not Medium.singleState and not noInitialPressure then
+        der(p) = 0;
+      end if;
+    elseif initOpt == Choices.Init.Options.steadyStateNoP then
+      der(h) = zeros(N);
+      assert(false, "initOpt = steadyStateNoP deprecated, use steadyState and noInitialPressure", AssertionLevel.warning);
+    elseif initOpt == Choices.Init.Options.steadyStateNoT and not Medium.singleState then
+      der(p) = 0;
+    else
+      assert(false, "Unsupported initialisation option");
+    end if;
+    annotation(
+      Diagram(graphics),
+      Icon(graphics = {Text(extent = {{-100, -40}, {100, -80}}, textString = "%name")}),
+      Documentation(info = "<HTML>
 <p>This model describes the flow of water or steam in a rigid tube. The basic modelling assumptions are:
 <ul><li>The fluid state is either one-phase, or a two-phase mixture.
 <li>In case of two-phase flow, the same velocity is assumed for both phases (homogeneous model).
@@ -3098,7 +2392,7 @@
 <p>Start values for pressure and flowrate are specified by <tt>pstart</tt>, <tt>wstart</tt>. The start values for the node enthalpies are linearly distributed from <tt>hstartin</tt> at the inlet to <tt>hstartout</tt> at the outlet.
 <p>A bank of <tt>Nt</tt> identical tubes working in parallel can be modelled by setting <tt>Nt > 1</tt>. The geometric parameters always refer to a <i>single</i> tube.
 <p>This models makes the temperature and external heat flow distributions visible through the <tt>wall</tt> connector. If other variables (e.g. the heat transfer coefficient) are needed by external components to compute the actual heat flow, the <tt>wall</tt> connector can be replaced by an extended version of the <tt>DHT</tt> connector.
-</HTML>", revisions="<html>
+</HTML>", revisions = "<html>
 <ul>
 <li><i>30 May 2005</i>
     by <a href=\"mailto:francesco.casella@polimi.it\">Francesco Casella</a>:<br>
@@ -3124,93 +2418,50 @@
        First release.</li>
 </ul>
 </html>
-"));
-  end Flow1DFEM2ph;
-
-  model FlowJoin "Joins two water/steam flows"
-    extends Icons.Water.FlowJoin;
-    replaceable package Medium = StandardWater constrainedby
-      Modelica.Media.Interfaces.PartialMedium "Medium model"
-      annotation(choicesAllMatching = true);
-    parameter Boolean allowFlowReversal=system.allowFlowReversal
-      "= true to allow flow reversal, false restricts to design direction"
-      annotation(Evaluate=true);
-    outer ThermoPower.System system "System wide properties";
-    constant SI.MassFlowRate wzero=1e-9
-      "Small flowrate to avoid singularity in computing the outlet enthalpy";
-    parameter Boolean rev_in1=allowFlowReversal "Allow flow reversal at in1"
-      annotation (Evaluate=true);
-    parameter Boolean rev_in2=allowFlowReversal "Allow flow reversal at in2"
-      annotation (Evaluate=true);
-    parameter Boolean rev_out=allowFlowReversal "Allow flow reversal at out"
-      annotation (Evaluate=true);
-    parameter Boolean checkFlowDirection=false "Check flow direction"
-      annotation (Dialog(enable=not rev_in1 or not rev_in2 or not rev_out));
-    FlangeB out(redeclare package Medium = Medium, m_flow(max=if
-            allowFlowReversal then +Modelica.Constants.inf else 0)) annotation (
-       Placement(transformation(extent={{40,-20},{80,20}}, rotation=0)));
-    FlangeA in1(redeclare package Medium = Medium, m_flow(min=if
-            allowFlowReversal then -Modelica.Constants.inf else 0)) annotation (
-       Placement(transformation(extent={{-80,20},{-40,60}}, rotation=0)));
-    FlangeA in2(redeclare package Medium = Medium, m_flow(min=if
-            allowFlowReversal then -Modelica.Constants.inf else 0)) annotation (
-       Placement(transformation(extent={{-80,-60},{-40,-20}}, rotation=0)));
-  equation
-    in1.m_flow + in2.m_flow + out.m_flow = 0 "Mass balance";
-    in1.p = out.p;
-    in2.p = out.p;
-
-    // Energy balance
-    out.h_outflow = homotopy(
-      if (in2.m_flow < 0 and rev_in2) then
-        inStream(in1.h_outflow)
-      else if (in1.m_flow < 0 and rev_in1) then
-         inStream(in2.h_outflow)
-      else
-        (inStream(in1.h_outflow)*(in1.m_flow + wzero) +
-         inStream(in2.h_outflow)*(in2.m_flow + wzero))/
-        (in1.m_flow + 2*wzero + in2.m_flow),
-      (inStream(in1.h_outflow)*(in1.m_flow + wzero) +
-       inStream(in2.h_outflow)*(in2.m_flow + wzero))/
-      (in1.m_flow + 2*wzero + in2.m_flow));
-
-    in1.h_outflow = homotopy(
-      if (in2.m_flow < 0 and rev_in2) then
-        inStream(out.h_outflow)
-      else if (out.m_flow < 0 or not rev_out) then
-        inStream(in2.h_outflow)
-      else
-        (inStream(out.h_outflow)*(out.m_flow + wzero) +
-         inStream(in2.h_outflow)*(in2.m_flow + wzero))/
-        (out.m_flow + 2*wzero + in2.m_flow),
-      inStream(out.h_outflow));
-
-    in2.h_outflow = homotopy(
-      if (in1.m_flow < 0 and rev_in1) then
-        inStream(out.h_outflow)
-      else if (out.m_flow < 0 or not rev_out) then
-        inStream(in1.h_outflow)
-      else
-        (inStream(out.h_outflow)*(out.m_flow + wzero) +
-         inStream(in1.h_outflow)*(in1.m_flow + wzero))/
-        (out.m_flow + 2*wzero + in1.m_flow),
-      inStream(out.h_outflow));
-
-    //Check flow direction
-    assert(not checkFlowDirection or
-      ((rev_in1 or in1.m_flow >= 0) and
-       (rev_in2 or in2.m_flow >= 0) and
-       (rev_out or out.m_flow <= 0)),
-      "Flow reversal not supported");
-    annotation (
-      Icon(graphics),
-      Documentation(info="<html>
+      "));
+  end Flow1DFEM2ph;
+
+  model FlowJoin "Joins two water/steam flows"
+    extends Icons.Water.FlowJoin;
+    replaceable package Medium = StandardWater constrainedby Modelica.Media.Interfaces.PartialMedium "Medium model" annotation(
+       choicesAllMatching = true);
+    parameter Boolean allowFlowReversal = system.allowFlowReversal "= true to allow flow reversal, false restricts to design direction" annotation(
+      Evaluate = true);
+    outer ThermoPower.System system "System wide properties";
+    constant SI.MassFlowRate wzero = 1e-9 "Small flowrate to avoid singularity in computing the outlet enthalpy";
+    parameter Boolean rev_in1 = allowFlowReversal "Allow flow reversal at in1" annotation(
+      Evaluate = true);
+    parameter Boolean rev_in2 = allowFlowReversal "Allow flow reversal at in2" annotation(
+      Evaluate = true);
+    parameter Boolean rev_out = allowFlowReversal "Allow flow reversal at out" annotation(
+      Evaluate = true);
+    parameter Boolean checkFlowDirection = false "Check flow direction" annotation(
+      Dialog(enable = not rev_in1 or not rev_in2 or not rev_out));
+    FlangeB out(redeclare package Medium = Medium, m_flow(max = if allowFlowReversal then +Modelica.Constants.inf else 0)) annotation(
+      Placement(transformation(extent = {{40, -20}, {80, 20}}, rotation = 0)));
+    FlangeA in1(redeclare package Medium = Medium, m_flow(min = if allowFlowReversal then -Modelica.Constants.inf else 0)) annotation(
+      Placement(transformation(extent = {{-80, 20}, {-40, 60}}, rotation = 0)));
+    FlangeA in2(redeclare package Medium = Medium, m_flow(min = if allowFlowReversal then -Modelica.Constants.inf else 0)) annotation(
+      Placement(transformation(extent = {{-80, -60}, {-40, -20}}, rotation = 0)));
+  equation
+    in1.m_flow + in2.m_flow + out.m_flow = 0 "Mass balance";
+    in1.p = out.p;
+    in2.p = out.p;
+// Energy balance
+    out.h_outflow = homotopy(if in2.m_flow < 0 and rev_in2 then inStream(in1.h_outflow) else if in1.m_flow < 0 and rev_in1 then inStream(in2.h_outflow) else (inStream(in1.h_outflow) * (in1.m_flow + wzero) + inStream(in2.h_outflow) * (in2.m_flow + wzero)) / (in1.m_flow + 2 * wzero + in2.m_flow), (inStream(in1.h_outflow) * (in1.m_flow + wzero) + inStream(in2.h_outflow) * (in2.m_flow + wzero)) / (in1.m_flow + 2 * wzero + in2.m_flow));
+    in1.h_outflow = homotopy(if in2.m_flow < 0 and rev_in2 then inStream(out.h_outflow) else if out.m_flow < 0 or not rev_out then inStream(in2.h_outflow) else (inStream(out.h_outflow) * (out.m_flow + wzero) + inStream(in2.h_outflow) * (in2.m_flow + wzero)) / (out.m_flow + 2 * wzero + in2.m_flow), inStream(out.h_outflow));
+    in2.h_outflow = homotopy(if in1.m_flow < 0 and rev_in1 then inStream(out.h_outflow) else if out.m_flow < 0 or not rev_out then inStream(in1.h_outflow) else (inStream(out.h_outflow) * (out.m_flow + wzero) + inStream(in1.h_outflow) * (in1.m_flow + wzero)) / (out.m_flow + 2 * wzero + in1.m_flow), inStream(out.h_outflow));
+//Check flow direction
+    assert(not checkFlowDirection or (rev_in1 or in1.m_flow >= 0) and (rev_in2 or in2.m_flow >= 0) and (rev_out or out.m_flow <= 0), "Flow reversal not supported");
+    annotation(
+      Icon(graphics),
+      Documentation(info = "<html>
 <p>This component allows to join two separate flows into one. The model is based on mass and energy balance equations, without any mass or energy buildup, and without any pressure drop between the inlet and the outlets.</p>
 <p>Since stream connectors are used in the library, this component is actually not necessary to handle a three-way connection. It can be used for a finer tuning of the simplified model for initialization using homotopy, in particularly hard-to-initialize systems, and it is included in the library for backwards compatibility.</p>
 <h4>Modelling options</h4>
 <p>If <code>rev_in1</code>, <code>rev_in2</code> or <code>rev_out</code> is true, the respective flows reversal is allowed. If at least ona among these parameters is false, it is possible to set <code>checkFlowDirection</code>.</p>
 <p>If <code>checkFlowDirection</code> is true, when the flow reversal happen where it is not allowed, the error message is showed.</p>
-</html>", revisions="<html>
+</html>", revisions = "<html>
 <ul>
 <li><i>30 Oct 2014</i>
     by <a href=\"mailto:francesco.casella@polimi.it\">Francesco Casella</a>:<br>
@@ -3226,91 +2477,51 @@
        First release.</li>
 </ul>
 </html>
-"),   Diagram(graphics));
-  end FlowJoin;
-
-  model FlowSplit "Splits a flow in two"
-    extends Icons.Water.FlowSplit;
-    replaceable package Medium = StandardWater constrainedby
-      Modelica.Media.Interfaces.PartialMedium "Medium model"
-      annotation(choicesAllMatching = true);
-    parameter Boolean allowFlowReversal=system.allowFlowReversal
-      "= true to allow flow reversal, false restricts to design direction"
-      annotation(Evaluate=true);
-    outer ThermoPower.System system "System wide properties";
-    constant SI.MassFlowRate wzero=1e-9
-      "Small flowrate to avoid singularity in computing the outlet enthalpy";
-    parameter Boolean rev_in1=allowFlowReversal "Allow flow reversal at in1"
-      annotation (Evaluate=true);
-    parameter Boolean rev_out1=allowFlowReversal "Allow flow reversal at out1"
-      annotation (Evaluate=true);
-    parameter Boolean rev_out2=allowFlowReversal "Allow flow reversal at out2"
-      annotation (Evaluate=true);
-    parameter Boolean checkFlowDirection=false "Check flow direction"
-      annotation (Dialog(enable=not rev_in1 or not rev_out1 or not rev_out2));
-    FlangeA in1(redeclare package Medium = Medium, m_flow(min=if
-            allowFlowReversal then -Modelica.Constants.inf else 0)) annotation (
-       Placement(transformation(extent={{-80,-20},{-40,20}}, rotation=0)));
-    FlangeB out1(redeclare package Medium = Medium, m_flow(max=if
-            allowFlowReversal then +Modelica.Constants.inf else 0)) annotation (
-       Placement(transformation(extent={{40,20},{80,60}}, rotation=0),
-          iconTransformation(extent={{40,20},{80,60}})));
-    FlangeB out2(redeclare package Medium = Medium, m_flow(max=if
-            allowFlowReversal then +Modelica.Constants.inf else 0)) annotation (
-       Placement(transformation(extent={{40,-60},{80,-20}}, rotation=0)));
-  equation
-    in1.m_flow + out1.m_flow + out2.m_flow = 0 "Mass balance";
-    out1.p = in1.p;
-    out2.p = in1.p;
-    // Energy balance
-    out1.h_outflow = homotopy(
-      if (in1.m_flow < 0 and rev_in1) then
-        inStream(out2.h_outflow)
-      else if (out2.m_flow < 0 or not rev_out2) then
-        inStream(in1.h_outflow)
-      else
-        (inStream(in1.h_outflow)*(in1.m_flow + wzero) +
-         inStream(out2.h_outflow)*(out2.m_flow + wzero))/
-        (in1.m_flow + 2*wzero + out2.m_flow),
-      inStream(in1.h_outflow));
-
-    out2.h_outflow = homotopy(
-      if (in1.m_flow < 0 and rev_in1) then
-        inStream(out1.h_outflow)
-      else if (out1.m_flow < 0 or not rev_out1) then
-        inStream(in1.h_outflow)
-      else
-        (inStream(in1.h_outflow)*(in1.m_flow + wzero) +
-         inStream(out1.h_outflow)*(out1.m_flow + wzero))/
-        (in1.m_flow + 2*wzero + out1.m_flow),
-      inStream(in1.h_outflow));
-
-    in1.h_outflow = homotopy(
-      if (out1.m_flow < 0 or not rev_out1) then
-         inStream(out2.h_outflow)
-      else if (out2.m_flow < 0 or not rev_out2) then
-         inStream(out1.h_outflow)
-      else
-        (inStream(out1.h_outflow)*(out1.m_flow + wzero) +
-         inStream(out2.h_outflow)*(out2.m_flow + wzero))/
-        (out1.m_flow + 2*wzero + out2.m_flow),
-      inStream(in1.h_outflow));
-
-    //Check flow direction
-    assert(not checkFlowDirection or
-     ((rev_in1 or in1.m_flow >= 0) and
-      (rev_out1 or out1.m_flow <= 0) and
-      (rev_out2 or out2.m_flow <= 0)),
-      "Flow reversal not supported");
-    annotation (
-      Icon(graphics),
-      Documentation(info="<html>
+      "),
+      Diagram(graphics));
+  end FlowJoin;
+
+  model FlowSplit "Splits a flow in two"
+    extends Icons.Water.FlowSplit;
+    replaceable package Medium = StandardWater constrainedby Modelica.Media.Interfaces.PartialMedium "Medium model" annotation(
+       choicesAllMatching = true);
+    parameter Boolean allowFlowReversal = system.allowFlowReversal "= true to allow flow reversal, false restricts to design direction" annotation(
+      Evaluate = true);
+    outer ThermoPower.System system "System wide properties";
+    constant SI.MassFlowRate wzero = 1e-9 "Small flowrate to avoid singularity in computing the outlet enthalpy";
+    parameter Boolean rev_in1 = allowFlowReversal "Allow flow reversal at in1" annotation(
+      Evaluate = true);
+    parameter Boolean rev_out1 = allowFlowReversal "Allow flow reversal at out1" annotation(
+      Evaluate = true);
+    parameter Boolean rev_out2 = allowFlowReversal "Allow flow reversal at out2" annotation(
+      Evaluate = true);
+    parameter Boolean checkFlowDirection = false "Check flow direction" annotation(
+      Dialog(enable = not rev_in1 or not rev_out1 or not rev_out2));
+    FlangeA in1(redeclare package Medium = Medium, m_flow(min = if allowFlowReversal then -Modelica.Constants.inf else 0)) annotation(
+      Placement(transformation(extent = {{-80, -20}, {-40, 20}}, rotation = 0)));
+    FlangeB out1(redeclare package Medium = Medium, m_flow(max = if allowFlowReversal then +Modelica.Constants.inf else 0)) annotation(
+      Placement(transformation(extent = {{40, 20}, {80, 60}}, rotation = 0), iconTransformation(extent = {{40, 20}, {80, 60}})));
+    FlangeB out2(redeclare package Medium = Medium, m_flow(max = if allowFlowReversal then +Modelica.Constants.inf else 0)) annotation(
+      Placement(transformation(extent = {{40, -60}, {80, -20}}, rotation = 0)));
+  equation
+    in1.m_flow + out1.m_flow + out2.m_flow = 0 "Mass balance";
+    out1.p = in1.p;
+    out2.p = in1.p;
+// Energy balance
+    out1.h_outflow = homotopy(if in1.m_flow < 0 and rev_in1 then inStream(out2.h_outflow) else if out2.m_flow < 0 or not rev_out2 then inStream(in1.h_outflow) else (inStream(in1.h_outflow) * (in1.m_flow + wzero) + inStream(out2.h_outflow) * (out2.m_flow + wzero)) / (in1.m_flow + 2 * wzero + out2.m_flow), inStream(in1.h_outflow));
+    out2.h_outflow = homotopy(if in1.m_flow < 0 and rev_in1 then inStream(out1.h_outflow) else if out1.m_flow < 0 or not rev_out1 then inStream(in1.h_outflow) else (inStream(in1.h_outflow) * (in1.m_flow + wzero) + inStream(out1.h_outflow) * (out1.m_flow + wzero)) / (in1.m_flow + 2 * wzero + out1.m_flow), inStream(in1.h_outflow));
+    in1.h_outflow = homotopy(if out1.m_flow < 0 or not rev_out1 then inStream(out2.h_outflow) else if out2.m_flow < 0 or not rev_out2 then inStream(out1.h_outflow) else (inStream(out1.h_outflow) * (out1.m_flow + wzero) + inStream(out2.h_outflow) * (out2.m_flow + wzero)) / (out1.m_flow + 2 * wzero + out2.m_flow), inStream(in1.h_outflow));
+//Check flow direction
+    assert(not checkFlowDirection or (rev_in1 or in1.m_flow >= 0) and (rev_out1 or out1.m_flow <= 0) and (rev_out2 or out2.m_flow <= 0), "Flow reversal not supported");
+    annotation(
+      Icon(graphics),
+      Documentation(info = "<html>
 <p>This component allows to split a single flow in two ones. The model is based on mass and energy balance equations, without any mass or energy buildup, and without any pressure drop between the inlet and the outlets. </p>
 <p>Since stream connectors are used in the library, this component is actually not necessary to handle a three-way connection. It can be used for a finer tuning of the simplified model for initialization using homotopy, in particularly hard-to-initialize systems, and it is included in the library for backwards compatibility.</p>
 <h4>Modelling options</h4>
 <p>If <code>rev_in1</code>, <code>rev_out1</code> or <code>rev_out2</code> is true, the respective flows reversal is allowed. If at least ona among these parameters is false, it is possible to set <code>checkFlowDirection</code>.</p>
 <p>If <code>checkFlowDirection</code> is true, when the flow reversal happen where it is not allowed, the error message is showed.</p>
-</html>", revisions="<html>
+</html>", revisions = "<html>
 <ul>
 <li><i>30 Oct 2014</i>
     by <a href=\"mailto:francesco.casella@polimi.it\">Francesco Casella</a>:<br>
@@ -3326,50 +2537,41 @@
        First release.</li>
 </ul>
 </html>
-"));
-  end FlowSplit;
-
-  model SensT "Temperature sensor for water-steam"
-    extends Icons.Water.SensThrough;
-    replaceable package Medium = StandardWater constrainedby
-      Modelica.Media.Interfaces.PartialMedium "Medium model"
-      annotation(choicesAllMatching = true);
-    parameter Boolean allowFlowReversal=system.allowFlowReversal
-      "= true to allow flow reversal, false restricts to design direction"
-      annotation(Evaluate=true);
-    outer ThermoPower.System system "System wide properties";
-    Medium.SpecificEnthalpy h "Specific enthalpy of the fluid";
-    Medium.ThermodynamicState fluidState "Thermodynamic state of the fluid";
-    FlangeA inlet(redeclare package Medium = Medium, m_flow(min=if
-            allowFlowReversal then -Modelica.Constants.inf else 0)) annotation (
-       Placement(transformation(extent={{-80,-60},{-40,-20}}, rotation=0)));
-    FlangeB outlet(redeclare package Medium = Medium, m_flow(max=if
-            allowFlowReversal then +Modelica.Constants.inf else 0)) annotation (
-       Placement(transformation(extent={{40,-60},{80,-20}}, rotation=0)));
-    Modelica.Blocks.Interfaces.RealOutput T annotation (Placement(
-          transformation(extent={{60,40},{100,80}}, rotation=0)));
-  equation
-    inlet.m_flow + outlet.m_flow = 0 "Mass balance";
-    inlet.p = outlet.p "No pressure drop";
-    // Set fluid properties
-    h = homotopy(if not allowFlowReversal then inStream(inlet.h_outflow) else
-      actualStream(inlet.h_outflow), inStream(inlet.h_outflow));
-    fluidState = Medium.setState_phX(inlet.p, h);
-    T = Medium.temperature(fluidState);
-
-    // Boundary conditions
-    inlet.h_outflow = inStream(outlet.h_outflow);
-    inStream(inlet.h_outflow) = outlet.h_outflow;
-    annotation (
-      Diagram(graphics),
-      Icon(graphics={Text(
-            extent={{-40,84},{38,34}},
-            lineColor={0,0,0},
-            textString="T")}),
-      Documentation(info="<HTML>
+      "));
+  end FlowSplit;
+
+  model SensT "Temperature sensor for water-steam"
+    extends Icons.Water.SensThrough;
+    replaceable package Medium = StandardWater constrainedby Modelica.Media.Interfaces.PartialMedium "Medium model" annotation(
+       choicesAllMatching = true);
+    parameter Boolean allowFlowReversal = system.allowFlowReversal "= true to allow flow reversal, false restricts to design direction" annotation(
+      Evaluate = true);
+    outer ThermoPower.System system "System wide properties";
+    Medium.SpecificEnthalpy h "Specific enthalpy of the fluid";
+    Medium.ThermodynamicState fluidState "Thermodynamic state of the fluid";
+    FlangeA inlet(redeclare package Medium = Medium, m_flow(min = if allowFlowReversal then -Modelica.Constants.inf else 0)) annotation(
+      Placement(transformation(extent = {{-80, -60}, {-40, -20}}, rotation = 0)));
+    FlangeB outlet(redeclare package Medium = Medium, m_flow(max = if allowFlowReversal then +Modelica.Constants.inf else 0)) annotation(
+      Placement(transformation(extent = {{40, -60}, {80, -20}}, rotation = 0)));
+    Modelica.Blocks.Interfaces.RealOutput T annotation(
+      Placement(transformation(extent = {{60, 40}, {100, 80}}, rotation = 0)));
+  equation
+    inlet.m_flow + outlet.m_flow = 0 "Mass balance";
+    inlet.p = outlet.p "No pressure drop";
+// Set fluid properties
+    h = homotopy(if not allowFlowReversal then inStream(inlet.h_outflow) else actualStream(inlet.h_outflow), inStream(inlet.h_outflow));
+    fluidState = Medium.setState_phX(inlet.p, h);
+    T = Medium.temperature(fluidState);
+// Boundary conditions
+    inlet.h_outflow = inStream(outlet.h_outflow);
+    inStream(inlet.h_outflow) = outlet.h_outflow;
+    annotation(
+      Diagram(graphics),
+      Icon(graphics = {Text(extent = {{-40, 84}, {38, 34}}, lineColor = {0, 0, 0}, textString = "T")}),
+      Documentation(info = "<HTML>
 <p>This component can be inserted in a hydraulic circuit to measure the temperature of the fluid flowing through it.
 <p>Flow reversal is supported.
-</HTML>", revisions="<html>
+</HTML>", revisions = "<html>
 <ul>
 <li><i>16 Dec 2004</i>
     by <a href=\"mailto:francesco.casella@polimi.it\">Francesco Casella</a>:<br>
@@ -3381,32 +2583,27 @@
     by <a href=\"mailto:francesco.casella@polimi.it\">Francesco Casella</a>:<br>
        First release.</li>
 </ul>
-</html>"));
-  end SensT;
-
-  model SensT1 "Temperature sensor for water/steam flows, single port"
-    extends ThermoPower.Icons.Water.SensP;
-    replaceable package Medium = ThermoPower.Water.StandardWater constrainedby
-      Modelica.Media.Interfaces.PartialMedium "Medium model"
-      annotation(choicesAllMatching = true);
-    Modelica.Blocks.Interfaces.RealOutput T annotation (Placement(
-          transformation(extent={{60,40},{100,80}}, rotation=0)));
-    FlangeA flange(redeclare package Medium = Medium, m_flow(min=0))
-      annotation (Placement(transformation(extent={{-20,-60},{20,-20}},
-            rotation=0)));
-  equation
-    flange.m_flow = 0;
-    flange.h_outflow = 0;
-    T = Medium.temperature(Medium.setState_phX(flange.p, inStream(flange.h_outflow)));
-    annotation (
-      Diagram(graphics),
-      Icon(graphics={Text(
-            extent={{-40,84},{38,34}},
-            lineColor={0,0,0},
-            textString="T")}),
-      Documentation(info="<HTML>
+</html>"));
+  end SensT;
+
+  model SensT1 "Temperature sensor for water/steam flows, single port"
+    extends ThermoPower.Icons.Water.SensP;
+    replaceable package Medium = ThermoPower.Water.StandardWater constrainedby Modelica.Media.Interfaces.PartialMedium "Medium model" annotation(
+       choicesAllMatching = true);
+    Modelica.Blocks.Interfaces.RealOutput T annotation(
+      Placement(transformation(extent = {{60, 40}, {100, 80}}, rotation = 0)));
+    FlangeA flange(redeclare package Medium = Medium, m_flow(min = 0)) annotation(
+      Placement(transformation(extent = {{-20, -60}, {20, -20}}, rotation = 0)));
+  equation
+    flange.m_flow = 0;
+    flange.h_outflow = 0;
+    T = Medium.temperature(Medium.setState_phX(flange.p, inStream(flange.h_outflow)));
+    annotation(
+      Diagram(graphics),
+      Icon(graphics = {Text(extent = {{-40, 84}, {38, 34}}, lineColor = {0, 0, 0}, textString = "T")}),
+      Documentation(info = "<HTML>
 <p>This component can be connected to any A-type or B-type connector to measure the pressure of the fluid flowing through it. In this case, it is possible to connect more than two <tt>Flange</tt> connectors together.
-</HTML>", revisions="<html>
+</HTML>", revisions = "<html>
 <ul>
 <li><i>16 Dec 2004</i>
     by <a href=\"mailto:francesco.casella@polimi.it\">Francesco Casella</a>:<br>
@@ -3415,44 +2612,36 @@
     by <a href=\"mailto:francesco.casella@polimi.it\">Francesco Casella</a>:<br>
        First release.</li>
 </ul>
-</html>"));
-  end SensT1;
-
-  model SensW "Mass Flowrate sensor for water/steam"
-    extends Icons.Water.SensThrough;
-    replaceable package Medium = StandardWater constrainedby
-      Modelica.Media.Interfaces.PartialMedium "Medium model"
-      annotation(choicesAllMatching = true);
-    parameter Boolean allowFlowReversal=system.allowFlowReversal
-      "= true to allow flow reversal, false restricts to design direction"
-      annotation(Evaluate=true);
-    outer ThermoPower.System system "System wide properties";
-    FlangeA inlet(redeclare package Medium = Medium, m_flow(min=if
-            allowFlowReversal then -Modelica.Constants.inf else 0)) annotation (
-       Placement(transformation(extent={{-80,-60},{-40,-20}}, rotation=0)));
-    FlangeB outlet(redeclare package Medium = Medium, m_flow(max=if
-            allowFlowReversal then +Modelica.Constants.inf else 0)) annotation (
-       Placement(transformation(extent={{40,-60},{80,-20}}, rotation=0)));
-    Modelica.Blocks.Interfaces.RealOutput w annotation (Placement(
-          transformation(extent={{60,40},{100,80}}, rotation=0)));
-  equation
-    inlet.m_flow + outlet.m_flow = 0 "Mass balance";
-
-    // Boundary conditions
-    inlet.p = outlet.p;
-    inlet.h_outflow = inStream(outlet.h_outflow);
-    inStream(inlet.h_outflow) = outlet.h_outflow;
-    w = inlet.m_flow;
-    annotation (
-      Diagram(graphics),
-      Icon(graphics={Text(
-            extent={{-42,92},{40,32}},
-            lineColor={0,0,0},
-            textString="w")}),
-      Documentation(info="<HTML>
+</html>"));
+  end SensT1;
+
+  model SensW "Mass Flowrate sensor for water/steam"
+    extends Icons.Water.SensThrough;
+    replaceable package Medium = StandardWater constrainedby Modelica.Media.Interfaces.PartialMedium "Medium model" annotation(
+       choicesAllMatching = true);
+    parameter Boolean allowFlowReversal = system.allowFlowReversal "= true to allow flow reversal, false restricts to design direction" annotation(
+      Evaluate = true);
+    outer ThermoPower.System system "System wide properties";
+    FlangeA inlet(redeclare package Medium = Medium, m_flow(min = if allowFlowReversal then -Modelica.Constants.inf else 0)) annotation(
+      Placement(transformation(extent = {{-80, -60}, {-40, -20}}, rotation = 0)));
+    FlangeB outlet(redeclare package Medium = Medium, m_flow(max = if allowFlowReversal then +Modelica.Constants.inf else 0)) annotation(
+      Placement(transformation(extent = {{40, -60}, {80, -20}}, rotation = 0)));
+    Modelica.Blocks.Interfaces.RealOutput w annotation(
+      Placement(transformation(extent = {{60, 40}, {100, 80}}, rotation = 0)));
+  equation
+    inlet.m_flow + outlet.m_flow = 0 "Mass balance";
+// Boundary conditions
+    inlet.p = outlet.p;
+    inlet.h_outflow = inStream(outlet.h_outflow);
+    inStream(inlet.h_outflow) = outlet.h_outflow;
+    w = inlet.m_flow;
+    annotation(
+      Diagram(graphics),
+      Icon(graphics = {Text(extent = {{-42, 92}, {40, 32}}, lineColor = {0, 0, 0}, textString = "w")}),
+      Documentation(info = "<HTML>
 <p>This component can be inserted in a hydraulic circuit to measure the flowrate of the fluid flowing through it.
 <p>Flow reversal is supported.
-</HTML>", revisions="<html>
+</HTML>", revisions = "<html>
 <ul>
 <li><i>16 Dec 2004</i>
     by <a href=\"mailto:francesco.casella@polimi.it\">Francesco Casella</a>:<br>
@@ -3462,32 +2651,27 @@
        First release.</li>
 </ul>
 </html>
-"));
-  end SensW;
-
-  model SensP "Pressure sensor for water/steam flows"
-    extends Icons.Water.SensP;
-    replaceable package Medium = StandardWater constrainedby
-      Modelica.Media.Interfaces.PartialMedium "Medium model"
-      annotation(choicesAllMatching = true);
-    Modelica.Blocks.Interfaces.RealOutput p annotation (Placement(
-          transformation(extent={{60,40},{100,80}}, rotation=0)));
-    FlangeA flange(redeclare package Medium = Medium, m_flow(min=0))
-      annotation (Placement(transformation(extent={{-20,-60},{20,-20}},
-            rotation=0)));
-  equation
-    flange.m_flow = 0;
-    p = flange.p;
-    flange.h_outflow = 0;
-    annotation (
-      Diagram(graphics),
-      Icon(graphics={Text(
-            extent={{-42,92},{44,36}},
-            lineColor={0,0,0},
-            textString="p")}),
-      Documentation(info="<HTML>
+      "));
+  end SensW;
+
+  model SensP "Pressure sensor for water/steam flows"
+    extends Icons.Water.SensP;
+    replaceable package Medium = StandardWater constrainedby Modelica.Media.Interfaces.PartialMedium "Medium model" annotation(
+       choicesAllMatching = true);
+    Modelica.Blocks.Interfaces.RealOutput p annotation(
+      Placement(transformation(extent = {{60, 40}, {100, 80}}, rotation = 0)));
+    FlangeA flange(redeclare package Medium = Medium, m_flow(min = 0)) annotation(
+      Placement(transformation(extent = {{-20, -60}, {20, -20}}, rotation = 0)));
+  equation
+    flange.m_flow = 0;
+    p = flange.p;
+    flange.h_outflow = 0;
+    annotation(
+      Diagram(graphics),
+      Icon(graphics = {Text(extent = {{-42, 92}, {44, 36}}, lineColor = {0, 0, 0}, textString = "p")}),
+      Documentation(info = "<HTML>
 <p>This component can be connected to any A-type or B-type connector to measure the pressure of the fluid flowing through it. In this case, it is possible to connect more than two <tt>Flange</tt> connectors together.
-</HTML>", revisions="<html>
+</HTML>", revisions = "<html>
 <ul>
 <li><i>16 Dec 2004</i>
     by <a href=\"mailto:francesco.casella@polimi.it\">Francesco Casella</a>:<br>
@@ -3496,156 +2680,127 @@
     by <a href=\"mailto:francesco.casella@polimi.it\">Francesco Casella</a>:<br>
        First release.</li>
 </ul>
-</html>"));
-  end SensP;
-
-  model Accumulator "Water-Gas Accumulator"
-    extends ThermoPower.Icons.Water.Accumulator;
-    replaceable package Medium = StandardWater constrainedby
-      Modelica.Media.Interfaces.PartialMedium "Liquid medium model"
-      annotation(choicesAllMatching = true);
-    Medium.ThermodynamicState liquidState "Thermodynamic state of the liquid";
-
-    parameter SI.Volume V "Total volume";
-    parameter SI.Volume Vl0 "Water nominal volume (at reference level)";
-    parameter SI.Area A "Cross Sectional Area";
-
-    parameter SI.Height zl0
-      "Height of water reference level over inlet/outlet connectors";
-    parameter SI.Height zl_start "Water start level (relative to reference)"
-      annotation (Dialog(tab="Initialisation"));
-    parameter Medium.SpecificEnthalpy hl_start "Water start specific enthalpy"
-      annotation (Dialog(tab="Initialisation"));
-    parameter SI.Pressure pg_start "Gas start pressure"
-      annotation (Dialog(tab="Initialisation"));
-    parameter Units.AbsoluteTemperature Tg_start=300 "Gas start temperature"
-      annotation (Dialog(tab="Initialisation"));
-    parameter SI.CoefficientOfHeatTransfer gamma_ex=50
-      "Water-Gas heat transfer coefficient";
-    parameter SI.Temperature Tgin=300 "Inlet gas temperature";
-    parameter SI.MolarMass MM=29e-3 "Gas molar mass";
-    parameter SI.MassFlowRate wg_out0 "Nominal gas outlet flowrate";
-    parameter Units.AbsoluteTemperature Tg0=300 "Nominal gas temperature";
-    parameter Units.AbsolutePressure pg0 "Nominal gas pressure";
-    parameter Boolean allowFlowReversal=system.allowFlowReversal
-      "= true to allow flow reversal, false restricts to design direction"
-      annotation(Evaluate=true);
-    outer ThermoPower.System system "System wide properties";
-    parameter Choices.Init.Options initOpt=system.initOpt
-      "Initialisation option"
-      annotation (Dialog(tab="Initialisation"));
-    parameter Boolean noInitialPressure=false
-      "Remove initial equation on pressure"
-      annotation (Dialog(tab="Initialisation"),choices(checkBox=true));
-  protected
-    constant SI.Acceleration g=Modelica.Constants.g_n;
-    constant Real R=Modelica.Constants.R "Universal gas constant";
-    parameter SI.SpecificHeatCapacityAtConstantPressure cpg=(7/2)*Rstar
-      "Cp of gas";
-    parameter SI.SpecificHeatCapacityAtConstantVolume cvg=(5/2)*Rstar
-      "Cv of gas";
-    parameter Real Rstar=R/MM "Gas constant";
-    parameter Real K=wg_out0/(pg0*sqrt(Tg0)) "Gas outlet flow coefficient";
-  public
-    Medium.MassFlowRate wl_in "Water inflow mass flow rate";
-    Medium.MassFlowRate wl_out "Water outflow mass flow rate";
-    SI.Height zl(start=zl_start) "Water level (relative to reference)";
-    Medium.SpecificEnthalpy hl_in "Water inlet specific enthalpy";
-    Medium.SpecificEnthalpy hl_out "Water outlet specific enthalpy";
-    Medium.SpecificEnthalpy hl(start=hl_start, stateSelect=StateSelect.prefer)
-      "Water internal specific enthalpy";
-    SI.Volume Vl "Volume occupied by water";
-    SI.Mass Mg "Mass of gas";
-    Medium.AbsolutePressure pf "Water Pressure at the inlet/outlet flanges";
-    SI.EnergyFlowRate Qp "Water-Gas heat flow";
-    SI.MassFlowRate wg_in "Gas inflow mass flow rate";
-    SI.MassFlowRate wg_out "Gas outflow mass flow rate";
-    Units.GasDensity rhog(start=pg_start*MM/(R*Tg_start)) "Gas density";
-    Medium.Temperature Tg(start=Tg_start) "Gas temperature";
-    SI.Volume Vg "Volume occupied by gas";
-    Medium.AbsolutePressure pg(start=pg_start) "Gas pressure";
-    Units.LiquidDensity rho "Density of the water";
-    Modelica.Blocks.Interfaces.RealInput GasInfl annotation (Placement(
-          transformation(extent={{-84,80},{-64,100}}, rotation=0)));
-    FlangeA WaterInfl(redeclare package Medium = Medium, m_flow(min=if
-            allowFlowReversal then -Modelica.Constants.inf else 0)) annotation (
-       Placement(transformation(extent={{-44,-100},{-24,-80}}, rotation=0)));
-    FlangeB WaterOutfl(redeclare package Medium = Medium, m_flow(max=if
-            allowFlowReversal then +Modelica.Constants.inf else 0)) annotation (
-       Placement(transformation(extent={{24,-100},{44,-80}}, rotation=0)));
-    Modelica.Blocks.Interfaces.RealInput OutletValveOpening annotation (
-        Placement(transformation(
-          origin={44,90},
-          extent={{-10,-10},{10,10}},
-          rotation=270)));
-  equation
-
-    //Equations for water and gas volumes and exchanged thermal power
-    Vl = Vl0 + A*zl;
-    Vg = V - Vl;
-    Qp = gamma_ex*A*(Medium.temperature(liquidState) - Tg);
-
-    // Boundary conditions
-    // (Thermal effects of the water going out of the accumulator are neglected)
-    hl_in = homotopy(if not allowFlowReversal then inStream(WaterInfl.h_outflow)
-       else if wl_in >= 0 then inStream(WaterInfl.h_outflow) else hl, inStream(
-      WaterInfl.h_outflow));
-    hl_out = homotopy(if not allowFlowReversal then hl else if wl_out >= 0
-       then inStream(WaterOutfl.h_outflow) else hl, hl);
-    WaterInfl.h_outflow = inStream(WaterOutfl.h_outflow);
-    WaterOutfl.h_outflow = inStream(WaterInfl.h_outflow);
-    wl_in = WaterInfl.m_flow;
-    wl_out = WaterOutfl.m_flow;
-    WaterInfl.p = pf;
-    WaterOutfl.p = pf;
-
-    rho*A*der(zl) = wl_in + wl_out
-      "Water mass balance (density variations neglected)";
-    rho*Vl*der(hl) - Vl*der(pg) - pg*der(Vl) = wl_in*(hl_in - hl) + wl_out*(
-      hl_out - hl) - Qp "Water energy balance";
-
-    // Set liquid properties
-    liquidState = Medium.setState_phX(pg, hl);
-    rho = Medium.density(liquidState);
-
-    pf = pg + rho*g*(zl + zl0) "Stevino's law";
-
-    wg_in = GasInfl "Gas inlet mass-flow rate";
-
-    //Gas outlet mass-flow rate
-    wg_out = -OutletValveOpening*K*pg*sqrt(Tg);
-
-    pg = rhog*Rstar*Tg "Gas state equation";
-    Mg = Vg*rhog "Gas mass";
-    der(Mg) = wg_in + wg_out "Gas mass balance";
-    rhog*Vg*cpg*der(Tg) = wg_in*cpg*(Tgin - Tg) + Vg*der(pg) + Qp
-      "Gas energy balance";
-  initial equation
-    if initOpt == Choices.Init.Options.noInit then
-      // do nothing
-    elseif initOpt == Choices.Init.Options.fixedState then
-      zl = zl_start;
-      Tg = Tg_start;
-      hl = hl_start;
-      if not noInitialPressure then
-        pg = pg_start;
-      end if;
-    elseif initOpt == Choices.Init.Options.steadyState then
-      zl = zl_start;
-      der(Tg) = 0;
-      der(hl) = 0;
-      der(pg) = 0;
-    elseif initOpt == Choices.Init.Options.steadyStateNoP then
-      zl = zl_start;
-      der(Tg) = 0;
-      der(hl) = 0;
-    else
-      assert(false, "Unsupported initialisation option");
-    end if;
-    annotation (
-      Diagram(graphics),
-      Icon(graphics),
-      Documentation(info="<HTML>
+</html>"));
+  end SensP;
+
+  model Accumulator "Water-Gas Accumulator"
+    extends ThermoPower.Icons.Water.Accumulator;
+    replaceable package Medium = StandardWater constrainedby Modelica.Media.Interfaces.PartialMedium "Liquid medium model" annotation(
+       choicesAllMatching = true);
+    Medium.ThermodynamicState liquidState "Thermodynamic state of the liquid";
+    parameter SI.Volume V "Total volume";
+    parameter SI.Volume Vl0 "Water nominal volume (at reference level)";
+    parameter SI.Area A "Cross Sectional Area";
+    parameter SI.Height zl0 "Height of water reference level over inlet/outlet connectors";
+    parameter SI.Height zl_start "Water start level (relative to reference)" annotation(
+      Dialog(tab = "Initialisation"));
+    parameter Medium.SpecificEnthalpy hl_start "Water start specific enthalpy" annotation(
+      Dialog(tab = "Initialisation"));
+    parameter SI.Pressure pg_start "Gas start pressure" annotation(
+      Dialog(tab = "Initialisation"));
+    parameter Units.AbsoluteTemperature Tg_start = 300 "Gas start temperature" annotation(
+      Dialog(tab = "Initialisation"));
+    parameter SI.CoefficientOfHeatTransfer gamma_ex = 50 "Water-Gas heat transfer coefficient";
+    parameter SI.Temperature Tgin = 300 "Inlet gas temperature";
+    parameter SI.MolarMass MM = 29e-3 "Gas molar mass";
+    parameter SI.MassFlowRate wg_out0 "Nominal gas outlet flowrate";
+    parameter Units.AbsoluteTemperature Tg0 = 300 "Nominal gas temperature";
+    parameter Units.AbsolutePressure pg0 "Nominal gas pressure";
+    parameter Boolean allowFlowReversal = system.allowFlowReversal "= true to allow flow reversal, false restricts to design direction" annotation(
+      Evaluate = true);
+    outer ThermoPower.System system "System wide properties";
+    parameter Choices.Init.Options initOpt = system.initOpt "Initialisation option" annotation(
+      Dialog(tab = "Initialisation"));
+    parameter Boolean noInitialPressure = false "Remove initial equation on pressure" annotation(
+      Dialog(tab = "Initialisation"),
+      choices(checkBox = true));
+  protected
+    constant SI.Acceleration g = Modelica.Constants.g_n;
+    constant Real R = Modelica.Constants.R "Universal gas constant";
+    parameter SI.SpecificHeatCapacityAtConstantPressure cpg = 7 / 2 * Rstar "Cp of gas";
+    parameter SI.SpecificHeatCapacityAtConstantVolume cvg = 5 / 2 * Rstar "Cv of gas";
+    parameter Real Rstar = R / MM "Gas constant";
+    parameter Real K = wg_out0 / (pg0 * sqrt(Tg0)) "Gas outlet flow coefficient";
+  public
+    Medium.MassFlowRate wl_in "Water inflow mass flow rate";
+    Medium.MassFlowRate wl_out "Water outflow mass flow rate";
+    SI.Height zl(start = zl_start) "Water level (relative to reference)";
+    Medium.SpecificEnthalpy hl_in "Water inlet specific enthalpy";
+    Medium.SpecificEnthalpy hl_out "Water outlet specific enthalpy";
+    Medium.SpecificEnthalpy hl(start = hl_start, stateSelect = StateSelect.prefer) "Water internal specific enthalpy";
+    SI.Volume Vl "Volume occupied by water";
+    SI.Mass Mg "Mass of gas";
+    Medium.AbsolutePressure pf "Water Pressure at the inlet/outlet flanges";
+    SI.EnergyFlowRate Qp "Water-Gas heat flow";
+    SI.MassFlowRate wg_in "Gas inflow mass flow rate";
+    SI.MassFlowRate wg_out "Gas outflow mass flow rate";
+    Units.GasDensity rhog(start = pg_start * MM / (R * Tg_start)) "Gas density";
+    Medium.Temperature Tg(start = Tg_start) "Gas temperature";
+    SI.Volume Vg "Volume occupied by gas";
+    Medium.AbsolutePressure pg(start = pg_start) "Gas pressure";
+    Units.LiquidDensity rho "Density of the water";
+    Modelica.Blocks.Interfaces.RealInput GasInfl annotation(
+      Placement(transformation(extent = {{-84, 80}, {-64, 100}}, rotation = 0)));
+    FlangeA WaterInfl(redeclare package Medium = Medium, m_flow(min = if allowFlowReversal then -Modelica.Constants.inf else 0)) annotation(
+      Placement(transformation(extent = {{-44, -100}, {-24, -80}}, rotation = 0)));
+    FlangeB WaterOutfl(redeclare package Medium = Medium, m_flow(max = if allowFlowReversal then +Modelica.Constants.inf else 0)) annotation(
+      Placement(transformation(extent = {{24, -100}, {44, -80}}, rotation = 0)));
+    Modelica.Blocks.Interfaces.RealInput OutletValveOpening annotation(
+      Placement(transformation(origin = {44, 90}, extent = {{-10, -10}, {10, 10}}, rotation = 270)));
+  equation
+//Equations for water and gas volumes and exchanged thermal power
+    Vl = Vl0 + A * zl;
+    Vg = V - Vl;
+    Qp = gamma_ex * A * (Medium.temperature(liquidState) - Tg);
+// Boundary conditions
+// (Thermal effects of the water going out of the accumulator are neglected)
+    hl_in = homotopy(if not allowFlowReversal then inStream(WaterInfl.h_outflow) else if wl_in >= 0 then inStream(WaterInfl.h_outflow) else hl, inStream(WaterInfl.h_outflow));
+    hl_out = homotopy(if not allowFlowReversal then hl else if wl_out >= 0 then inStream(WaterOutfl.h_outflow) else hl, hl);
+    WaterInfl.h_outflow = inStream(WaterOutfl.h_outflow);
+    WaterOutfl.h_outflow = inStream(WaterInfl.h_outflow);
+    wl_in = WaterInfl.m_flow;
+    wl_out = WaterOutfl.m_flow;
+    WaterInfl.p = pf;
+    WaterOutfl.p = pf;
+    rho * A * der(zl) = wl_in + wl_out "Water mass balance (density variations neglected)";
+    rho * Vl * der(hl) - Vl * der(pg) - pg * der(Vl) = wl_in * (hl_in - hl) + wl_out * (hl_out - hl) - Qp "Water energy balance";
+// Set liquid properties
+    liquidState = Medium.setState_phX(pg, hl);
+    rho = Medium.density(liquidState);
+    pf = pg + rho * g * (zl + zl0) "Stevino's law";
+    wg_in = GasInfl "Gas inlet mass-flow rate";
+//Gas outlet mass-flow rate
+    wg_out = -OutletValveOpening * K * pg * sqrt(Tg);
+    pg = rhog * Rstar * Tg "Gas state equation";
+    Mg = Vg * rhog "Gas mass";
+    der(Mg) = wg_in + wg_out "Gas mass balance";
+    rhog * Vg * cpg * der(Tg) = wg_in * cpg * (Tgin - Tg) + Vg * der(pg) + Qp "Gas energy balance";
+  initial equation
+    if initOpt == Choices.Init.Options.noInit then
+// do nothing
+    elseif initOpt == Choices.Init.Options.fixedState then
+      zl = zl_start;
+      Tg = Tg_start;
+      hl = hl_start;
+      if not noInitialPressure then
+        pg = pg_start;
+      end if;
+    elseif initOpt == Choices.Init.Options.steadyState then
+      zl = zl_start;
+      der(Tg) = 0;
+      der(hl) = 0;
+      der(pg) = 0;
+    elseif initOpt == Choices.Init.Options.steadyStateNoP then
+      zl = zl_start;
+      der(Tg) = 0;
+      der(hl) = 0;
+    else
+      assert(false, "Unsupported initialisation option");
+    end if;
+    annotation(
+      Diagram(graphics),
+      Icon(graphics),
+      Documentation(info = "<HTML>
 <p>This model describes a water-gas accumulator (the gas is modeled as ideal bi-atomic). <p>
 Water flows in and out through the interfaces at the component bottom (flow reversal supported). <p>
 The gas is supposed to flow in at constant temperature (parameter <tt>Tgin</tt>) and with variable flow-rate (<tt>GasInfl</tt> signal port), and to flow out by a valve operating in choked condition; the valve coefficient is determined by the working point at full opening (<tt>wg_out0,Tg0, Pg0</tt>) while the valve opening (in the range <tt>0-1</tt>) is an input signal (<tt>OutletValveOpening</tt> signal port).
@@ -3656,7 +2811,7 @@
 <li><tt>zl0</tt>: height of water nominal level above the water connectors;
 <li><tt>A</tt>: cross-sectional area at actual water level;
 </ul>
-</HTML>", revisions="<html>
+</HTML>", revisions = "<html>
 <ul>
 <li><i>30 May 2005</i>
     by <a href=\"mailto:francesco.casella@polimi.it\">Francesco Casella</a>:<br>
@@ -3671,295 +2826,227 @@
     by <a href=\"mailto:francesco.schiavo@polimi.it\">Francesco Schiavo</a>:<br>
        First release.</li>
 </ul>
-</html>"));
-  end Accumulator;
-
-  model Drum "Drum for circulation boilers"
-    extends Icons.Water.Drum;
-    replaceable package Medium = StandardWater constrainedby
-      Modelica.Media.Interfaces.PartialTwoPhaseMedium "Medium model"
-      annotation(choicesAllMatching = true);
-    Medium.ThermodynamicState liquidState "Thermodynamic state of the liquid";
-    Medium.ThermodynamicState vapourState "Thermodynamic state of the vapour";
-    Medium.SaturationProperties sat;
-    parameter SI.Length rint=0 "Internal radius";
-    parameter SI.Length rext=0 "External radius";
-    parameter SI.Length L=0 "Length";
-    parameter SI.HeatCapacity Cm=0 "Total Heat Capacity of the metal wall"
-      annotation (Evaluate=true);
-    parameter SI.Temperature Text=293 "External atmospheric temperature";
-    parameter SI.Time tauev=15 "Time constant of bulk evaporation";
-    parameter SI.Time tauc=15 "Time constant of bulk condensation";
-    parameter Real Kcs=0 "Surface condensation coefficient [kg/(s.m2.K)]";
-    parameter Real Ks=0 "Surface heat transfer coefficient [W/(m2.K)]";
-    parameter SI.CoefficientOfHeatTransfer gext=0
-      "Heat transfer coefficient between metal wall and external atmosphere";
-    parameter SI.CoefficientOfHeatTransfer gl=200
-      "Heat transfer coefficient between metal wall and liquid phase"
-      annotation (Evaluate=true);
-    parameter SI.CoefficientOfHeatTransfer gv=200
-      "Heat transfer coefficient between metal wall and vapour phase"
-      annotation (Evaluate=true);
-    parameter SI.ThermalConductivity lm=20 "Metal wall thermal conductivity";
-    parameter Real afd=0.05 "Ratio of feedwater in downcomer flowrate";
-    parameter Real avr=1.2 "Phase separation efficiency coefficient";
-    parameter Integer DrumOrientation=0 "0: Horizontal; 1: Vertical";
-    parameter Boolean allowFlowReversal=system.allowFlowReversal
-      "= true to allow flow reversal, false restricts to design direction"
-      annotation(Evaluate=true);
-    outer ThermoPower.System system "System wide properties";
-    parameter Medium.AbsolutePressure pstart=1e5 "Pressure start value"
-      annotation (Dialog(tab="Initialisation"));
-    parameter Medium.SpecificEnthalpy hlstart=Medium.bubbleEnthalpy(Medium.setSat_p(
-        pstart)) "Liquid enthalpy start value"
-      annotation (Dialog(tab="Initialisation"));
-    parameter Medium.SpecificEnthalpy hvstart=Medium.dewEnthalpy(Medium.setSat_p(
-        pstart)) "Vapour enthalpy start value"
-      annotation (Dialog(tab="Initialisation"));
-    parameter Medium.Temperature Tmstart = Medium.saturationTemperature(pstart)
-      "Wall temperature start value"
-      annotation (Dialog(tab="Initialisation"));
-    parameter SI.Length ystart=0 "Start level value"
-      annotation (Dialog(tab="Initialisation"));
-    parameter Choices.Init.Options initOpt=system.initOpt
-      "Initialisation option"
-      annotation (Dialog(tab="Initialisation"));
-    parameter Boolean noInitialPressure=false
-      "Remove initial equation on pressure"
-      annotation (Dialog(tab="Initialisation"),choices(checkBox=true));
-    constant SI.Acceleration g=Modelica.Constants.g_n;
-    constant Real pi=Modelica.Constants.pi;
-
-    SI.Volume Vv(start=pi*rint^2*L/2) "Volume occupied by the vapour";
-    SI.Volume Vl(start=pi*rint^2*L/2) "Volume occupied by the liquid";
-    Medium.AbsolutePressure p(start=pstart, stateSelect=StateSelect.prefer)
-      "Surface pressure";
-    SI.SpecificEnthalpy hl(start=hlstart, stateSelect=StateSelect.prefer)
-      "Liquid specific enthalpy";
-    SI.SpecificEnthalpy hv(start=hvstart, stateSelect=StateSelect.prefer)
-      "Vapour specific enthalpy";
-    SI.SpecificEnthalpy hrv
-      "Specific enthalpy of vapour from the risers after separation";
-    SI.SpecificEnthalpy hrl
-      "Specific enthalpy of liquid from the risers after separation";
-    SI.SpecificEnthalpy hls "Specific enthalpy of saturated liquid";
-    SI.SpecificEnthalpy hvs "Specific enthalpy of saturated vapour";
-    SI.SpecificEnthalpy hf "Specific enthalpy of feedwater";
-    SI.SpecificEnthalpy hd "Specific enthalpy of liquid to the downcomers";
-    SI.SpecificEnthalpy hvout "Specific enthalpy of steam at the outlet";
-    SI.SpecificEnthalpy hr "Specific enthalpy of fluid from the risers";
-    Medium.MassFlowRate wf "Mass flowrate of feedwater";
-    Medium.MassFlowRate wd "Mass flowrate to the downcomers";
-    Medium.MassFlowRate wb "Mass flowrate of blowdown";
-    Medium.MassFlowRate wr "Mass flowrate from the risers";
-    Medium.MassFlowRate wrl "Mass flowrate of liquid from the risers";
-    Medium.MassFlowRate wrv "Mass flowrate of vapour from the risers";
-    Medium.MassFlowRate wv "Mass flowrate of steam at the outlet";
-    Medium.MassFlowRate wc "Mass flowrate of bulk condensation";
-    Medium.MassFlowRate wcs "Mass flowrate of surface condensation";
-    Medium.MassFlowRate wev "Mass flowrate of bulk evaporation";
-    Medium.Temperature Tl "Liquid temperature";
-    Medium.Temperature Tv "Vapour temperature";
-    Units.AbsoluteTemperature Tm(start=Tmstart,
-        stateSelect=if Cm > 0 then StateSelect.prefer else StateSelect.default)
-      "Wall temperature";
-    Medium.Temperature Ts "Saturated water temperature";
-    SI.Power Qmv "Heat flow from the wall to the vapour";
-    SI.Power Qvl "Heat flow from the vapour to the liquid";
-    SI.Power Qml "Heat flow from the wall to the liquid";
-    SI.Power Qme "Heat flow from the wall to the atmosphere";
-    SI.Mass Ml "Liquid mass";
-    SI.Mass Mv "Vapour mass";
-    SI.Energy El "Liquid internal energy";
-    SI.Energy Ev "Vapour internal energy";
-    Units.LiquidDensity rhol "Liquid density";
-    Units.GasDensity rhov "Vapour density";
-    SI.PerUnit xl "Mass fraction of vapour in the liquid volume";
-    SI.PerUnit xv "Steam quality in the vapour volume";
-    SI.PerUnit xr "Steam quality of the fluid from the risers";
-    SI.PerUnit xrv "Steam quality of the separated steam from the risers";
-    Real gml "Total heat transfer coefficient (wall-liquid)";
-    Real gmv "Total heat transfer coefficient (wall-vapour)";
-    Real a;
-    SI.Length y(start=ystart, stateSelect=StateSelect.prefer)
-      "Level (referred to the centreline)";
-    SI.Area Aml "Surface of the wall-liquid interface";
-    SI.Area Amv "Surface of the wall-vapour interface";
-    SI.Area Asup "Surface of the liquid-vapour interface";
-    SI.Area Aext "External drum surface";
-    FlangeA feedwater(
-      p(start=pstart),
-      h_outflow(start=hlstart),
-      redeclare package Medium = Medium,
-      m_flow(min=if allowFlowReversal then -Modelica.Constants.inf else 0))
-      annotation (Placement(transformation(extent={{-114,-32},{-80,2}},
-            rotation=0)));
-    FlangeA riser(
-      p(start=pstart),
-      h_outflow(start=hlstart),
-      redeclare package Medium = Medium,
-      m_flow(min=if allowFlowReversal then -Modelica.Constants.inf else 0))
-      annotation (Placement(transformation(extent={{60,-74},{96,-40}}, rotation=
-             0)));
-    FlangeB downcomer(
-      p(start=pstart),
-      h_outflow(start=hlstart),
-      redeclare package Medium = Medium,
-      m_flow(max=if allowFlowReversal then +Modelica.Constants.inf else 0))
-      annotation (Placement(transformation(extent={{-88,-88},{-52,-52}},
-            rotation=0)));
-    FlangeB blowdown(
-      p(start=pstart),
-      h_outflow(start=hlstart),
-      redeclare package Medium = Medium,
-      m_flow(max=if allowFlowReversal then +Modelica.Constants.inf else 0))
-      annotation (Placement(transformation(extent={{-18,-116},{18,-80}},
-            rotation=0)));
-    FlangeB steam(
-      p(start=pstart),
-      h_outflow(start=hvstart),
-      redeclare package Medium = Medium,
-      m_flow(max=if allowFlowReversal then +Modelica.Constants.inf else 0))
-      annotation (Placement(transformation(extent={{40,52},{76,88}}, rotation=0)));
-  equation
-    der(Mv) = wrv + wev - wv - wc - wcs "Vapour volume mass balance";
-    der(Ml) = wf + wrl + wc + wcs - wd - wb - wev "Liquid volume mass balance";
-    der(Ev) = wrv*hrv + (wev - wcs)*hvs - wc*hls - wv*hvout + Qmv - Qvl - p*der(
-      Vv) "Vapour volume energy balance";
-    der(El) = wf*hf + wrl*hrl + wc*hls + (wcs - wev)*hvs - wd*hd - wb*hl + Qml
-       + Qvl - p*der(Vl) "Liquid volume energy balance";
-    //Metal wall energy balance with singular cases
-    if Cm > 0 and (gl > 0 or gv > 0) then
-      Cm*der(Tm) = -Qml - Qmv - Qme "Metal wall dynamic energy balance";
-    elseif (gl > 0 or gv > 0) then
-      0 = -Qml - Qmv - Qme "Metal wall static energy balance";
-    else
-      Tm = 300 "Wall temperature doesn't matter";
-    end if;
-    Mv = Vv*rhov "Vapour volume mass";
-    Ml = Vl*rhol "Liquid volume mass";
-    Ev = Mv*Medium.specificInternalEnergy(vapourState) "Vapour volume energy";
-    El = Ml*Medium.specificInternalEnergy(liquidState) "Liquid volume energy";
-    wev = xl*rhol*Vl/tauev "Bulk evaporation flow rate in the liquid volume";
-    wc = (1 - xv)*rhov*Vv/tauc
-      "Bulk condensation flow rate in the vapour volume";
-    wcs = Kcs*Asup*(Ts - Tl) "Surface condensation flow rate";
-    Qme = gext*Aext*(Tm - Text)
-      "Heat flow from metal wall to external environment";
-    Qml = gml*Aml*(Tm - Tl) "Heat flow from metal wall to liquid volume";
-    Qmv = gmv*Amv*(Tm - Tv) "Heat flow from metal wall to vapour volume";
-    Qvl = Ks*Asup*(Tv - Ts) "Heat flow from vapour to liquid volume";
-    xv = homotopy(if hv >= hvs then 1 else (hv - hls)/(hvs - hls), (hv - hls)/(
-      hvs - hls)) "Steam quality in the vapour volume";
-    xl = homotopy(if hl <= hls then 0 else (hl - hls)/(hvs - hls), 0)
-      "Steam quality in the liquid volume";
-    gml = if gl == 0 then 0 else 1/(1/gl + a*rint/lm)
-      "Total Heat conductance metal-liquid";
-    gmv = if gv == 0 then 0 else 1/(1/gv + a*rint/lm)
-      "Total Heat conductance metal-vapour";
-    a = rext^2/(rext^2 - rint^2)*log(rext/rint) - 0.5;
-    if DrumOrientation == 0 then
-      Vl = L*(rint^2*acos(-y/rint) + y*sqrt(rint^2 - y^2)) "Liquid volume";
-      Aml = 2*Vl/L + 2*rint*acos(-y/rint)*L "Metal-liquid interface area";
-      Asup = 2*sqrt(rint^2 - y^2)*L "Liquid-vapour interface area";
-    else
-      Vl = pi*rint^2*(y + L/2) "Liquid volume";
-      Aml = pi*rint^2 + 2*pi*rint*(y + L/2) "Metal-liquid interface area";
-      Asup = pi*rint^2 "Liquid-vapour interface area";
-    end if;
-    Vv = pi*rint^2*L - Vl "Vapour volume";
-    Amv = 2*pi*rint*L + 2*pi*rint^2 - Aml "Metal-vapour interface area";
-    Aext = 2*pi*rext^2 + 2*pi*rext*L "External metal surface area";
-
-    // Fluid properties
-    liquidState = Medium.setState_phX(p, hl);
-    Tl = Medium.temperature(liquidState);
-    rhol = Medium.density(liquidState);
-    vapourState = Medium.setState_phX(p, hv);
-    Tv = Medium.temperature(vapourState);
-    rhov = Medium.density(vapourState);
-    sat.psat = p;
-    sat.Tsat = Medium.saturationTemperature(p);
-    hls = Medium.bubbleEnthalpy(sat);
-    hvs = Medium.dewEnthalpy(sat);
-    Ts = sat.Tsat;
-
-    // Boundary conditions
-    feedwater.p = p;
-    feedwater.m_flow = wf;
-    feedwater.h_outflow = hl;
-    hf = homotopy(if not allowFlowReversal then inStream(feedwater.h_outflow)
-       else noEvent(actualStream(feedwater.h_outflow)), inStream(feedwater.h_outflow));
-    downcomer.p = p + rhol*g*y;
-    downcomer.m_flow = -wd;
-    downcomer.h_outflow = hd;
-    hd = homotopy(if not allowFlowReversal then afd*hf + (1 - afd)*hl else
-      noEvent(if wd >= 0 then afd*hf + (1 - afd)*hl else inStream(downcomer.h_outflow)),
-      afd*hf + (1 - afd)*hl);
-    blowdown.p = p;
-    blowdown.m_flow = -wb;
-    blowdown.h_outflow = hl;
-    riser.p = p;
-    riser.m_flow = wr;
-    riser.h_outflow = hl;
-    hrv = hls + xrv*(hvs - hls);
-    xrv = homotopy(1 - (rhov/rhol)^avr, 1 - (Medium.dewDensity(Medium.setSat_p(
-      pstart))/Medium.bubbleDensity(Medium.setSat_p(pstart)))^avr);
-    hr = homotopy(if not allowFlowReversal then inStream(riser.h_outflow) else
-      noEvent(actualStream(riser.h_outflow)), inStream(riser.h_outflow));
-    xr = homotopy(if not allowFlowReversal then (if hr > hls then (hr - hls)/(
-      hvs - hls) else 0) else noEvent(if wr >= 0 then (if hr > hls then (hr -
-      hls)/(hvs - hls) else 0) else xl), (hr - hls)/(hvs - hls));
-    hrl = homotopy(if not allowFlowReversal then (if hr > hls then hls else hr)
-       else noEvent(if wr >= 0 then (if hr > hls then hls else hr) else hl),
-      hls);
-    wrv = homotopy(if not allowFlowReversal then xr*wr/xrv else noEvent(if wr
-       >= 0 then xr*wr/xrv else 0), xr*wr/xrv);
-    wrl = wr - wrv;
-    steam.p = p;
-    steam.m_flow = -wv;
-    steam.h_outflow = hv;
-    hvout = homotopy(if not allowFlowReversal then hv else noEvent(actualStream(
-      steam.h_outflow)), hv);
-  initial equation
-    if initOpt == Choices.Init.Options.noInit then
-      // do nothing
-    elseif initOpt == Choices.Init.Options.fixedState then
-      if not noInitialPressure then
-        p = pstart;
-      end if;
-      hl = hlstart;
-      hv = hvstart;
-      y = ystart;
-      if Cm > 0 and (gl > 0 or gv > 0) then
-        Tm = Tmstart;
-      end if;
-    elseif initOpt == Choices.Init.Options.steadyState then
-      der(p) = 0;
-      der(hl) = 0;
-      der(hv) = 0;
-      der(y) = 0;
-      if Cm > 0 and (gl > 0 or gv > 0) then
-        der(Tm) = 0;
-      end if;
-    elseif initOpt == Choices.Init.Options.steadyStateNoP then
-      der(hl) = 0;
-      der(hv) = 0;
-      der(y) = 0;
-      if Cm > 0 and (gl > 0 or gv > 0) then
-        der(Tm) = 0;
-      end if;
-    else
-      assert(false, "Unsupported initialisation option");
-    end if;
-    annotation (
-      Icon(graphics={
-          Text(extent={{-150,26},{-78,0}}, textString="Feed"),
-          Text(extent={{-180,-34},{-66,-58}}, textString="Downcomer"),
-          Text(extent={{-38,-102},{46,-142}}, textString="Blowdown"),
-          Text(extent={{52,-22},{146,-40}}, textString="Risers"),
-          Text(extent={{-22,100},{50,80}}, textString="Steam")}),
-      Documentation(info="<HTML>
+</html>"));
+  end Accumulator;
+
+  model Drum "Drum for circulation boilers"
+    extends Icons.Water.Drum;
+    replaceable package Medium = StandardWater constrainedby Modelica.Media.Interfaces.PartialTwoPhaseMedium "Medium model" annotation(
+       choicesAllMatching = true);
+    Medium.ThermodynamicState liquidState "Thermodynamic state of the liquid";
+    Medium.ThermodynamicState vapourState "Thermodynamic state of the vapour";
+    Medium.SaturationProperties sat;
+    parameter SI.Length rint = 0 "Internal radius";
+    parameter SI.Length rext = 0 "External radius";
+    parameter SI.Length L = 0 "Length";
+    parameter SI.HeatCapacity Cm = 0 "Total Heat Capacity of the metal wall" annotation(
+      Evaluate = true);
+    parameter SI.Temperature Text = 293 "External atmospheric temperature";
+    parameter SI.Time tauev = 15 "Time constant of bulk evaporation";
+    parameter SI.Time tauc = 15 "Time constant of bulk condensation";
+    parameter Real Kcs = 0 "Surface condensation coefficient [kg/(s.m2.K)]";
+    parameter Real Ks = 0 "Surface heat transfer coefficient [W/(m2.K)]";
+    parameter SI.CoefficientOfHeatTransfer gext = 0 "Heat transfer coefficient between metal wall and external atmosphere";
+    parameter SI.CoefficientOfHeatTransfer gl = 200 "Heat transfer coefficient between metal wall and liquid phase" annotation(
+      Evaluate = true);
+    parameter SI.CoefficientOfHeatTransfer gv = 200 "Heat transfer coefficient between metal wall and vapour phase" annotation(
+      Evaluate = true);
+    parameter SI.ThermalConductivity lm = 20 "Metal wall thermal conductivity";
+    parameter Real afd = 0.05 "Ratio of feedwater in downcomer flowrate";
+    parameter Real avr = 1.2 "Phase separation efficiency coefficient";
+    parameter Integer DrumOrientation = 0 "0: Horizontal; 1: Vertical";
+    parameter Boolean allowFlowReversal = system.allowFlowReversal "= true to allow flow reversal, false restricts to design direction" annotation(
+      Evaluate = true);
+    outer ThermoPower.System system "System wide properties";
+    parameter Medium.AbsolutePressure pstart = 1e5 "Pressure start value" annotation(
+      Dialog(tab = "Initialisation"));
+    parameter Medium.SpecificEnthalpy hlstart = Medium.bubbleEnthalpy(Medium.setSat_p(pstart)) "Liquid enthalpy start value" annotation(
+      Dialog(tab = "Initialisation"));
+    parameter Medium.SpecificEnthalpy hvstart = Medium.dewEnthalpy(Medium.setSat_p(pstart)) "Vapour enthalpy start value" annotation(
+      Dialog(tab = "Initialisation"));
+    parameter Medium.Temperature Tmstart = Medium.saturationTemperature(pstart) "Wall temperature start value" annotation(
+      Dialog(tab = "Initialisation"));
+    parameter SI.Length ystart = 0 "Start level value" annotation(
+      Dialog(tab = "Initialisation"));
+    parameter Choices.Init.Options initOpt = system.initOpt "Initialisation option" annotation(
+      Dialog(tab = "Initialisation"));
+    parameter Boolean noInitialPressure = false "Remove initial equation on pressure" annotation(
+      Dialog(tab = "Initialisation"),
+      choices(checkBox = true));
+    constant SI.Acceleration g = Modelica.Constants.g_n;
+    constant Real pi = Modelica.Constants.pi;
+    SI.Volume Vv(start = pi * rint ^ 2 * L / 2) "Volume occupied by the vapour";
+    SI.Volume Vl(start = pi * rint ^ 2 * L / 2) "Volume occupied by the liquid";
+    Medium.AbsolutePressure p(start = pstart, stateSelect = StateSelect.prefer) "Surface pressure";
+    SI.SpecificEnthalpy hl(start = hlstart, stateSelect = StateSelect.prefer) "Liquid specific enthalpy";
+    SI.SpecificEnthalpy hv(start = hvstart, stateSelect = StateSelect.prefer) "Vapour specific enthalpy";
+    SI.SpecificEnthalpy hrv "Specific enthalpy of vapour from the risers after separation";
+    SI.SpecificEnthalpy hrl "Specific enthalpy of liquid from the risers after separation";
+    SI.SpecificEnthalpy hls "Specific enthalpy of saturated liquid";
+    SI.SpecificEnthalpy hvs "Specific enthalpy of saturated vapour";
+    SI.SpecificEnthalpy hf "Specific enthalpy of feedwater";
+    SI.SpecificEnthalpy hd "Specific enthalpy of liquid to the downcomers";
+    SI.SpecificEnthalpy hvout "Specific enthalpy of steam at the outlet";
+    SI.SpecificEnthalpy hr "Specific enthalpy of fluid from the risers";
+    Medium.MassFlowRate wf "Mass flowrate of feedwater";
+    Medium.MassFlowRate wd "Mass flowrate to the downcomers";
+    Medium.MassFlowRate wb "Mass flowrate of blowdown";
+    Medium.MassFlowRate wr "Mass flowrate from the risers";
+    Medium.MassFlowRate wrl "Mass flowrate of liquid from the risers";
+    Medium.MassFlowRate wrv "Mass flowrate of vapour from the risers";
+    Medium.MassFlowRate wv "Mass flowrate of steam at the outlet";
+    Medium.MassFlowRate wc "Mass flowrate of bulk condensation";
+    Medium.MassFlowRate wcs "Mass flowrate of surface condensation";
+    Medium.MassFlowRate wev "Mass flowrate of bulk evaporation";
+    Medium.Temperature Tl "Liquid temperature";
+    Medium.Temperature Tv "Vapour temperature";
+    Units.AbsoluteTemperature Tm(start = Tmstart, stateSelect = if Cm > 0 then StateSelect.prefer else StateSelect.default) "Wall temperature";
+    Medium.Temperature Ts "Saturated water temperature";
+    SI.Power Qmv "Heat flow from the wall to the vapour";
+    SI.Power Qvl "Heat flow from the vapour to the liquid";
+    SI.Power Qml "Heat flow from the wall to the liquid";
+    SI.Power Qme "Heat flow from the wall to the atmosphere";
+    SI.Mass Ml "Liquid mass";
+    SI.Mass Mv "Vapour mass";
+    SI.Energy El "Liquid internal energy";
+    SI.Energy Ev "Vapour internal energy";
+    Units.LiquidDensity rhol "Liquid density";
+    Units.GasDensity rhov "Vapour density";
+    SI.PerUnit xl "Mass fraction of vapour in the liquid volume";
+    SI.PerUnit xv "Steam quality in the vapour volume";
+    SI.PerUnit xr "Steam quality of the fluid from the risers";
+    SI.PerUnit xrv "Steam quality of the separated steam from the risers";
+    Real gml "Total heat transfer coefficient (wall-liquid)";
+    Real gmv "Total heat transfer coefficient (wall-vapour)";
+    Real a;
+    SI.Length y(start = ystart, stateSelect = StateSelect.prefer) "Level (referred to the centreline)";
+    SI.Area Aml "Surface of the wall-liquid interface";
+    SI.Area Amv "Surface of the wall-vapour interface";
+    SI.Area Asup "Surface of the liquid-vapour interface";
+    SI.Area Aext "External drum surface";
+    FlangeA feedwater(p(start = pstart), h_outflow(start = hlstart), redeclare package Medium = Medium, m_flow(min = if allowFlowReversal then -Modelica.Constants.inf else 0)) annotation(
+      Placement(transformation(extent = {{-114, -32}, {-80, 2}}, rotation = 0)));
+    FlangeA riser(p(start = pstart), h_outflow(start = hlstart), redeclare package Medium = Medium, m_flow(min = if allowFlowReversal then -Modelica.Constants.inf else 0)) annotation(
+      Placement(transformation(extent = {{60, -74}, {96, -40}}, rotation = 0)));
+    FlangeB downcomer(p(start = pstart), h_outflow(start = hlstart), redeclare package Medium = Medium, m_flow(max = if allowFlowReversal then +Modelica.Constants.inf else 0)) annotation(
+      Placement(transformation(extent = {{-88, -88}, {-52, -52}}, rotation = 0)));
+    FlangeB blowdown(p(start = pstart), h_outflow(start = hlstart), redeclare package Medium = Medium, m_flow(max = if allowFlowReversal then +Modelica.Constants.inf else 0)) annotation(
+      Placement(transformation(extent = {{-18, -116}, {18, -80}}, rotation = 0)));
+    FlangeB steam(p(start = pstart), h_outflow(start = hvstart), redeclare package Medium = Medium, m_flow(max = if allowFlowReversal then +Modelica.Constants.inf else 0)) annotation(
+      Placement(transformation(extent = {{40, 52}, {76, 88}}, rotation = 0)));
+  equation
+    der(Mv) = wrv + wev - wv - wc - wcs "Vapour volume mass balance";
+    der(Ml) = wf + wrl + wc + wcs - wd - wb - wev "Liquid volume mass balance";
+    der(Ev) = wrv * hrv + (wev - wcs) * hvs - wc * hls - wv * hvout + Qmv - Qvl - p * der(Vv) "Vapour volume energy balance";
+    der(El) = wf * hf + wrl * hrl + wc * hls + (wcs - wev) * hvs - wd * hd - wb * hl + Qml + Qvl - p * der(Vl) "Liquid volume energy balance";
+//Metal wall energy balance with singular cases
+    if Cm > 0 and (gl > 0 or gv > 0) then
+      Cm * der(Tm) = (-Qml) - Qmv - Qme "Metal wall dynamic energy balance";
+    elseif gl > 0 or gv > 0 then
+      0 = (-Qml) - Qmv - Qme "Metal wall static energy balance";
+    else
+      Tm = 300 "Wall temperature doesn't matter";
+    end if;
+    Mv = Vv * rhov "Vapour volume mass";
+    Ml = Vl * rhol "Liquid volume mass";
+    Ev = Mv * Medium.specificInternalEnergy(vapourState) "Vapour volume energy";
+    El = Ml * Medium.specificInternalEnergy(liquidState) "Liquid volume energy";
+    wev = xl * rhol * Vl / tauev "Bulk evaporation flow rate in the liquid volume";
+    wc = (1 - xv) * rhov * Vv / tauc "Bulk condensation flow rate in the vapour volume";
+    wcs = Kcs * Asup * (Ts - Tl) "Surface condensation flow rate";
+    Qme = gext * Aext * (Tm - Text) "Heat flow from metal wall to external environment";
+    Qml = gml * Aml * (Tm - Tl) "Heat flow from metal wall to liquid volume";
+    Qmv = gmv * Amv * (Tm - Tv) "Heat flow from metal wall to vapour volume";
+    Qvl = Ks * Asup * (Tv - Ts) "Heat flow from vapour to liquid volume";
+    xv = homotopy(if hv >= hvs then 1 else (hv - hls) / (hvs - hls), (hv - hls) / (hvs - hls)) "Steam quality in the vapour volume";
+    xl = homotopy(if hl <= hls then 0 else (hl - hls) / (hvs - hls), 0) "Steam quality in the liquid volume";
+    gml = if gl == 0 then 0 else 1 / (1 / gl + a * rint / lm) "Total Heat conductance metal-liquid";
+    gmv = if gv == 0 then 0 else 1 / (1 / gv + a * rint / lm) "Total Heat conductance metal-vapour";
+    a = rext ^ 2 / (rext ^ 2 - rint ^ 2) * log(rext / rint) - 0.5;
+    if DrumOrientation == 0 then
+      Vl = L * (rint ^ 2 * acos(-y / rint) + y * sqrt(rint ^ 2 - y ^ 2)) "Liquid volume";
+      Aml = 2 * Vl / L + 2 * rint * acos(-y / rint) * L "Metal-liquid interface area";
+      Asup = 2 * sqrt(rint ^ 2 - y ^ 2) * L "Liquid-vapour interface area";
+    else
+      Vl = pi * rint ^ 2 * (y + L / 2) "Liquid volume";
+      Aml = pi * rint ^ 2 + 2 * pi * rint * (y + L / 2) "Metal-liquid interface area";
+      Asup = pi * rint ^ 2 "Liquid-vapour interface area";
+    end if;
+    Vv = pi * rint ^ 2 * L - Vl "Vapour volume";
+    Amv = 2 * pi * rint * L + 2 * pi * rint ^ 2 - Aml "Metal-vapour interface area";
+    Aext = 2 * pi * rext ^ 2 + 2 * pi * rext * L "External metal surface area";
+// Fluid properties
+    liquidState = Medium.setState_phX(p, hl);
+    Tl = Medium.temperature(liquidState);
+    rhol = Medium.density(liquidState);
+    vapourState = Medium.setState_phX(p, hv);
+    Tv = Medium.temperature(vapourState);
+    rhov = Medium.density(vapourState);
+    sat.psat = p;
+    sat.Tsat = Medium.saturationTemperature(p);
+    hls = Medium.bubbleEnthalpy(sat);
+    hvs = Medium.dewEnthalpy(sat);
+    Ts = sat.Tsat;
+// Boundary conditions
+    feedwater.p = p;
+    feedwater.m_flow = wf;
+    feedwater.h_outflow = hl;
+    hf = homotopy(if not allowFlowReversal then inStream(feedwater.h_outflow) else noEvent(actualStream(feedwater.h_outflow)), inStream(feedwater.h_outflow));
+    downcomer.p = p + rhol * g * y;
+    downcomer.m_flow = -wd;
+    downcomer.h_outflow = hd;
+    hd = homotopy(if not allowFlowReversal then afd * hf + (1 - afd) * hl else noEvent(if wd >= 0 then afd * hf + (1 - afd) * hl else inStream(downcomer.h_outflow)), afd * hf + (1 - afd) * hl);
+    blowdown.p = p;
+    blowdown.m_flow = -wb;
+    blowdown.h_outflow = hl;
+    riser.p = p;
+    riser.m_flow = wr;
+    riser.h_outflow = hl;
+    hrv = hls + xrv * (hvs - hls);
+    xrv = homotopy(1 - (rhov / rhol) ^ avr, 1 - (Medium.dewDensity(Medium.setSat_p(pstart)) / Medium.bubbleDensity(Medium.setSat_p(pstart))) ^ avr);
+    hr = homotopy(if not allowFlowReversal then inStream(riser.h_outflow) else noEvent(actualStream(riser.h_outflow)), inStream(riser.h_outflow));
+    xr = homotopy(if not allowFlowReversal then if hr > hls then (hr - hls) / (hvs - hls) else 0 else noEvent(if wr >= 0 then if hr > hls then (hr - hls) / (hvs - hls) else 0 else xl), (hr - hls) / (hvs - hls));
+    hrl = homotopy(if not allowFlowReversal then if hr > hls then hls else hr else noEvent(if wr >= 0 then if hr > hls then hls else hr else hl), hls);
+    wrv = homotopy(if not allowFlowReversal then xr * wr / xrv else noEvent(if wr >= 0 then xr * wr / xrv else 0), xr * wr / xrv);
+    wrl = wr - wrv;
+    steam.p = p;
+    steam.m_flow = -wv;
+    steam.h_outflow = hv;
+    hvout = homotopy(if not allowFlowReversal then hv else noEvent(actualStream(steam.h_outflow)), hv);
+  initial equation
+    if initOpt == Choices.Init.Options.noInit then
+// do nothing
+    elseif initOpt == Choices.Init.Options.fixedState then
+      if not noInitialPressure then
+        p = pstart;
+      end if;
+      hl = hlstart;
+      hv = hvstart;
+      y = ystart;
+      if Cm > 0 and (gl > 0 or gv > 0) then
+        Tm = Tmstart;
+      end if;
+    elseif initOpt == Choices.Init.Options.steadyState then
+      der(p) = 0;
+      der(hl) = 0;
+      der(hv) = 0;
+      der(y) = 0;
+      if Cm > 0 and (gl > 0 or gv > 0) then
+        der(Tm) = 0;
+      end if;
+    elseif initOpt == Choices.Init.Options.steadyStateNoP then
+      der(hl) = 0;
+      der(hv) = 0;
+      der(y) = 0;
+      if Cm > 0 and (gl > 0 or gv > 0) then
+        der(Tm) = 0;
+      end if;
+    else
+      assert(false, "Unsupported initialisation option");
+    end if;
+    annotation(
+      Icon(graphics = {Text(extent = {{-150, 26}, {-78, 0}}, textString = "Feed"), Text(extent = {{-180, -34}, {-66, -58}}, textString = "Downcomer"), Text(extent = {{-38, -102}, {46, -142}}, textString = "Blowdown"), Text(extent = {{52, -22}, {146, -40}}, textString = "Risers"), Text(extent = {{-22, 100}, {50, 80}}, textString = "Steam")}),
+      Documentation(info = "<HTML>
 <p>This model describes the cylindrical drum of a drum boiler, without assuming thermodynamic equilibrium between the liquid and vapour holdups. Connectors are provided for feedwater inlet, steam outlet, downcomer outlet, riser inlet, and blowdown outlet.
 <p>The model is based on dynamic mass and energy balance equations of the liquid volume and vapour volume inside the drum. Mass and energy tranfer between the two phases is provided by bulk condensation and surface condensation of the vapour phase, and by bulk boiling of the liquid phase. Additional energy transfer can take place at the surface if the steam is superheated.
 <p>The riser flowrate is separated before entering the drum, at the vapour pressure. The (saturated) liquid fraction goes into the liquid volume; the (wet) vapour fraction goes into the vapour volume, vith a steam quality depending on the liquid/vapour density ratio and on the <tt>avr</tt> parameter.
@@ -3972,7 +3059,7 @@
 <ul><li><tt>DrumOrientation = 0</tt>: horizontal axis.
 <li><tt>DrumOrientation = 1</tt>: vertical axis.
 </ul>
-</HTML>", revisions="<html>
+</HTML>", revisions = "<html>
 <ul>
 <li><i>30 May 2005</i>
     by <a href=\"mailto:francesco.casella@polimi.it\">Francesco Casella</a>:<br>
@@ -3990,120 +3077,102 @@
     by <a href=\"mailto:francesco.casella@polimi.it\">Francesco Casella</a>:<br>
        First release.</li>
 </ul>
-"),   Diagram(graphics));
-  end Drum;
-
-  model DrumEquilibrium
-    extends Icons.Water.Drum;
-    replaceable package Medium = StandardWater constrainedby
-      Modelica.Media.Interfaces.PartialTwoPhaseMedium "Medium model"
-      annotation(choicesAllMatching = true);
-    parameter SI.Volume Vd "Drum internal volume";
-    parameter SI.Mass Mm "Drum metal mass";
-    parameter Medium.SpecificHeatCapacity cm
-      "Specific heat capacity of the metal";
-    parameter Boolean allowFlowReversal=system.allowFlowReversal
-      "= true to allow flow reversal, false restricts to design direction"
-      annotation(Evaluate=true);
-    outer ThermoPower.System system "System wide properties";
-    parameter SI.Pressure pstart "Pressure start value"
-      annotation (Dialog(tab="Initialisation"));
-    parameter SI.Volume Vlstart "Start value of drum water volume"
-      annotation (Dialog(tab="Initialisation"));
-    parameter Choices.Init.Options initOpt=system.initOpt
-      "Initialisation option"
-      annotation (Dialog(tab="Initialisation"));
-    parameter Boolean noInitialPressure=false
-      "Remove initial equation on pressure"
-      annotation (Dialog(tab="Initialisation"),choices(checkBox=true));
-
-    Medium.SaturationProperties sat "Saturation conditions";
-    FlangeA feed(redeclare package Medium = Medium, m_flow(min=if
-            allowFlowReversal then -Modelica.Constants.inf else 0)) annotation (
-       Placement(transformation(extent={{-110,-64},{-70,-24}}, rotation=0)));
-    FlangeB steam(redeclare package Medium = Medium, m_flow(max=if
-            allowFlowReversal then +Modelica.Constants.inf else 0)) annotation (
-       Placement(transformation(extent={{48,52},{88,92}}, rotation=0)));
-    Modelica.Thermal.HeatTransfer.Interfaces.HeatPort_a wall
-      "Metal wall thermal port" annotation (Placement(transformation(extent={{-28,
-              -100},{28,-80}}, rotation=0)));
-
-    SI.Mass Ml "Liquid water mass";
-    SI.Mass Mv "Steam mass";
-    SI.Mass M "Total liquid+steam mass";
-    SI.Energy E "Total energy";
-    SI.Volume Vv(start = Vd - Vlstart) "Steam volume";
-    SI.Volume Vl(
-      start = Vlstart,
-      stateSelect=StateSelect.prefer)
-      "Liquid water total volume";
-    Medium.AbsolutePressure p(
-      start=pstart,
-      stateSelect=StateSelect.prefer)
-      "Drum pressure";
-    Medium.MassFlowRate qf "Feedwater mass flowrate";
-    Medium.MassFlowRate qs "Steam mass flowrate";
-    SI.HeatFlowRate Q "Heat flow to the risers";
-    Medium.SpecificEnthalpy hf "Feedwater specific enthalpy";
-    Medium.SpecificEnthalpy hl "Specific enthalpy of saturated liquid";
-    Medium.SpecificEnthalpy hv "Specific enthalpy of saturated steam";
-    Medium.Temperature Ts "Saturation temperature";
-    Units.LiquidDensity rhol "Density of saturated liquid";
-    Units.GasDensity rhov "Density of saturated steam";
-  equation
-    Ml = Vl*rhol "Mass of liquid";
-    Mv = Vv*rhov "Mass of vapour";
-    M = Ml + Mv "Total mass";
-    E = Ml*hl + Mv*hv - p*Vd + Mm*cm*Ts "Total energy";
-    Ts = sat.Tsat "Saturation temperature";
-    der(M) = qf - qs "Mass balance";
-    der(E) = Q + qf*hf - qs*hv "Energy balance";
-    Vl + Vv = Vd "Total volume";
-
-    // Boundary conditions
-    p = feed.p;
-    p = steam.p;
-    if not allowFlowReversal then
-      hf = inStream(feed.h_outflow);
-    else
-      // assume flow is entering during simplified initialization
-      hf = homotopy(
-        actualStream(feed.h_outflow),
-        inStream(feed.h_outflow));
-    end if;
-    feed.m_flow = qf;
-    -steam.m_flow = qs;
-    feed.h_outflow = hl;
-    steam.h_outflow = hv;
-    Q = wall.Q_flow;
-    wall.T = Ts;
-
-    // Fluid properties
-    sat.psat = p;
-    sat.Tsat = Medium.saturationTemperature(p);
-    rhol = Medium.bubbleDensity(sat);
-    rhov = Medium.dewDensity(sat);
-    hl = Medium.bubbleEnthalpy(sat);
-    hv = Medium.dewEnthalpy(sat);
-  initial equation
-    if initOpt == Choices.Init.Options.noInit then
-      // do nothing
-    elseif initOpt == Choices.Init.Options.fixedState then
-      if not noInitialPressure then
-        p = pstart;
-      end if;
-      Vl = Vlstart;
-    elseif initOpt == Choices.Init.Options.steadyState then
-      if not noInitialPressure then
-        der(p) = 0;
-      end if;
-      der(Vl) = 0;
-    else
-      assert(false, "Unsupported initialisation option");
-    end if;
-    annotation (
-      Diagram(graphics),
-      Documentation(info="<HTML>
+      "),
+      Diagram(graphics));
+  end Drum;
+
+  model DrumEquilibrium
+    extends Icons.Water.Drum;
+    replaceable package Medium = StandardWater constrainedby Modelica.Media.Interfaces.PartialTwoPhaseMedium "Medium model" annotation(
+       choicesAllMatching = true);
+    parameter SI.Volume Vd "Drum internal volume";
+    parameter SI.Mass Mm "Drum metal mass";
+    parameter Medium.SpecificHeatCapacity cm "Specific heat capacity of the metal";
+    parameter Boolean allowFlowReversal = system.allowFlowReversal "= true to allow flow reversal, false restricts to design direction" annotation(
+      Evaluate = true);
+    outer ThermoPower.System system "System wide properties";
+    parameter SI.Pressure pstart "Pressure start value" annotation(
+      Dialog(tab = "Initialisation"));
+    parameter SI.Volume Vlstart "Start value of drum water volume" annotation(
+      Dialog(tab = "Initialisation"));
+    parameter Choices.Init.Options initOpt = system.initOpt "Initialisation option" annotation(
+      Dialog(tab = "Initialisation"));
+    parameter Boolean noInitialPressure = false "Remove initial equation on pressure" annotation(
+      Dialog(tab = "Initialisation"),
+      choices(checkBox = true));
+    Medium.SaturationProperties sat "Saturation conditions";
+    FlangeA feed(redeclare package Medium = Medium, m_flow(min = if allowFlowReversal then -Modelica.Constants.inf else 0)) annotation(
+      Placement(transformation(extent = {{-110, -64}, {-70, -24}}, rotation = 0)));
+    FlangeB steam(redeclare package Medium = Medium, m_flow(max = if allowFlowReversal then +Modelica.Constants.inf else 0)) annotation(
+      Placement(transformation(extent = {{48, 52}, {88, 92}}, rotation = 0)));
+    Modelica.Thermal.HeatTransfer.Interfaces.HeatPort_a wall "Metal wall thermal port" annotation(
+      Placement(transformation(extent = {{-28, -100}, {28, -80}}, rotation = 0)));
+    SI.Mass Ml "Liquid water mass";
+    SI.Mass Mv "Steam mass";
+    SI.Mass M "Total liquid+steam mass";
+    SI.Energy E "Total energy";
+    SI.Volume Vv(start = Vd - Vlstart) "Steam volume";
+    SI.Volume Vl(start = Vlstart, stateSelect = StateSelect.prefer) "Liquid water total volume";
+    Medium.AbsolutePressure p(start = pstart, stateSelect = StateSelect.prefer) "Drum pressure";
+    Medium.MassFlowRate qf "Feedwater mass flowrate";
+    Medium.MassFlowRate qs "Steam mass flowrate";
+    SI.HeatFlowRate Q "Heat flow to the risers";
+    Medium.SpecificEnthalpy hf "Feedwater specific enthalpy";
+    Medium.SpecificEnthalpy hl "Specific enthalpy of saturated liquid";
+    Medium.SpecificEnthalpy hv "Specific enthalpy of saturated steam";
+    Medium.Temperature Ts "Saturation temperature";
+    Units.LiquidDensity rhol "Density of saturated liquid";
+    Units.GasDensity rhov "Density of saturated steam";
+  equation
+    Ml = Vl * rhol "Mass of liquid";
+    Mv = Vv * rhov "Mass of vapour";
+    M = Ml + Mv "Total mass";
+    E = Ml * hl + Mv * hv - p * Vd + Mm * cm * Ts "Total energy";
+    Ts = sat.Tsat "Saturation temperature";
+    der(M) = qf - qs "Mass balance";
+    der(E) = Q + qf * hf - qs * hv "Energy balance";
+    Vl + Vv = Vd "Total volume";
+// Boundary conditions
+    p = feed.p;
+    p = steam.p;
+    if not allowFlowReversal then
+      hf = inStream(feed.h_outflow);
+    else
+// assume flow is entering during simplified initialization
+      hf = homotopy(actualStream(feed.h_outflow), inStream(feed.h_outflow));
+    end if;
+    feed.m_flow = qf;
+    -steam.m_flow = qs;
+    feed.h_outflow = hl;
+    steam.h_outflow = hv;
+    Q = wall.Q_flow;
+    wall.T = Ts;
+// Fluid properties
+    sat.psat = p;
+    sat.Tsat = Medium.saturationTemperature(p);
+    rhol = Medium.bubbleDensity(sat);
+    rhov = Medium.dewDensity(sat);
+    hl = Medium.bubbleEnthalpy(sat);
+    hv = Medium.dewEnthalpy(sat);
+  initial equation
+    if initOpt == Choices.Init.Options.noInit then
+// do nothing
+    elseif initOpt == Choices.Init.Options.fixedState then
+      if not noInitialPressure then
+        p = pstart;
+      end if;
+      Vl = Vlstart;
+    elseif initOpt == Choices.Init.Options.steadyState then
+      if not noInitialPressure then
+        der(p) = 0;
+      end if;
+      der(Vl) = 0;
+    else
+      assert(false, "Unsupported initialisation option");
+    end if;
+    annotation(
+      Diagram(graphics),
+      Documentation(info = "<HTML>
 <p>Simplified model of a drum for drum boilers and fire-tube boilers. This model assumes
 <ul>
 <li>Thermodynamic equiibrium between the liquid, vapour, and metal wall
@@ -4112,53 +3181,44 @@
 <p>The model has two state variables the pressure <code>p</code> and the liquid volume <code>Vl</code>. It is possible to extend it,
 adding a specific geometry and the computation of the level from the liquid volume. In that case, one may want to use the level as a state.
 </p>
-</HTML>", revisions="<html>
+</HTML>", revisions = "<html>
 <ul>
 <li><i>19 Feb 2019</i>
     by <a href=\"mailto:francesco.casella@polimi.it\">Francesco Casella</a>:<br>
        Adapted from old <code>Drum2States</code> model.</li>
 </ul>
-</html>"),
-      Icon(graphics));
-  end DrumEquilibrium;
-
-  model ValveLin "Valve for water/steam flows with linear pressure drop"
-    extends Icons.Water.Valve;
-    replaceable package Medium = StandardWater constrainedby
-      Modelica.Media.Interfaces.PartialMedium "Medium model"
-      annotation(choicesAllMatching = true);
-    parameter Units.HydraulicConductance Kv "Nominal hydraulic conductance";
-    parameter Boolean allowFlowReversal=system.allowFlowReversal
-      "= true to allow flow reversal, false restricts to design direction"
-      annotation(Evaluate=true);
-    outer ThermoPower.System system "System wide properties";
-    Medium.MassFlowRate w "Mass flowrate";
-    FlangeA inlet(redeclare package Medium = Medium, m_flow(min=if
-            allowFlowReversal then -Modelica.Constants.inf else 0)) annotation (
-       Placement(transformation(extent={{-120,-20},{-80,20}}, rotation=0)));
-    FlangeB outlet(redeclare package Medium = Medium, m_flow(max=if
-            allowFlowReversal then +Modelica.Constants.inf else 0)) annotation (
-       Placement(transformation(extent={{80,-20},{120,20}}, rotation=0)));
-    Modelica.Blocks.Interfaces.RealInput cmd annotation (Placement(
-          transformation(
-          origin={0,80},
-          extent={{-20,-20},{20,20}},
-          rotation=270)));
-  equation
-    inlet.m_flow + outlet.m_flow = 0 "Mass balance";
-    w = Kv*cmd*(inlet.p - outlet.p) "Valve characteristics";
-
-    // Boundary conditions
-    w = inlet.m_flow;
-    inlet.h_outflow = inStream(outlet.h_outflow);
-    inStream(inlet.h_outflow) = outlet.h_outflow;
-
-    annotation (
-      Icon(graphics={Text(extent={{-100,-40},{100,-74}}, textString="%name")}),
-      Diagram(graphics),
-      Documentation(info="<HTML>
+</html>"),
+      Icon(graphics));
+  end DrumEquilibrium;
+
+  model ValveLin "Valve for water/steam flows with linear pressure drop"
+    extends Icons.Water.Valve;
+    replaceable package Medium = StandardWater constrainedby Modelica.Media.Interfaces.PartialMedium "Medium model" annotation(
+       choicesAllMatching = true);
+    parameter Units.HydraulicConductance Kv "Nominal hydraulic conductance";
+    parameter Boolean allowFlowReversal = system.allowFlowReversal "= true to allow flow reversal, false restricts to design direction" annotation(
+      Evaluate = true);
+    outer ThermoPower.System system "System wide properties";
+    Medium.MassFlowRate w "Mass flowrate";
+    FlangeA inlet(redeclare package Medium = Medium, m_flow(min = if allowFlowReversal then -Modelica.Constants.inf else 0)) annotation(
+      Placement(transformation(extent = {{-120, -20}, {-80, 20}}, rotation = 0)));
+    FlangeB outlet(redeclare package Medium = Medium, m_flow(max = if allowFlowReversal then +Modelica.Constants.inf else 0)) annotation(
+      Placement(transformation(extent = {{80, -20}, {120, 20}}, rotation = 0)));
+    Modelica.Blocks.Interfaces.RealInput cmd annotation(
+      Placement(transformation(origin = {0, 80}, extent = {{-20, -20}, {20, 20}}, rotation = 270)));
+  equation
+    inlet.m_flow + outlet.m_flow = 0 "Mass balance";
+    w = Kv * cmd * (inlet.p - outlet.p) "Valve characteristics";
+// Boundary conditions
+    w = inlet.m_flow;
+    inlet.h_outflow = inStream(outlet.h_outflow);
+    inStream(inlet.h_outflow) = outlet.h_outflow;
+    annotation(
+      Icon(graphics = {Text(extent = {{-100, -40}, {100, -74}}, textString = "%name")}),
+      Diagram(graphics),
+      Documentation(info = "<HTML>
 <p>This very simple model provides a pressure drop which is proportional to the flowrate and to the <tt>cmd</tt> signal, without computing any fluid property.</p>
-</HTML>", revisions="<html>
+</HTML>", revisions = "<html>
 <ul>
 <li><i>16 Dec 2004</i>
     by <a href=\"mailto:francesco.casella@polimi.it\">Francesco Casella</a>:<br>
@@ -4167,33 +3227,29 @@
     by <a href=\"mailto:francesco.casella@polimi.it\">Francesco Casella</a>:<br>
        First release.</li>
 </ul>
-</html>"));
-  end ValveLin;
-
-  model ValveLiq "Valve for liquid water flow"
-    extends BaseClasses.ValveBase;
-    import ThermoPower.Choices.Valve.CvTypes;
-  initial equation
-    if CvData == CvTypes.OpPoint then
-      wnom = FlowChar(thetanom)*Av*sqrt(rhonom)*sqrtR(dpnom)
-        "Determination of Av by the operating point";
-    end if;
-
-  equation
-    if CheckValve then
-      w = homotopy(FlowChar(theta_act)*Av*sqrt(rho)*smooth(0, if dp >= 0 then sqrtR(
-        dp) else 0), theta_act/thetanom*wnom/dpnom*(inlet.p - outlet.p));
-    else
-      w = homotopy(FlowChar(theta_act)*Av*sqrt(rho)*sqrtR(dp), theta_act/thetanom*wnom/
-        dpnom*(inlet.p - outlet.p));
-    end if;
-    annotation (
-      Icon(graphics={Text(extent={{-100,-40},{100,-80}}, textString="%name")}),
-      Diagram(graphics),
-      Documentation(info="<HTML>
+</html>"));
+  end ValveLin;
+
+  model ValveLiq "Valve for liquid water flow"
+    extends BaseClasses.ValveBase;
+    import ThermoPower.Choices.Valve.CvTypes;
+  initial equation
+    if CvData == CvTypes.OpPoint then
+      wnom = FlowChar(thetanom) * Av * sqrt(rhonom) * sqrtR(dpnom) "Determination of Av by the operating point";
+    end if;
+  equation
+    if CheckValve then
+      w = homotopy(FlowChar(theta_act) * Av * sqrt(rho) * smooth(0, if dp >= 0 then sqrtR(dp) else 0), theta_act / thetanom * wnom / dpnom * (inlet.p - outlet.p));
+    else
+      w = homotopy(FlowChar(theta_act) * Av * sqrt(rho) * sqrtR(dp), theta_act / thetanom * wnom / dpnom * (inlet.p - outlet.p));
+    end if;
+    annotation(
+      Icon(graphics = {Text(extent = {{-100, -40}, {100, -80}}, textString = "%name")}),
+      Diagram(graphics),
+      Documentation(info = "<HTML>
 <p>Liquid water valve model according to the IEC 534/ISA S.75 standards for valve sizing, incompressible fluid. <p>
 Extends the <tt>ValveBase</tt> model (see the corresponding documentation for common valve features).
-</html>", revisions="<html>
+</html>", revisions = "<html>
 <ul>
 <li><i>15 Mar 2005</i>
     by <a href=\"mailto:francesco.casella@polimi.it\">Francesco Casella</a>:<br>
@@ -4209,64 +3265,59 @@
     by <a href=\"mailto:francesco.casella@polimi.it\">Francesco Casella</a>:<br>
        First release.</li>
 </ul>
-</HTML>"));
-  end ValveLiq;
-
-  model ValveVap "Valve for steam flow"
-    extends BaseClasses.ValveBase;
-    import ThermoPower.Choices.Valve.CvTypes;
-    parameter Real Fxt_full=0.5 "Fk*xt critical ratio at full opening";
-    replaceable function xtfun = Functions.ValveCharacteristics.one
-      constrainedby Functions.ValveCharacteristics.baseFun
-      "Critical ratio characteristic"
-      annotation(choicesAllMatching = true);
-    Real x "Pressure drop ratio";
-    Real xs "Saturated pressure drop ratio";
-    Real Y "Compressibility factor";
-    Real Fxt "Fxt coefficient";
-    Medium.AbsolutePressure p "Inlet pressure";
-  protected
-    parameter Real Fxt_nom(fixed=false) "Nominal Fxt";
-    parameter Real x_nom(fixed=false) "Nominal pressure drop ratio";
-    parameter Real xs_nom(fixed=false) "Nominal saturated pressure drop ratio";
-    parameter Real Y_nom(fixed=false) "Nominal compressibility factor";
-  initial equation
-    if CvData == CvTypes.OpPoint then
-      // Determination of Av by the nominal operating point conditions
-      Fxt_nom = Fxt_full*xtfun(thetanom);
-      x_nom = dpnom/pnom;
-      xs_nom = smooth(0, if x_nom > Fxt_nom then Fxt_nom else x_nom);
-      Y_nom = 1 - abs(xs_nom)/(3*Fxt_nom);
-      wnom = FlowChar(thetanom)*Av*Y_nom*sqrt(rhonom)*sqrtR(pnom*xs_nom);
-    else
-      // Dummy values
-      Fxt_nom = 0;
-      x_nom = 0;
-      xs_nom = 0;
-      Y_nom = 0;
-    end if;
-  equation
-    p = homotopy(if not allowFlowReversal then inlet.p else noEvent(if dp >= 0
-       then inlet.p else outlet.p), inlet.p);
-    Fxt = Fxt_full*xtfun(theta_act);
-    x = dp/p;
-    xs = smooth(0, if x < -Fxt then -Fxt else if x > Fxt then Fxt else x);
-    Y = 1 - abs(xs)/(3*Fxt);
-    if CheckValve then
-      w = homotopy(FlowChar(theta_act)*Av*Y*sqrt(rho)*smooth(0, if xs >= 0 then
-        sqrtR(p*xs) else 0), theta_act/thetanom*wnom/dpnom*(inlet.p - outlet.p));
-    else
-      w = homotopy(FlowChar(theta_act)*Av*Y*sqrt(rho)*sqrtR(p*xs), theta_act/thetanom*
-        wnom/dpnom*(inlet.p - outlet.p));
-    end if;
-    annotation (
-      Icon(graphics={Text(extent={{-100,-40},{100,-80}}, textString="%name")}),
-      Diagram(graphics),
-      Documentation(info="<HTML>
+</HTML>"));
+  end ValveLiq;
+
+  model ValveVap "Valve for steam flow"
+    extends BaseClasses.ValveBase;
+    import ThermoPower.Choices.Valve.CvTypes;
+    parameter Real Fxt_full = 0.5 "Fk*xt critical ratio at full opening";
+    replaceable function xtfun = Functions.ValveCharacteristics.one constrainedby Functions.ValveCharacteristics.baseFun "Critical ratio characteristic" annotation(
+       choicesAllMatching = true);
+    Real x "Pressure drop ratio";
+    Real xs "Saturated pressure drop ratio";
+    Real Y "Compressibility factor";
+    Real Fxt "Fxt coefficient";
+    Medium.AbsolutePressure p "Inlet pressure";
+  protected
+    parameter Real Fxt_nom(fixed = false) "Nominal Fxt";
+    parameter Real x_nom(fixed = false) "Nominal pressure drop ratio";
+    parameter Real xs_nom(fixed = false) "Nominal saturated pressure drop ratio";
+    parameter Real Y_nom(fixed = false) "Nominal compressibility factor";
+  initial equation
+    if CvData == CvTypes.OpPoint then
+// Determination of Av by the nominal operating point conditions
+      Fxt_nom = Fxt_full * xtfun(thetanom);
+      x_nom = dpnom / pnom;
+      xs_nom = smooth(0, if x_nom > Fxt_nom then Fxt_nom else x_nom);
+      Y_nom = 1 - abs(xs_nom) / (3 * Fxt_nom);
+      wnom = FlowChar(thetanom) * Av * Y_nom * sqrt(rhonom) * sqrtR(pnom * xs_nom);
+    else
+// Dummy values
+      Fxt_nom = 0;
+      x_nom = 0;
+      xs_nom = 0;
+      Y_nom = 0;
+    end if;
+  equation
+    p = homotopy(if not allowFlowReversal then inlet.p else noEvent(if dp >= 0 then inlet.p else outlet.p), inlet.p);
+    Fxt = Fxt_full * xtfun(theta_act);
+    x = dp / p;
+    xs = smooth(0, if x < (-Fxt) then -Fxt else if x > Fxt then Fxt else x);
+    Y = 1 - abs(xs) / (3 * Fxt);
+    if CheckValve then
+      w = homotopy(FlowChar(theta_act) * Av * Y * sqrt(rho) * smooth(0, if xs >= 0 then sqrtR(p * xs) else 0), theta_act / thetanom * wnom / dpnom * (inlet.p - outlet.p));
+    else
+      w = homotopy(FlowChar(theta_act) * Av * Y * sqrt(rho) * sqrtR(p * xs), theta_act / thetanom * wnom / dpnom * (inlet.p - outlet.p));
+    end if;
+    annotation(
+      Icon(graphics = {Text(extent = {{-100, -40}, {100, -80}}, textString = "%name")}),
+      Diagram(graphics),
+      Documentation(info = "<HTML>
 <p>Liquid water valve model according to the IEC 534/ISA S.75 standards for valve sizing, compressible fluid. <p>
 Extends the <tt>ValveBase</tt> model (see the corresponding documentation for common valve features).
 <p>The product Fk*xt is given by the parameter <tt>Fxt_full</tt>, and is assumed constant by default. The relative change (per unit) of the xt coefficient with the valve opening can be specified by customising the <tt>xtfun</tt> function.
-</HTML>", revisions="<html>
+</HTML>", revisions = "<html>
 <ul>
 <li><i>15 Mar 2005</i>
     by <a href=\"mailto:francesco.casella@polimi.it\">Francesco Casella</a>:<br>
@@ -4282,53 +3333,43 @@
     by <a href=\"mailto:francesco.casella@polimi.it\">Francesco Casella</a>:<br>
        First release.</li>
 </ul>
-</HTML>"));
-  end ValveVap;
-
-  model ValveLiqChoked
-    "Valve for liquid water flow, allows choked flow conditions"
-    extends BaseClasses.ValveBase(redeclare replaceable package Medium =
-          StandardWater constrainedby
-        Modelica.Media.Interfaces.PartialTwoPhaseMedium);
-    import ThermoPower.Choices.Valve.CvTypes;
-    parameter Real Flnom=0.9 "Liquid pressure recovery factor";
-    replaceable function Flfun = ThermoPower.Functions.ValveCharacteristics.one
-      constrainedby Functions.ValveCharacteristics.baseFun
-      "Pressure recovery characteristic";
-    Medium.MassFlowRate w "Mass flowrate";
-    SI.PerUnit Ff "Ff coefficient (see IEC/ISA standard)";
-    SI.PerUnit Fl "Pressure recovery coefficient Fl (see IEC/ISA standard)";
-    Medium.AbsolutePressure pv "Saturation pressure";
-    SI.Pressure dpEff "Effective pressure drop";
-  initial equation
-    if CvData == CvTypes.OpPoint then
-      wnom = FlowChar(thetanom)*Av*sqrt(rhonom)*sqrtR(dpnom)
-        "Determination of Av by the operating point";
-    end if;
-  equation
-    pv = Medium.saturationPressure(Tin);
-    Ff = 0.96 - 0.28*sqrt(pv/Medium.fluidConstants[1].criticalPressure);
-    Fl = Flnom*Flfun(theta_act);
-    dpEff = if outlet.p < (1 - Fl^2)*inlet.p + Ff*Fl^2*pv then Fl^2*(inlet.p -
-      Ff*pv) else inlet.p - outlet.p
-      "Effective pressure drop, accounting for possible choked conditions";
-    if CheckValve then
-      w = homotopy(FlowChar(theta_act)*Av*sqrt(rho)*(if dpEff >= 0 then sqrtR(dpEff)
-         else 0), theta_act/thetanom*wnom/dpnom*(inlet.p - outlet.p));
-    else
-      w = homotopy(FlowChar(theta_act)*Av*sqrt(rho)*sqrtR(dpEff), theta_act/thetanom*
-        wnom/dpnom*(inlet.p - outlet.p));
-    end if;
-    annotation (
-      Icon(graphics={Text(extent={{-100,-40},{100,-80}}, textString="%name")}),
-      Diagram(graphics),
-      Documentation(info="<HTML>
+</HTML>"));
+  end ValveVap;
+
+  model ValveLiqChoked "Valve for liquid water flow, allows choked flow conditions"
+    extends BaseClasses.ValveBase(redeclare replaceable package Medium = StandardWater constrainedby Modelica.Media.Interfaces.PartialTwoPhaseMedium);
+    import ThermoPower.Choices.Valve.CvTypes;
+    parameter Real Flnom = 0.9 "Liquid pressure recovery factor";
+    replaceable function Flfun = ThermoPower.Functions.ValveCharacteristics.one constrainedby Functions.ValveCharacteristics.baseFun "Pressure recovery characteristic";
+    Medium.MassFlowRate w "Mass flowrate";
+    SI.PerUnit Ff "Ff coefficient (see IEC/ISA standard)";
+    SI.PerUnit Fl "Pressure recovery coefficient Fl (see IEC/ISA standard)";
+    Medium.AbsolutePressure pv "Saturation pressure";
+    SI.Pressure dpEff "Effective pressure drop";
+  initial equation
+    if CvData == CvTypes.OpPoint then
+      wnom = FlowChar(thetanom) * Av * sqrt(rhonom) * sqrtR(dpnom) "Determination of Av by the operating point";
+    end if;
+  equation
+    pv = Medium.saturationPressure(Tin);
+    Ff = 0.96 - 0.28 * sqrt(pv / Medium.fluidConstants[1].criticalPressure);
+    Fl = Flnom * Flfun(theta_act);
+    dpEff = if outlet.p < (1 - Fl ^ 2) * inlet.p + Ff * Fl ^ 2 * pv then Fl ^ 2 * (inlet.p - Ff * pv) else inlet.p - outlet.p "Effective pressure drop, accounting for possible choked conditions";
+    if CheckValve then
+      w = homotopy(FlowChar(theta_act) * Av * sqrt(rho) * (if dpEff >= 0 then sqrtR(dpEff) else 0), theta_act / thetanom * wnom / dpnom * (inlet.p - outlet.p));
+    else
+      w = homotopy(FlowChar(theta_act) * Av * sqrt(rho) * sqrtR(dpEff), theta_act / thetanom * wnom / dpnom * (inlet.p - outlet.p));
+    end if;
+    annotation(
+      Icon(graphics = {Text(extent = {{-100, -40}, {100, -80}}, textString = "%name")}),
+      Diagram(graphics),
+      Documentation(info = "<HTML>
 <p>Liquid water valve model according to the IEC 534/ISA S.75 standards for valve sizing, incompressible fluid, with possible choked flow conditions. <p>
 Extends the <tt>ValveBase</tt> model (see the corresponding documentation for common valve features).<p>
 The model operating range includes choked flow operation, which takes place for low outlet pressures due to flashing in the vena contracta; otherwise, non-choking conditions are assumed.
 <p>The default liquid pressure recovery coefficient <tt>Fl</tt> is constant and given by the parameter <tt>Flnom</tt>. The relative change (per unit) of the recovery coefficient can be specified as a given function of the valve opening by customising the <tt>Flfun</tt> function.
 <p>If the flow coefficient is specified in terms of a nominal operating point, this should be in non-chocked conditions.
-</HTML>", revisions="<html>
+</HTML>", revisions = "<html>
 <ul>
 <li><i>15 Mar 2005</i>
     by <a href=\"mailto:francesco.casella@polimi.it\">Francesco Casella</a>:<br>
@@ -4344,40 +3385,34 @@
     by <a href=\"mailto:francesco.casella@polimi.it\">Francesco Casella</a>:<br>
        First release.</li>
 </ul>
-</HTML>"));
-  end ValveLiqChoked;
-
-  model Pump "Centrifugal pump with ideally controlled speed"
-    extends BaseClasses.PumpBase;
-    parameter NonSI.AngularVelocity_rpm n_const=n0 "Constant rotational speed"
-      annotation(Dialog(enable = not use_in_n));
-    Modelica.Blocks.Interfaces.RealInput in_n if use_in_n "RPM" annotation (Placement(
-          transformation(
-          origin={-26,80},
-          extent={{-10,-10},{10,10}},
-          rotation=270)));
-    parameter Boolean use_in_n = false
-      "Use connector input for the rotational speed"
-      annotation(Dialog(group="External inputs"), choices(checkBox=true));
-  protected
-    Modelica.Blocks.Interfaces.RealInput in_n_int
-      "Internal connector for rotational speed";
-  equation
-    connect(in_n, in_n_int);
-    if not use_in_n then
-      in_n_int = n_const "Rotational speed provided by parameter";
-    end if;
-    n = in_n_int "Rotational speed";
-    annotation (
-      Icon(graphics),
-      Diagram(coordinateSystem(preserveAspectRatio=false, extent={{-100,-100},{
-              100,100}}),
-              graphics),
-      Documentation(info="<HTML>
+</HTML>"));
+  end ValveLiqChoked;
+
+  model Pump "Centrifugal pump with ideally controlled speed"
+    extends BaseClasses.PumpBase;
+    parameter NonSI.AngularVelocity_rpm n_const = n0 "Constant rotational speed" annotation(
+      Dialog(enable = not use_in_n));
+    Modelica.Blocks.Interfaces.RealInput in_n if use_in_n "RPM" annotation(
+      Placement(transformation(origin = {-26, 80}, extent = {{-10, -10}, {10, 10}}, rotation = 270)));
+    parameter Boolean use_in_n = false "Use connector input for the rotational speed" annotation(
+      Dialog(group = "External inputs"),
+      choices(checkBox = true));
+  protected
+    Modelica.Blocks.Interfaces.RealInput in_n_int "Internal connector for rotational speed";
+  equation
+    connect(in_n, in_n_int);
+    if not use_in_n then
+      in_n_int = n_const "Rotational speed provided by parameter";
+    end if;
+    n = in_n_int "Rotational speed";
+    annotation(
+      Icon(graphics),
+      Diagram(coordinateSystem(preserveAspectRatio = false, extent = {{-100, -100}, {100, 100}}), graphics),
+      Documentation(info = "<HTML>
 <p>This model describes a centrifugal pump (or a group of <tt>Np</tt> pumps in parallel) with controlled speed, either fixed or provided by an external signal.
 <p>The model extends <tt>PumpBase</tt>
 <p>If the <tt>in_n</tt> input connector is wired, it provides rotational speed of the pumps (rpm); otherwise, a constant rotational speed equal to <tt>n_const</tt> (which can be different from <tt>n0</tt>) is assumed.</p>
-</HTML>", revisions="<html>
+</HTML>", revisions = "<html>
 <ul>
 <li><i>5 Jul 2004</i>
     by <a href=\"mailto:francesco.casella@polimi.it\">Francesco Casella</a>:<br>
@@ -4389,48 +3424,47 @@
     by <a href=\"mailto:francesco.schiavo@polimi.it\">Francesco Schiavo</a>:<br>
        First release.</li>
 </ul>
-</html>"));
-  end Pump;
-
-  model PumpNPSH
-    extends Pump(redeclare replaceable package Medium = StandardWater
-        constrainedby Modelica.Media.Interfaces.PartialTwoPhaseMedium);
-    SI.Height NPSHa "Net Positive Suction Head available";
-    Medium.AbsolutePressure pv "Saturated liquid pressure";
-  equation
-    pv = Medium.saturationPressure(Tin);
-    NPSHa = (infl.p - pv)/(rho*g);
-    annotation (Documentation(info="<html>Same as Pump. Additionally, the net positive suction head available is computed. Requires a two-phase medium model to compute the saturation properties.
-</html>", revisions="<html>
+</html>"));
+  end Pump;
+
+  model PumpNPSH
+    extends Pump(redeclare replaceable package Medium = StandardWater constrainedby Modelica.Media.Interfaces.PartialTwoPhaseMedium);
+    SI.Height NPSHa "Net Positive Suction Head available";
+    Medium.AbsolutePressure pv "Saturated liquid pressure";
+  equation
+    pv = Medium.saturationPressure(Tin);
+    NPSHa = (infl.p - pv) / (rho * g);
+    annotation(
+      Documentation(info = "<html>Same as Pump. Additionally, the net positive suction head available is computed. Requires a two-phase medium model to compute the saturation properties.
+</html>", revisions = "<html>
 <ul>
 <li><i>30 Jul 2007</i>
     by <a href=\"mailto:francesco.casella@polimi.it\">Francesco Casella</a>:<br>
        Added (removed NPSH from Pump model).</li>
 </ul>
-</html>"));
-  end PumpNPSH;
-
-  model PumpMech "Centrifugal pump with mechanical connector for the shaft"
-    extends BaseClasses.PumpBase;
-    extends Icons.Water.PumpMech;
-    SI.Angle phi "Shaft angle";
-    SI.AngularVelocity omega "Shaft angular velocity";
-    Modelica.Mechanics.Rotational.Interfaces.Flange_a MechPort annotation (
-        Placement(transformation(extent={{76,6},{106,36}}, rotation=0)));
-  equation
-    // Mechanical boundary condition
-    phi = MechPort.phi;
-    omega = der(phi);
-    W = omega*MechPort.tau;
-
-    n = Modelica.SIunits.Conversions.to_rpm(omega) "Rotational speed";
-    annotation (
-      Icon(graphics={Text(extent={{-10,104},{18,84}}, textString="Np")}),
-      Diagram(graphics),
-      Documentation(info="<HTML>
+</html>"));
+  end PumpNPSH;
+
+  model PumpMech "Centrifugal pump with mechanical connector for the shaft"
+    extends BaseClasses.PumpBase;
+    extends Icons.Water.PumpMech;
+    SI.Angle phi "Shaft angle";
+    SI.AngularVelocity omega "Shaft angular velocity";
+    Modelica.Mechanics.Rotational.Interfaces.Flange_a MechPort annotation(
+      Placement(transformation(extent = {{76, 6}, {106, 36}}, rotation = 0)));
+  equation
+// Mechanical boundary condition
+    phi = MechPort.phi;
+    omega = der(phi);
+    W = omega * MechPort.tau;
+    n = Modelica.Units.Conversions.to_rpm(omega) "Rotational speed";
+    annotation(
+      Icon(graphics = {Text(extent = {{-10, 104}, {18, 84}}, textString = "Np")}),
+      Diagram(graphics),
+      Documentation(info = "<HTML>
 <p>This model describes a centrifugal pump (or a group of <tt>Np</tt> pumps in parallel) with a mechanical rotational connector for the shaft, to be used when the pump drive has to be modelled explicitly. In the case of <tt>Np</tt> pumps in parallel, the mechanical connector is relative to a single pump.
 <p>The model extends <tt>PumpBase</tt>
- </HTML>", revisions="<html>
+ </HTML>", revisions = "<html>
 <ul>
 <li><i>5 Jul 2004</i>
     by <a href=\"mailto:francesco.casella@polimi.it\">Francesco Casella</a>:<br>
@@ -4442,577 +3476,358 @@
     by <a href=\"mailto:francesco.schiavo@polimi.it\">Francesco Schiavo</a>:<br>
        First release.</li>
 </ul>
-</html>"));
-  end PumpMech;
-
-  model SprayCondenser
-    "Model of a spray condenser  assuming  themodynamic equilibrium between the phases"
-    replaceable package Medium = StandardWater constrainedby
-      Modelica.Media.Interfaces.PartialTwoPhaseMedium "Medium model"
-      annotation(choicesAllMatching = true);
-    parameter SI.Volume Vt "Condenser total volume";
-    parameter SI.Volume V0 "Volume of liquid at zero level";
-    parameter SI.Height y0 "Height of liquid outlet over the zero level";
-    parameter SI.Area A "Cross section";
-                                          outer ThermoPower.System system "System wide properties";
-    parameter SI.Pressure pstart "Pressure start value"
-      annotation (Dialog(tab="Initialisation"));
-    parameter SI.Height ystart "Start value of the level"
-      annotation (Dialog(tab="Initialisation"));
-    parameter Choices.Init.Options initOpt=system.initOpt
-      "Initialisation option"
-      annotation (Dialog(tab="Initialisation"));
-    parameter Boolean noInitialPressure=false
-      "Remove initial equation on pressure"
-      annotation (Dialog(tab="Initialisation"),choices(checkBox=true));
-    parameter Boolean noInitialLevel=false
-      "Remove initial equation on level"
-      annotation (Dialog(tab="Initialisation"),choices(checkBox=true));
-    constant SI.Acceleration g = Modelica.Constants.g_n "Acceleration of gravity";
-
-    Medium.SaturationProperties sat "Saturation conditions";
-    FlangeA coolingWater(redeclare package Medium = Medium, m_flow(min=0)) annotation (
-        Placement(transformation(extent={{-100,20},{-60,60}}, rotation=0),
-          iconTransformation(extent={{-100,20},{-60,60}})));
-    FlangeA condensingSteam(redeclare package Medium = Medium, m_flow(min=0)) annotation (
-        Placement(transformation(extent={{-20,80},{20,120}}, rotation=0),
-          iconTransformation(extent={{-20,80},{20,120}})));
-    FlangeB liquidOutlet(redeclare package Medium = Medium) annotation (
-        Placement(transformation(extent={{-20,-120},{20,-80}}, rotation=0),
-          iconTransformation(extent={{-20,-120},{20,-80}})));
-    SI.Mass Ml "Liquid water mass";
-    SI.Mass Mv "Steam mass";
-    SI.Mass M "Total liquid+steam mass";
-    SI.Energy E "Total energy";
-    SI.Volume Vl "Liquid water total volume";
-    SI.Volume Vv "Steam volume";
-    SI.Height y(start = ystart, stateSelect=StateSelect.prefer) "Level relative to zero reference";
-    Medium.AbsolutePressure p(start=pstart,stateSelect=StateSelect.prefer)
-      "Steam pressure";
-    Medium.AbsolutePressure pl "Pressure at the liquid outlet";
-    Medium.MassFlowRate qs "Condensing steam inlet mass flow rate";
-    Medium.MassFlowRate qc "Cooling water  inlet mass flow rate";
-    Medium.MassFlowRate ql "Saturated liquid outlet flow rate";
-    Medium.SpecificEnthalpy hs "Condensing steam specific enthalpy";
-    Medium.SpecificEnthalpy hc "Cooling water specific enthalpy";
-    Medium.SpecificEnthalpy hl "Specific enthalpy of saturated liquid";
-    Medium.SpecificEnthalpy hv "Specific enthalpy of saturated steam";
-    Medium.Temperature Ts "Saturation temperature";
-    Units.LiquidDensity rhol "Density of saturated liquid";
-    Units.GasDensity rhov "Density of saturated steam";
-  equation
-    Ml = Vl*rhol "Mass of liquid";
-    Mv = Vv*rhov "Mass of vapour";
-    M = Ml + Mv "Total mass";
-    E = Ml*hl + Mv*hv - p*Vt "Total energy";
-    Vl = V0 + A*y "Volume - level relationship";
-    Ts = Medium.saturationTemperature_sat(sat) "Saturation temperature";
-    der(M) = qs + qc - ql "Mass balance";
-    der(E) = qs*hs + qc*hc - ql*hl "Energy balance";
-    Vt = Vl + Vv "Total volume";
-    pl = p + rhol*g*(y + y0) "Static head between steam and liquid outlet";
-
-    // Boundary conditions
-    p =coolingWater.p;
-    p =condensingSteam.p;
-    pl = liquidOutlet.p;
-    condensingSteam.m_flow = qs;
-    coolingWater.m_flow = qc;
-    -liquidOutlet.m_flow = ql;
-    hs = inStream(condensingSteam.h_outflow);
-    hc = inStream(coolingWater.h_outflow);
-    condensingSteam.h_outflow = hv "Not used, no flow reversal";
-    coolingWater.h_outflow = hl "Not used, no flow reversal";
-    liquidOutlet.h_outflow = hl;
-
-    // Fluid properties
-    sat.psat = p;
-    sat.Tsat = Medium.saturationTemperature(p);
-    rhol = Medium.bubbleDensity(sat);
-    rhov = Medium.dewDensity(sat);
-    hl = Medium.bubbleEnthalpy(sat);
-    hv = Medium.dewEnthalpy(sat);
-  initial equation
-    if initOpt == Choices.Init.Options.noInit then
-      // do nothing
-    elseif initOpt == Choices.Init.Options.fixedState then
-      if not noInitialPressure then
-        p = pstart;
-      end if;
-      if not noInitialLevel then
-        y = ystart;
-      end if;
-    elseif initOpt == Choices.Init.Options.steadyState then
-      if not noInitialPressure then
-        der(p) = 0;
-      end if;
-      if not noInitialLevel then
-        der(y) = 0;
-      end if;
-    else
-      assert(false, "Unsupported initialisation option");
-    end if;
-    annotation (
-      Documentation(info="<html>
+</html>"));
+  end PumpMech;
+
+  model SprayCondenser "Model of a spray condenser  assuming  themodynamic equilibrium between the phases"
+    replaceable package Medium = StandardWater constrainedby Modelica.Media.Interfaces.PartialTwoPhaseMedium "Medium model" annotation(
+       choicesAllMatching = true);
+    parameter SI.Volume Vt "Condenser total volume";
+    parameter SI.Volume V0 "Volume of liquid at zero level";
+    parameter SI.Height y0 "Height of liquid outlet over the zero level";
+    parameter SI.Area A "Cross section";
+    outer ThermoPower.System system "System wide properties";
+    parameter SI.Pressure pstart "Pressure start value" annotation(
+      Dialog(tab = "Initialisation"));
+    parameter SI.Height ystart "Start value of the level" annotation(
+      Dialog(tab = "Initialisation"));
+    parameter Choices.Init.Options initOpt = system.initOpt "Initialisation option" annotation(
+      Dialog(tab = "Initialisation"));
+    parameter Boolean noInitialPressure = false "Remove initial equation on pressure" annotation(
+      Dialog(tab = "Initialisation"),
+      choices(checkBox = true));
+    parameter Boolean noInitialLevel = false "Remove initial equation on level" annotation(
+      Dialog(tab = "Initialisation"),
+      choices(checkBox = true));
+    constant SI.Acceleration g = Modelica.Constants.g_n "Acceleration of gravity";
+    Medium.SaturationProperties sat "Saturation conditions";
+    FlangeA coolingWater(redeclare package Medium = Medium, m_flow(min = 0)) annotation(
+      Placement(transformation(extent = {{-100, 20}, {-60, 60}}, rotation = 0), iconTransformation(extent = {{-100, 20}, {-60, 60}})));
+    FlangeA condensingSteam(redeclare package Medium = Medium, m_flow(min = 0)) annotation(
+      Placement(transformation(extent = {{-20, 80}, {20, 120}}, rotation = 0), iconTransformation(extent = {{-20, 80}, {20, 120}})));
+    FlangeB liquidOutlet(redeclare package Medium = Medium) annotation(
+      Placement(transformation(extent = {{-20, -120}, {20, -80}}, rotation = 0), iconTransformation(extent = {{-20, -120}, {20, -80}})));
+    SI.Mass Ml "Liquid water mass";
+    SI.Mass Mv "Steam mass";
+    SI.Mass M "Total liquid+steam mass";
+    SI.Energy E "Total energy";
+    SI.Volume Vl "Liquid water total volume";
+    SI.Volume Vv "Steam volume";
+    SI.Height y(start = ystart, stateSelect = StateSelect.prefer) "Level relative to zero reference";
+    Medium.AbsolutePressure p(start = pstart, stateSelect = StateSelect.prefer) "Steam pressure";
+    Medium.AbsolutePressure pl "Pressure at the liquid outlet";
+    Medium.MassFlowRate qs "Condensing steam inlet mass flow rate";
+    Medium.MassFlowRate qc "Cooling water  inlet mass flow rate";
+    Medium.MassFlowRate ql "Saturated liquid outlet flow rate";
+    Medium.SpecificEnthalpy hs "Condensing steam specific enthalpy";
+    Medium.SpecificEnthalpy hc "Cooling water specific enthalpy";
+    Medium.SpecificEnthalpy hl "Specific enthalpy of saturated liquid";
+    Medium.SpecificEnthalpy hv "Specific enthalpy of saturated steam";
+    Medium.Temperature Ts "Saturation temperature";
+    Units.LiquidDensity rhol "Density of saturated liquid";
+    Units.GasDensity rhov "Density of saturated steam";
+  equation
+    Ml = Vl * rhol "Mass of liquid";
+    Mv = Vv * rhov "Mass of vapour";
+    M = Ml + Mv "Total mass";
+    E = Ml * hl + Mv * hv - p * Vt "Total energy";
+    Vl = V0 + A * y "Volume - level relationship";
+    Ts = Medium.saturationTemperature_sat(sat) "Saturation temperature";
+    der(M) = qs + qc - ql "Mass balance";
+    der(E) = qs * hs + qc * hc - ql * hl "Energy balance";
+    Vt = Vl + Vv "Total volume";
+    pl = p + rhol * g * (y + y0) "Static head between steam and liquid outlet";
+// Boundary conditions
+    p = coolingWater.p;
+    p = condensingSteam.p;
+    pl = liquidOutlet.p;
+    condensingSteam.m_flow = qs;
+    coolingWater.m_flow = qc;
+    -liquidOutlet.m_flow = ql;
+    hs = inStream(condensingSteam.h_outflow);
+    hc = inStream(coolingWater.h_outflow);
+    condensingSteam.h_outflow = hv "Not used, no flow reversal";
+    coolingWater.h_outflow = hl "Not used, no flow reversal";
+    liquidOutlet.h_outflow = hl;
+// Fluid properties
+    sat.psat = p;
+    sat.Tsat = Medium.saturationTemperature(p);
+    rhol = Medium.bubbleDensity(sat);
+    rhov = Medium.dewDensity(sat);
+    hl = Medium.bubbleEnthalpy(sat);
+    hv = Medium.dewEnthalpy(sat);
+  initial equation
+    if initOpt == Choices.Init.Options.noInit then
+// do nothing
+    elseif initOpt == Choices.Init.Options.fixedState then
+      if not noInitialPressure then
+        p = pstart;
+      end if;
+      if not noInitialLevel then
+        y = ystart;
+      end if;
+    elseif initOpt == Choices.Init.Options.steadyState then
+      if not noInitialPressure then
+        der(p) = 0;
+      end if;
+      if not noInitialLevel then
+        der(y) = 0;
+      end if;
+    else
+      assert(false, "Unsupported initialisation option");
+    end if;
+    annotation(
+      Documentation(info = "<html>
 <p>Model of a spray condenser. Thermodynamic equilibrium and perfect phase separation is assumed between the vapour and liquid phase, the condensate outlet pressure takes into account the static head due to the liquid level. The model assumes a cylindrical geometry with vertical axis in its validity range; by choosing Vt, V0, and y0 appropriately, any shape can be represented for the top and bottom of the vessel.  </p>
-</html>", revisions="<html>
+</html>", revisions = "<html>
 <ul>
 <li><i>26 Jul 2017</i> <a href=\"mailto:francesco.casella@polimi.it\">Francesco Casella</a>:<br>First release.</li>
 </ul>
-</html>"),   Icon(graphics={
-          Rectangle(
-            extent={{-60,60},{60,-60}},
-            lineColor={0,0,255},
-            pattern=LinePattern.None,
-            fillColor={128,128,128},
-            fillPattern=FillPattern.Solid),
-          Ellipse(
-            extent={{-60,80},{60,40}},
-            lineColor={0,0,255},
-            pattern=LinePattern.None,
-            fillColor={128,128,128},
-            fillPattern=FillPattern.Solid),
-          Ellipse(
-            extent={{-60,-40},{60,-80}},
-            lineColor={0,0,255},
-            pattern=LinePattern.None,
-            fillColor={128,128,128},
-            fillPattern=FillPattern.Solid),
-          Ellipse(
-            extent={{-52,74},{52,44}},
-            lineColor={0,0,191},
-            pattern=LinePattern.None,
-            fillColor={159,159,223},
-            fillPattern=FillPattern.Solid),
-          Rectangle(
-            extent={{-52,2},{52,-60}},
-            lineColor={0,0,191},
-            fillColor={0,0,191},
-            fillPattern=FillPattern.Solid),
-          Rectangle(
-            extent={{-52,60},{52,0}},
-            lineColor={0,0,255},
-            pattern=LinePattern.None,
-            fillColor={159,159,223},
-            fillPattern=FillPattern.Solid),
-          Ellipse(
-            extent={{-52,-44},{52,-74}},
-            lineColor={0,0,191},
-            pattern=LinePattern.None,
-            fillColor={0,0,191},
-            fillPattern=FillPattern.Solid),
-          Polygon(
-            points={{-60,38},{2,38},{2,44},{-60,44},{-60,38}},
-            lineColor={0,0,255},
-            pattern=LinePattern.None,
-            fillColor={128,128,128},
-            fillPattern=FillPattern.Solid),
-          Polygon(
-            points={{2,38},{-10,26},{12,26},{2,38}},
-            lineColor={0,0,255},
-            fillColor={0,0,235},
-            fillPattern=FillPattern.Solid)}));
-  end SprayCondenser;
-
-  model BarometricCondenser
-    "Model of a barometric condenser including the barometric leg"
-    replaceable package Medium = StandardWater constrainedby
-      Modelica.Media.Interfaces.PartialTwoPhaseMedium "Medium model"
-      annotation(choicesAllMatching = true);
-    parameter SI.Time Tr = 1 "Residence time of the droplets in the condenser";
-    parameter SI.MassFlowRate wnom "Nominal cooling water flow rate";
-    parameter SI.TemperatureDifference Tt = 5 "Terminal temperature difference";
-    parameter Boolean neglectLegDynamics = true "Neglect the dynamics of the barometric leg";
-
-    parameter ThermoPower.Choices.Init.Options initOpt = system.initOpt "Initialization option"
-       annotation (Dialog(tab="Initialisation"));
-    parameter Medium.Temperature Tlstart = 293.15 "Liquid outlet temperature start value"
-     annotation (Dialog(tab="Initialisation"));
-
-    final parameter Medium.AbsolutePressure pstart = Medium.saturationPressure(Tlstart + Tt);
-    final parameter Medium.SpecificEnthalpy hlstart = Medium.specificEnthalpy_pTX(pstart, Tlstart, fill(0,0));
-
-    outer ThermoPower.System system "System wide properties";
-
-    Medium.Temperature Tl "Liquid outlet temperature";
-    Medium.SpecificEnthalpy hc "Cooling water specific enthalpy";
-    Medium.SpecificEnthalpy hv "Condensing steam specific enthalpy";
-    Medium.SpecificEnthalpy hl(start = hlstart, stateSelect = StateSelect.prefer)
-      "Liquid outlet specific enthalpy";
-
-    SI.MassFlowRate wc "Cooling water mass flow rate";
-    SI.MassFlowRate wv "Condensing steam inlet mass flow rate";
-    SI.MassFlowRate wl "Liquid outlet mass flow rate";
-
-    FlangeA coolingWater(redeclare package Medium = Medium, m_flow(min=0)) "Cooling water inlet"
-       annotation (Placement(transformation(extent={{-100,20},{-60,60}}, rotation=0),
-          iconTransformation(extent={{-140,80},{-100,120}})));
-    FlangeA condensingSteam(redeclare package Medium = Medium, m_flow(min=0)) "Condensing steam inlet"
-       annotation (
-        Placement(transformation(extent={{-20,80},{20,120}}, rotation=0),
-          iconTransformation(extent={{-20,138},{20,178}})));
-    FlangeB liquidOutlet(redeclare package Medium = Medium) "Liquid outlet" annotation (
-        Placement(transformation(extent={{-20,-120},{20,-80}}, rotation=0),
-          iconTransformation(extent={{-20,-172},{20,-132}})));
-
-    Medium.AbsolutePressure p(start=pstart) "Steam pressure in the condenser";
-
-  equation
-    wc + wv = wl;
-    Tr*wnom*der(hl) = wc*hc + wv*hv - wl*hl;
-    Tl = Medium.temperature_ph(p, hl);
-    p = Medium.saturationPressure(Tl + Tt);
-
-    assert(neglectLegDynamics, "Full leg dynamics not implemented yet");
-
-    // Boundary conditions
-    p = coolingWater.p;
-    p = condensingSteam.p;
-    wc = coolingWater.m_flow;
-    wv = condensingSteam.m_flow;
-    wl = -liquidOutlet.m_flow;
-    hv = inStream(condensingSteam.h_outflow);
-    hc = inStream(coolingWater.h_outflow);
-    condensingSteam.h_outflow = hv "Not used, no flow reversal";
-    coolingWater.h_outflow = hl "Not used, no flow reversal";
-    liquidOutlet.h_outflow = hl;
-
-  initial equation
-    if initOpt == ThermoPower.Choices.Init.Options.steadyState then
-      der(hl) = 0;
-    elseif initOpt == ThermoPower.Choices.Init.Options.fixedState then
-      hl = hlstart;
-    end if;
-
-    annotation (
-      Documentation(info="<html>
+</html>"),
+      Icon(graphics = {Rectangle(extent = {{-60, 60}, {60, -60}}, lineColor = {0, 0, 255}, pattern = LinePattern.None, fillColor = {128, 128, 128}, fillPattern = FillPattern.Solid), Ellipse(extent = {{-60, 80}, {60, 40}}, lineColor = {0, 0, 255}, pattern = LinePattern.None, fillColor = {128, 128, 128}, fillPattern = FillPattern.Solid), Ellipse(extent = {{-60, -40}, {60, -80}}, lineColor = {0, 0, 255}, pattern = LinePattern.None, fillColor = {128, 128, 128}, fillPattern = FillPattern.Solid), Ellipse(extent = {{-52, 74}, {52, 44}}, lineColor = {0, 0, 191}, pattern = LinePattern.None, fillColor = {159, 159, 223}, fillPattern = FillPattern.Solid), Rectangle(extent = {{-52, 2}, {52, -60}}, lineColor = {0, 0, 191}, fillColor = {0, 0, 191}, fillPattern = FillPattern.Solid), Rectangle(extent = {{-52, 60}, {52, 0}}, lineColor = {0, 0, 255}, pattern = LinePattern.None, fillColor = {159, 159, 223}, fillPattern = FillPattern.Solid), Ellipse(extent = {{-52, -44}, {52, -74}}, lineColor = {0, 0, 191}, pattern = LinePattern.None, fillColor = {0, 0, 191}, fillPattern = FillPattern.Solid), Polygon(points = {{-60, 38}, {2, 38}, {2, 44}, {-60, 44}, {-60, 38}}, lineColor = {0, 0, 255}, pattern = LinePattern.None, fillColor = {128, 128, 128}, fillPattern = FillPattern.Solid), Polygon(points = {{2, 38}, {-10, 26}, {12, 26}, {2, 38}}, lineColor = {0, 0, 255}, fillColor = {0, 0, 235}, fillPattern = FillPattern.Solid)}));
+  end SprayCondenser;
+
+  model BarometricCondenser "Model of a barometric condenser including the barometric leg"
+    replaceable package Medium = StandardWater constrainedby Modelica.Media.Interfaces.PartialTwoPhaseMedium "Medium model" annotation(
+       choicesAllMatching = true);
+    parameter SI.Time Tr = 1 "Residence time of the droplets in the condenser";
+    parameter SI.MassFlowRate wnom "Nominal cooling water flow rate";
+    parameter SI.TemperatureDifference Tt = 5 "Terminal temperature difference";
+    parameter Boolean neglectLegDynamics = true "Neglect the dynamics of the barometric leg";
+    parameter ThermoPower.Choices.Init.Options initOpt = system.initOpt "Initialization option" annotation(
+      Dialog(tab = "Initialisation"));
+    parameter Medium.Temperature Tlstart = 293.15 "Liquid outlet temperature start value" annotation(
+      Dialog(tab = "Initialisation"));
+    final parameter Medium.AbsolutePressure pstart = Medium.saturationPressure(Tlstart + Tt);
+    final parameter Medium.SpecificEnthalpy hlstart = Medium.specificEnthalpy_pTX(pstart, Tlstart, fill(0, 0));
+    outer ThermoPower.System system "System wide properties";
+    Medium.Temperature Tl "Liquid outlet temperature";
+    Medium.SpecificEnthalpy hc "Cooling water specific enthalpy";
+    Medium.SpecificEnthalpy hv "Condensing steam specific enthalpy";
+    Medium.SpecificEnthalpy hl(start = hlstart, stateSelect = StateSelect.prefer) "Liquid outlet specific enthalpy";
+    SI.MassFlowRate wc "Cooling water mass flow rate";
+    SI.MassFlowRate wv "Condensing steam inlet mass flow rate";
+    SI.MassFlowRate wl "Liquid outlet mass flow rate";
+    FlangeA coolingWater(redeclare package Medium = Medium, m_flow(min = 0)) "Cooling water inlet" annotation(
+      Placement(transformation(extent = {{-100, 20}, {-60, 60}}, rotation = 0), iconTransformation(extent = {{-140, 80}, {-100, 120}})));
+    FlangeA condensingSteam(redeclare package Medium = Medium, m_flow(min = 0)) "Condensing steam inlet" annotation(
+      Placement(transformation(extent = {{-20, 80}, {20, 120}}, rotation = 0), iconTransformation(extent = {{-20, 138}, {20, 178}})));
+    FlangeB liquidOutlet(redeclare package Medium = Medium) "Liquid outlet" annotation(
+      Placement(transformation(extent = {{-20, -120}, {20, -80}}, rotation = 0), iconTransformation(extent = {{-20, -172}, {20, -132}})));
+    Medium.AbsolutePressure p(start = pstart) "Steam pressure in the condenser";
+  equation
+    wc + wv = wl;
+    Tr * wnom * der(hl) = wc * hc + wv * hv - wl * hl;
+    Tl = Medium.temperature_ph(p, hl);
+    p = Medium.saturationPressure(Tl + Tt);
+    assert(neglectLegDynamics, "Full leg dynamics not implemented yet");
+// Boundary conditions
+    p = coolingWater.p;
+    p = condensingSteam.p;
+    wc = coolingWater.m_flow;
+    wv = condensingSteam.m_flow;
+    wl = -liquidOutlet.m_flow;
+    hv = inStream(condensingSteam.h_outflow);
+    hc = inStream(coolingWater.h_outflow);
+    condensingSteam.h_outflow = hv "Not used, no flow reversal";
+    coolingWater.h_outflow = hl "Not used, no flow reversal";
+    liquidOutlet.h_outflow = hl;
+  initial equation
+    if initOpt == ThermoPower.Choices.Init.Options.steadyState then
+      der(hl) = 0;
+    elseif initOpt == ThermoPower.Choices.Init.Options.fixedState then
+      hl = hlstart;
+    end if;
+    annotation(
+      Documentation(info = "<html>
 <p>Model of a barometric condenser including the barometric leg.</p>
 <p>The incoming cooling water is sprayed in the condenser and mixes with the incoming steam flow. It is assumed that the residence time of the droplets in the condenser is equal to <code>Tr</code>. The pressure <code>p</code> in the condenser corresponds to the droplet temperature <code>Tl</code> plus the terminal temperature difference <code>Tt</code>, which is assumed to be constant for simplicity. </p>
 <p>In most cases, barometric condensers discharge into tanks that have a much larger diameter and a much larger mass storage than the barometric leg. Therefore, the effects of the leg dynamics, i.e. the changes of the level in the pipe and the delay between the temperature at the condenser outlet and the temperature at the pipe outlet, are negligible. By setting <code>neglectLegDynamics = true</code>, the mass flow rate and specific enthalpy at the barometric leg outlet are assumed to be the same as the ones at the condenser outlet. </p>
 <p>If <code>neglectLegDynamics</code> = false, the effects of mass, momentum and energy storage in the barometric leg are also accounted for. This is currently not yet implemented.</p>
-</html>", revisions="<html>
+</html>", revisions = "<html>
 <ul>
 <li><i>26 Jul 2017</i> <a href=\"mailto:francesco.casella@polimi.it\">Francesco Casella</a>:<br>First release.</li>
 </ul>
-</html>"),   Icon(coordinateSystem(extent={{-120,-160},{120,160}}),
-                  graphics={
-          Rectangle(
-            extent={{-60,128},{60,58}},
-            lineColor={0,0,255},
-            pattern=LinePattern.None,
-            fillColor={128,128,128},
-            fillPattern=FillPattern.Solid),
-          Ellipse(
-            extent={{-60,140},{60,112}},
-            lineColor={0,0,255},
-            pattern=LinePattern.None,
-            fillColor={128,128,128},
-            fillPattern=FillPattern.Solid),
-          Ellipse(
-            extent={{-52,132},{54,116}},
-            lineColor={0,0,191},
-            pattern=LinePattern.None,
-            fillColor={159,159,223},
-            fillPattern=FillPattern.Solid),
-          Rectangle(
-            extent={{-54,124},{54,58}},
-            lineColor={0,0,255},
-            pattern=LinePattern.None,
-            fillColor={159,159,223},
-            fillPattern=FillPattern.Solid),
-          Polygon(
-            points={{-100,96},{2,96},{2,102},{-100,102},{-100,96}},
-            lineColor={0,0,255},
-            pattern=LinePattern.None,
-            fillColor={128,128,128},
-            fillPattern=FillPattern.Solid),
-          Polygon(
-            points={{0,96},{-12,84},{10,84},{0,96}},
-            lineColor={0,0,255},
-            fillColor={0,0,235},
-            fillPattern=FillPattern.Solid),
-          Polygon(
-            points={{-54,60},{56,60},{12,2},{-10,2},{-54,60}},
-            lineColor={159,159,223},
-            fillColor={159,159,223},
-            fillPattern=FillPattern.Solid),
-          Polygon(
-            points={{-60,60},{-12,0},{-4,-2},{-54,60},{-60,60}},
-            lineColor={128,128,128},
-            fillColor={128,128,128},
-            fillPattern=FillPattern.Solid),
-          Polygon(
-            points={{54,60},{60,60},{12,2},{6,2},{54,60}},
-            lineColor={128,128,128},
-            fillColor={128,128,128},
-            fillPattern=FillPattern.Solid),
-          Rectangle(
-            extent={{-12,2},{12,-140}},
-            lineColor={0,0,255},
-            pattern=LinePattern.None,
-            fillColor={128,128,128},
-            fillPattern=FillPattern.Solid),
-          Rectangle(
-            extent={{8,20},{-8,20}},
-            fillColor={159,159,223},
-            fillPattern=FillPattern.Solid,
-            pattern=LinePattern.None),
-          Rectangle(
-            extent={{6,2},{-6,-136}},
-            fillColor={0,0,255},
-            fillPattern=FillPattern.Solid,
-            pattern=LinePattern.None,
-            lineColor={0,0,0})}),
-      Diagram(coordinateSystem(extent={{-120,-160},{120,160}})));
-  end BarometricCondenser;
-
-  model CoolingTower "Cooling tower with variable speed fan"
-    import Modelica.SIunits.Conversions;
-    package Water = Modelica.Media.Water.StandardWater;
-    package DryAir = Modelica.Media.Air.SimpleAir;
-
-    outer ThermoPower.System system "System object";
-
-    ThermoPower.Water.FlangeA waterInlet annotation (Placement(transformation(
-            extent={{-10,80},{10,100}}), iconTransformation(extent={{-10,80},{10,100}})));
-    ThermoPower.Water.FlangeB waterOutlet annotation (Placement(transformation(
-            extent={{-10,-100},{10,-80}}), iconTransformation(extent={{-10,-100},{
-              10,-80}})));
-    Modelica.Blocks.Interfaces.RealInput fanRpm "Fan rotational speed in rpm"
-      annotation (Placement(transformation(extent={{-100,60},{-60,100}}),
-          iconTransformation(extent={{-90,30},{-70,50}})));
-
-      Modelica.Blocks.Interfaces.RealOutput powerConsumption
-      "Total fan power consumption"
-      annotation (Placement(transformation(extent={{74,-10},{94,10}}),
-          iconTransformation(extent={{70,-10},{90,10}})));
-    Thermal.DHTVolumes tubeWalls(N = Nw, T = Tp, Q = Qwp*Nt) if closedCircuit
-      "Interface to tube walls @ wall temperature"
-      annotation (Placement(transformation(extent={{-80,-22},{-60,-2}}), iconTransformation(extent={{-90,-60}, {-70,0}})));
-
-    parameter Boolean closedCircuit = false "true for closed-circuit tower";
-    parameter Boolean staticModel = false "= true for a static model";
-    parameter ThermoPower.Choices.Init.Options initOpt = system.initOpt "Initialization option"
-       annotation (Dialog(tab="Initialisation", enable = not staticModel));
-    parameter Integer Nt = 1 "Number of towers in parallel";
-    parameter Integer N(min = 2) = 10 "Number of nodes";
-    final parameter Integer Nw = N-1 "Number of volumes on the pipe wall";
-    parameter SI.Mass M0 = 0
-      "Water hold-up at zero water flow rate (single column)"
-      annotation(Dialog(group = "Dynamic model only", enable = not staticModel));
-    parameter SI.Mass Mnom = 0
-      "Water hold-up at nominal water flow rate (single tower)"
-      annotation(Dialog(group = "Dynamic model only", enable = not staticModel));
-    parameter SI.MassFlowRate wlnom
-      "Nominal water mass flow rate (single tower)";
-    parameter SI.VolumeFlowRate qanom
-      "Nominal air volume flow rate (single tower)";
-    parameter SI.Density rhoanom "Nominal air density";
-    parameter SI.Mass Mp = 0 "Mass of packing (single tower)"
-      annotation(Dialog(group = "Dynamic model only",
-                        enable = not staticModel and not closedCircuit));
-    parameter SI.SpecificHeatCapacity cp = 0 "Specific heat of packing"
-      annotation(Dialog(enable = not staticModel and not closedCircuit));
-    parameter SI.Area S "Surface of air/water mass and heat transfer (single tower)";
-    parameter SI.CoefficientOfHeatTransfer gamma_wp_nom = 0
-      "Nominal heat transfer coefficient beween water and packing or tubes"
-      annotation(Dialog(enable = not staticModel or closedCircuit));
-    parameter Real k_wa_nom(final unit = "kg/(m2.s)")
-      "Nominal total mass & heat transfer coefficient per unit surface (single tower)";
-    parameter SI.PerUnit nu_a
-      "Exponent of air flow rate in mass & heat transfer coefficients";
-    parameter SI.PerUnit nu_l
-      "Exponent of liquid flow rate in mass & heat transfer coefficients";
-    parameter Real rpm_nom "Nominal fan rotational speed [rpm]";
-    parameter SI.Power Wnom "Nominal power consumption (single tower)";
-    parameter SI.Pressure patm = 101325 "Atmospheric pressure";
-    parameter SI.Mass Mstart[N-1] = ones(N-1)*Mnom/(N-1) "Start value of water holdup in each volume"
-       annotation (Dialog(tab="Initialisation", enable = not staticModel));
-    parameter SI.SpecificEnthalpy hlstart[N] = fill(120e3,N) "Start values of liquid enthalpy at volume boundaries"
-      annotation (Dialog(tab="Initialisation"));
-    parameter SI.Temperature Tpstart[N-1] = ones(N-1)*(30+273.15) "Start value of packing temperature in each volume"
-       annotation (Dialog(tab="Initialisation",
-                          enable = not staticModel and not useHeatPort));
-    parameter SI.Temperature Twbstart = system.T_wb "Start value of average wet bulb temperature"
-      annotation (Dialog(tab="Initialisation"));
-    final parameter SI.MassFlowRate wanom = qanom*rhoanom
-      "Nominal air mass flow rate";
-
-    constant Real MMv = 0.029;
-    constant Real MMa = 0.018;
-
-    SI.MassFlowRate wl[N] "Water flow rate";
-    SI.MassFlowRate wa(start = qanom*rhoanom) "Dry air flow rate";
-    SI.MassFlowRate wev[N-1] "Evaporation flow rate";
-    SI.VolumeFlowRate qfan "Air volume flow rate through fan";
-    Water.SpecificEnthalpy hl[N] "Water specific enthalpy";
-    DryAir.SpecificEnthalpy ha[N]
-      "Specific enthalpy of saturated humid air @ Twb, per unit dry mass";
-    SI.SpecificEnthalpy hw[N]
-      "Specific enthalpy of saturated humid air @ water temperature, per unit dry mass";
-    Water.SpecificEnthalpy hvw[N]
-      "Specific enthalpy of saturated steam at water temperature";
-    Water.SpecificEnthalpy hva[N]
-      "Specific enthalpy of saturated steam at interface (i.e. Twb)";
-    DryAir.SpecificEnthalpy haw[N]
-      "Dry air specific enthalpy @ liquid temperature";
-    DryAir.SpecificEnthalpy haa[N]
-      "Dry air specific enthalpy @ interface (i.e. Twb)";
-    Water.AbsolutePressure pvw[N] "Saturation pressure at water temperature";
-    Water.AbsolutePressure pva[N](each start = 5000, each nominal = 5000)
-      "Saturation pressure at interface (i.e. Twb)";
-    SI.MassFraction Xvw[N](each start = 0.01)
-      "Absolute humidity (Mv/Ma_dry) of saturated air at the liquid temperature";
-    SI.MassFraction Xva[N](each start = 0.01)
-      "Absolute humidity (Mv/Ma_dry) of air at the interface";
-    Water.Temperature Tl[N](each start = 300) "Water temperature at the nodes";
-    Water.Temperature Tla[N-1](each start = 300) "Average water temperature for each volume";
-    Water.Temperature Twb[N](each start = Twbstart)
-      "Wet bulb temperature of air at interface";
-    SI.Mass M[N-1](
-      each start = Mnom/(N-1),
-      each stateSelect = if staticModel then StateSelect.default else StateSelect.prefer)
-       "Water hold-up";
-    Water.SpecificEnthalpy hltilde[N-1](
-      start = hlstart[2:N],
-      each stateSelect = if staticModel then StateSelect.default else StateSelect.prefer)
-      "Specific enthalpy state variable";
-    SI.Temperature Tp[N-1](
-      start = Tpstart,
-      each stateSelect = if not staticModel and not closedCircuit then StateSelect.prefer else StateSelect.default)
-       "Temperature of packing or tube surface";
-    SI.Power Qwp[N-1] "Thermal power transfer between water and packing or tubes";
-    SI.Power Q[N-1] "Total thermal power transfer water -> air interface (@Twb)";
-    SI.Power W "Power consumption of the fan (single column)";
-    SI.Power Wtot "Power consumption of the fans (all columns)";
-    SI.CoefficientOfHeatTransfer gamma_wp[N](each start = gamma_wp_nom)
-      "Heat transfer coefficient between water and packing or tubes";
-    Real k_wa(final unit = "kg/(m2.s)", start = k_wa_nom)
-      "Total evaporation heat transfer coefficient per unit surface";
-
-    SI.Temperature Tlin "Inlet water temperature";
-    SI.Temperature Tlout "Outlet water temperature";
-
-  equation
-    for i in 1:N-1 loop
-      // Liquid mass and energy balance
-      if staticModel then
-        0 = wl[i] - wl[i+1] - wev[i];
-        0 = wl[i]*hl[i] - wl[i+1]*hl[i+1] - Q[i] + Qwp[i];
-        M[i] = 0;
-      else
-        der(M[i]) = wl[i] - wl[i+1] - wev[i];
-        der(M[i])*hltilde[i] + M[i]*der(hltilde[i]) =
-          wl[i]*hl[i] - wl[i+1]*hl[i+1] - Q[i] + Qwp[i];
-        wl[i+1] = (M[i] - M0/(N-1))/(Mnom/(N-1) - M0/(N-1))*wlnom;
-      end if;
-
-      // Energy balance for packing/tubes
-      // if closedCircuit = true, Qwp is bound to the tubeWalls.Q variable in the connector
-      if not closedCircuit then
-        if not Mp > 0 or staticModel then
-           0 = -Qwp[i];
-        else
-           cp*Mp/(N-1)*der(Tp[i]) = -Qwp[i];
-        end if;
-      end if;
-
-
-      // Equation for Qwp for open-circuit dynamic model with packing
-      // and for closed-circuit model with external tubes
-      // otherwise dummy equation for unused Tp
-      if closedCircuit or (not staticModel and Mp > 0) then
-        Qwp[i] = (Tp[i] - Tla[i])*S/(N-1)*gamma_wp[i];
-      else
-        Tp[i] = Tl[i];
-      end if;
-
-      wa*Xva[i+1] + wev[i] = wa*Xva[i] "vapour mass balance in air";
-      wa*ha[i+1] + Q[i] = wa*ha[i] "energy balance @ air interface";
-
-      hltilde[i] = hl[i+1];
-
-      Q[i] = ((hw[i] + hw[i+1])/2 - (ha[i] + ha[i+1])/2)*S/(N-1)*k_wa;
-
-      Tla[i] = if closedCircuit then Tl[i+1] else (Tl[i] + Tl[i+1])/2;
-    end for;
-
-    for i in 1:N loop
-      Tl[i] = Water.temperature_ph(patm, hl[i]);
-      pvw[i] = Water.saturationPressure(Tl[i]);
-      pva[i] = Water.saturationPressure(Twb[i]);
-      hvw[i] = Water.dewEnthalpy(Water.setSat_T(Tl[i]));
-      hva[i] = Water.dewEnthalpy(Water.setSat_T(Twb[i]));
-      haw[i] = DryAir.specificEnthalpy(DryAir.setState_pTX(patm, Tl[i]));
-      haa[i] = DryAir.specificEnthalpy(DryAir.setState_pTX(patm, Twb[i]));
-      pvw[i]/patm = Xvw[i]*MMa/(Xvw[i]*MMa+MMv)
-        "Saturation conditions @ liquid temperature";
-      pva[i]/patm = Xva[i]*MMa/(Xva[i]*MMa+MMv)
-        "Saturation conditions @ interface (i.e. Twb)";
-      hw[i] = haw[i] + hvw[i]*Xvw[i];
-      ha[i] = haa[i] + hva[i]*Xva[i];
-
-      gamma_wp[i] = gamma_wp_nom*max(wl[i]/wlnom, 0.3)^nu_l;
-    end for;
-
-    k_wa = k_wa_nom*max(wa/wanom, 0.3)^nu_a*max(wl[1]/wlnom, 0.3)^nu_l;
-    qfan = qanom*fanRpm/rpm_nom;
-    wa = qfan*rhoanom "Dry air flow roughly equal to humid air flow (+/- 1%)";
-    W = Wnom*(fanRpm/rpm_nom)^3;
-    Wtot = W*Nt;
-
-    // Boundary conditions
-    wl[1] = waterInlet.m_flow/Nt;
-    wl[N] = -waterOutlet.m_flow/Nt;
-    waterInlet.p = patm;
-    hl[1] = inStream(waterInlet.h_outflow);
-    waterInlet.h_outflow = hltilde[1];
-    waterOutlet.h_outflow = hl[N];
-    Twb[N] = system.T_wb;
-
-    powerConsumption = Wtot;
-
-    // Monitoring variables
-    Tlin = Tl[1];
-    Tlout = Tl[N];
-
-  initial equation
-    if not staticModel and initOpt == ThermoPower.Choices.Init.Options.steadyState then
-      der(M) = zeros(N-1);
-      der(hltilde) = zeros(N-1);
-      if Mp > 0 then
-        der(Tp) = zeros(N-1);
-      end if;
-    elseif not staticModel and initOpt == ThermoPower.Choices.Init.Options.fixedState then
-      M = Mstart;
-      hltilde = hlstart[2:N];
-      if Mp > 0 then
-        Tp = Tpstart;
-      end if;
-    end if;
-
-    // Default parameter values not allowed for dynamic model
-    if closedCircuit then
-      assert(not Mp > 0, "A closed-circuit tower should have Mp = 0");
-    end if;
-    if not staticModel then
-      assert(M0 > 0, "M0 must be positive");
-      assert(Mnom > 0, "Mnom must be positive");
-      assert(not (Mp > 0 and not cp > 0), "If Mp > 0 then cp must be positive");
-      assert(not (Mp > 0 and not gamma_wp_nom > 0), "If Mp > 0 then gamma_wp_nom must be positive");
-    end if;
-    annotation (Icon(graphics={Polygon(
-            points={{-70,80},{-70,-80},{70,-80},{70,80},{-70,80}},
-            lineColor={0,0,0},
-            smooth=Smooth.None,
-            fillColor={0,0,255},
-            fillPattern=FillPattern.Solid), Polygon(
-            points={{-12,36},{-28,36},{-40,48},{-28,62},{-12,62},{12,36},{30,36},
-                {40,48},{30,62},{12,62},{0,48},{-12,36}},
-            lineColor={0,0,0},
-            smooth=Smooth.None,
-            fillColor={255,255,255},
-            fillPattern=FillPattern.Solid)}), Documentation(info="<html>
+</html>"),
+      Icon(coordinateSystem(extent = {{-120, -160}, {120, 160}}), graphics = {Rectangle(extent = {{-60, 128}, {60, 58}}, lineColor = {0, 0, 255}, pattern = LinePattern.None, fillColor = {128, 128, 128}, fillPattern = FillPattern.Solid), Ellipse(extent = {{-60, 140}, {60, 112}}, lineColor = {0, 0, 255}, pattern = LinePattern.None, fillColor = {128, 128, 128}, fillPattern = FillPattern.Solid), Ellipse(extent = {{-52, 132}, {54, 116}}, lineColor = {0, 0, 191}, pattern = LinePattern.None, fillColor = {159, 159, 223}, fillPattern = FillPattern.Solid), Rectangle(extent = {{-54, 124}, {54, 58}}, lineColor = {0, 0, 255}, pattern = LinePattern.None, fillColor = {159, 159, 223}, fillPattern = FillPattern.Solid), Polygon(points = {{-100, 96}, {2, 96}, {2, 102}, {-100, 102}, {-100, 96}}, lineColor = {0, 0, 255}, pattern = LinePattern.None, fillColor = {128, 128, 128}, fillPattern = FillPattern.Solid), Polygon(points = {{0, 96}, {-12, 84}, {10, 84}, {0, 96}}, lineColor = {0, 0, 255}, fillColor = {0, 0, 235}, fillPattern = FillPattern.Solid), Polygon(points = {{-54, 60}, {56, 60}, {12, 2}, {-10, 2}, {-54, 60}}, lineColor = {159, 159, 223}, fillColor = {159, 159, 223}, fillPattern = FillPattern.Solid), Polygon(points = {{-60, 60}, {-12, 0}, {-4, -2}, {-54, 60}, {-60, 60}}, lineColor = {128, 128, 128}, fillColor = {128, 128, 128}, fillPattern = FillPattern.Solid), Polygon(points = {{54, 60}, {60, 60}, {12, 2}, {6, 2}, {54, 60}}, lineColor = {128, 128, 128}, fillColor = {128, 128, 128}, fillPattern = FillPattern.Solid), Rectangle(extent = {{-12, 2}, {12, -140}}, lineColor = {0, 0, 255}, pattern = LinePattern.None, fillColor = {128, 128, 128}, fillPattern = FillPattern.Solid), Rectangle(extent = {{8, 20}, {-8, 20}}, fillColor = {159, 159, 223}, fillPattern = FillPattern.Solid, pattern = LinePattern.None), Rectangle(extent = {{6, 2}, {-6, -136}}, fillColor = {0, 0, 255}, fillPattern = FillPattern.Solid, pattern = LinePattern.None, lineColor = {0, 0, 0})}),
+      Diagram(coordinateSystem(extent = {{-120, -160}, {120, 160}})));
+  end BarometricCondenser;
+
+  model CoolingTower "Cooling tower with variable speed fan"
+    import Modelica.Units.Conversions;
+    package Water = Modelica.Media.Water.StandardWater;
+    package DryAir = Modelica.Media.Air.SimpleAir;
+    outer ThermoPower.System system "System object";
+    ThermoPower.Water.FlangeA waterInlet annotation(
+      Placement(transformation(extent = {{-10, 80}, {10, 100}}), iconTransformation(extent = {{-10, 80}, {10, 100}})));
+    ThermoPower.Water.FlangeB waterOutlet annotation(
+      Placement(transformation(extent = {{-10, -100}, {10, -80}}), iconTransformation(extent = {{-10, -100}, {10, -80}})));
+    Modelica.Blocks.Interfaces.RealInput fanRpm "Fan rotational speed in rpm" annotation(
+      Placement(transformation(extent = {{-100, 60}, {-60, 100}}), iconTransformation(extent = {{-90, 30}, {-70, 50}})));
+    Modelica.Blocks.Interfaces.RealOutput powerConsumption "Total fan power consumption" annotation(
+      Placement(transformation(extent = {{74, -10}, {94, 10}}), iconTransformation(extent = {{70, -10}, {90, 10}})));
+    Thermal.DHTVolumes tubeWalls(N = Nw, T = Tp, Q = Qwp * Nt) if closedCircuit "Interface to tube walls @ wall temperature" annotation(
+      Placement(transformation(extent = {{-80, -22}, {-60, -2}}), iconTransformation(extent = {{-90, -60}, {-70, 0}})));
+    parameter Boolean closedCircuit = false "true for closed-circuit tower";
+    parameter Boolean staticModel = false "= true for a static model";
+    parameter ThermoPower.Choices.Init.Options initOpt = system.initOpt "Initialization option" annotation(
+      Dialog(tab = "Initialisation", enable = not staticModel));
+    parameter Integer Nt = 1 "Number of towers in parallel";
+    parameter Integer N(min = 2) = 10 "Number of nodes";
+    final parameter Integer Nw = N - 1 "Number of volumes on the pipe wall";
+    parameter SI.Mass M0 = 0 "Water hold-up at zero water flow rate (single column)" annotation(
+      Dialog(group = "Dynamic model only", enable = not staticModel));
+    parameter SI.Mass Mnom = 0 "Water hold-up at nominal water flow rate (single tower)" annotation(
+      Dialog(group = "Dynamic model only", enable = not staticModel));
+    parameter SI.MassFlowRate wlnom "Nominal water mass flow rate (single tower)";
+    parameter SI.VolumeFlowRate qanom "Nominal air volume flow rate (single tower)";
+    parameter SI.Density rhoanom "Nominal air density";
+    parameter SI.Mass Mp = 0 "Mass of packing (single tower)" annotation(
+      Dialog(group = "Dynamic model only", enable = not staticModel and not closedCircuit));
+    parameter SI.SpecificHeatCapacity cp = 0 "Specific heat of packing" annotation(
+      Dialog(enable = not staticModel and not closedCircuit));
+    parameter SI.Area S "Surface of air/water mass and heat transfer (single tower)";
+    parameter SI.CoefficientOfHeatTransfer gamma_wp_nom = 0 "Nominal heat transfer coefficient beween water and packing or tubes" annotation(
+      Dialog(enable = not staticModel or closedCircuit));
+    parameter Real k_wa_nom(final unit = "kg/(m2.s)") "Nominal total mass & heat transfer coefficient per unit surface (single tower)";
+    parameter SI.PerUnit nu_a "Exponent of air flow rate in mass & heat transfer coefficients";
+    parameter SI.PerUnit nu_l "Exponent of liquid flow rate in mass & heat transfer coefficients";
+    parameter Real rpm_nom "Nominal fan rotational speed [rpm]";
+    parameter SI.Power Wnom "Nominal power consumption (single tower)";
+    parameter SI.Pressure patm = 101325 "Atmospheric pressure";
+    parameter SI.Mass Mstart[N - 1] = ones(N - 1) * Mnom / (N - 1) "Start value of water holdup in each volume" annotation(
+      Dialog(tab = "Initialisation", enable = not staticModel));
+    parameter SI.SpecificEnthalpy hlstart[N] = fill(120e3, N) "Start values of liquid enthalpy at volume boundaries" annotation(
+      Dialog(tab = "Initialisation"));
+    parameter SI.Temperature Tpstart[N - 1] = ones(N - 1) * (30 + 273.15) "Start value of packing temperature in each volume" annotation(
+      Dialog(tab = "Initialisation", enable = not staticModel and not useHeatPort));
+    parameter SI.Temperature Twbstart = system.T_wb "Start value of average wet bulb temperature" annotation(
+      Dialog(tab = "Initialisation"));
+    final parameter SI.MassFlowRate wanom = qanom * rhoanom "Nominal air mass flow rate";
+    constant Real MMv = 0.029;
+    constant Real MMa = 0.018;
+    SI.MassFlowRate wl[N] "Water flow rate";
+    SI.MassFlowRate wa(start = qanom * rhoanom) "Dry air flow rate";
+    SI.MassFlowRate wev[N - 1] "Evaporation flow rate";
+    SI.VolumeFlowRate qfan "Air volume flow rate through fan";
+    Water.SpecificEnthalpy hl[N] "Water specific enthalpy";
+    DryAir.SpecificEnthalpy ha[N] "Specific enthalpy of saturated humid air @ Twb, per unit dry mass";
+    SI.SpecificEnthalpy hw[N] "Specific enthalpy of saturated humid air @ water temperature, per unit dry mass";
+    Water.SpecificEnthalpy hvw[N] "Specific enthalpy of saturated steam at water temperature";
+    Water.SpecificEnthalpy hva[N] "Specific enthalpy of saturated steam at interface (i.e. Twb)";
+    DryAir.SpecificEnthalpy haw[N] "Dry air specific enthalpy @ liquid temperature";
+    DryAir.SpecificEnthalpy haa[N] "Dry air specific enthalpy @ interface (i.e. Twb)";
+    Water.AbsolutePressure pvw[N] "Saturation pressure at water temperature";
+    Water.AbsolutePressure pva[N](each start = 5000, each nominal = 5000) "Saturation pressure at interface (i.e. Twb)";
+    SI.MassFraction Xvw[N](each start = 0.01) "Absolute humidity (Mv/Ma_dry) of saturated air at the liquid temperature";
+    SI.MassFraction Xva[N](each start = 0.01) "Absolute humidity (Mv/Ma_dry) of air at the interface";
+    Water.Temperature Tl[N](each start = 300) "Water temperature at the nodes";
+    Water.Temperature Tla[N - 1](each start = 300) "Average water temperature for each volume";
+    Water.Temperature Twb[N](each start = Twbstart) "Wet bulb temperature of air at interface";
+    SI.Mass M[N - 1](each start = Mnom / (N - 1), each stateSelect = if staticModel then StateSelect.default else StateSelect.prefer) "Water hold-up";
+    Water.SpecificEnthalpy hltilde[N - 1](start = hlstart[2:N], each stateSelect = if staticModel then StateSelect.default else StateSelect.prefer) "Specific enthalpy state variable";
+    SI.Temperature Tp[N - 1](start = Tpstart, each stateSelect = if not staticModel and not closedCircuit then StateSelect.prefer else StateSelect.default) "Temperature of packing or tube surface";
+    SI.Power Qwp[N - 1] "Thermal power transfer between water and packing or tubes";
+    SI.Power Q[N - 1] "Total thermal power transfer water -> air interface (@Twb)";
+    SI.Power W "Power consumption of the fan (single column)";
+    SI.Power Wtot "Power consumption of the fans (all columns)";
+    SI.CoefficientOfHeatTransfer gamma_wp[N](each start = gamma_wp_nom) "Heat transfer coefficient between water and packing or tubes";
+    Real k_wa(final unit = "kg/(m2.s)", start = k_wa_nom) "Total evaporation heat transfer coefficient per unit surface";
+    SI.Temperature Tlin "Inlet water temperature";
+    SI.Temperature Tlout "Outlet water temperature";
+  equation
+    for i in 1:N - 1 loop
+// Liquid mass and energy balance
+      if staticModel then
+        0 = wl[i] - wl[i + 1] - wev[i];
+        0 = wl[i] * hl[i] - wl[i + 1] * hl[i + 1] - Q[i] + Qwp[i];
+        M[i] = 0;
+      else
+        der(M[i]) = wl[i] - wl[i + 1] - wev[i];
+        der(M[i]) * hltilde[i] + M[i] * der(hltilde[i]) = wl[i] * hl[i] - wl[i + 1] * hl[i + 1] - Q[i] + Qwp[i];
+        wl[i + 1] = (M[i] - M0 / (N - 1)) / (Mnom / (N - 1) - M0 / (N - 1)) * wlnom;
+      end if;
+// Energy balance for packing/tubes
+// if closedCircuit = true, Qwp is bound to the tubeWalls.Q variable in the connector
+      if not closedCircuit then
+        if not Mp > 0 or staticModel then
+          0 = -Qwp[i];
+        else
+          cp * Mp / (N - 1) * der(Tp[i]) = -Qwp[i];
+        end if;
+      end if;
+// Equation for Qwp for open-circuit dynamic model with packing
+// and for closed-circuit model with external tubes
+// otherwise dummy equation for unused Tp
+      if closedCircuit or not staticModel and Mp > 0 then
+        Qwp[i] = (Tp[i] - Tla[i]) * S / (N - 1) * gamma_wp[i];
+      else
+        Tp[i] = Tl[i];
+      end if;
+      wa * Xva[i + 1] + wev[i] = wa * Xva[i] "vapour mass balance in air";
+      wa * ha[i + 1] + Q[i] = wa * ha[i] "energy balance @ air interface";
+      hltilde[i] = hl[i + 1];
+      Q[i] = ((hw[i] + hw[i + 1]) / 2 - (ha[i] + ha[i + 1]) / 2) * S / (N - 1) * k_wa;
+      Tla[i] = if closedCircuit then Tl[i + 1] else (Tl[i] + Tl[i + 1]) / 2;
+    end for;
+    for i in 1:N loop
+      Tl[i] = Water.temperature_ph(patm, hl[i]);
+      pvw[i] = Water.saturationPressure(Tl[i]);
+      pva[i] = Water.saturationPressure(Twb[i]);
+      hvw[i] = Water.dewEnthalpy(Water.setSat_T(Tl[i]));
+      hva[i] = Water.dewEnthalpy(Water.setSat_T(Twb[i]));
+      haw[i] = DryAir.specificEnthalpy(DryAir.setState_pTX(patm, Tl[i]));
+      haa[i] = DryAir.specificEnthalpy(DryAir.setState_pTX(patm, Twb[i]));
+      pvw[i] / patm = Xvw[i] * MMa / (Xvw[i] * MMa + MMv) "Saturation conditions @ liquid temperature";
+      pva[i] / patm = Xva[i] * MMa / (Xva[i] * MMa + MMv) "Saturation conditions @ interface (i.e. Twb)";
+      hw[i] = haw[i] + hvw[i] * Xvw[i];
+      ha[i] = haa[i] + hva[i] * Xva[i];
+      gamma_wp[i] = gamma_wp_nom * max(wl[i] / wlnom, 0.3) ^ nu_l;
+    end for;
+    k_wa = k_wa_nom * max(wa / wanom, 0.3) ^ nu_a * max(wl[1] / wlnom, 0.3) ^ nu_l;
+    qfan = qanom * fanRpm / rpm_nom;
+    wa = qfan * rhoanom "Dry air flow roughly equal to humid air flow (+/- 1%)";
+    W = Wnom * (fanRpm / rpm_nom) ^ 3;
+    Wtot = W * Nt;
+// Boundary conditions
+    wl[1] = waterInlet.m_flow / Nt;
+    wl[N] = -waterOutlet.m_flow / Nt;
+    waterInlet.p = patm;
+    hl[1] = inStream(waterInlet.h_outflow);
+    waterInlet.h_outflow = hltilde[1];
+    waterOutlet.h_outflow = hl[N];
+    Twb[N] = system.T_wb;
+    powerConsumption = Wtot;
+// Monitoring variables
+    Tlin = Tl[1];
+    Tlout = Tl[N];
+  initial equation
+    if not staticModel and initOpt == ThermoPower.Choices.Init.Options.steadyState then
+      der(M) = zeros(N - 1);
+      der(hltilde) = zeros(N - 1);
+      if Mp > 0 then
+        der(Tp) = zeros(N - 1);
+      end if;
+    elseif not staticModel and initOpt == ThermoPower.Choices.Init.Options.fixedState then
+      M = Mstart;
+      hltilde = hlstart[2:N];
+      if Mp > 0 then
+        Tp = Tpstart;
+      end if;
+    end if;
+// Default parameter values not allowed for dynamic model
+    if closedCircuit then
+      assert(not Mp > 0, "A closed-circuit tower should have Mp = 0");
+    end if;
+    if not staticModel then
+      assert(M0 > 0, "M0 must be positive");
+      assert(Mnom > 0, "Mnom must be positive");
+      assert(not (Mp > 0 and not cp > 0), "If Mp > 0 then cp must be positive");
+      assert(not (Mp > 0 and not gamma_wp_nom > 0), "If Mp > 0 then gamma_wp_nom must be positive");
+    end if;
+    annotation(
+      Icon(graphics = {Polygon(points = {{-70, 80}, {-70, -80}, {70, -80}, {70, 80}, {-70, 80}}, lineColor = {0, 0, 0}, smooth = Smooth.None, fillColor = {0, 0, 255}, fillPattern = FillPattern.Solid), Polygon(points = {{-12, 36}, {-28, 36}, {-40, 48}, {-28, 62}, {-12, 62}, {12, 36}, {30, 36}, {40, 48}, {30, 62}, {12, 62}, {0, 48}, {-12, 36}}, lineColor = {0, 0, 0}, smooth = Smooth.None, fillColor = {255, 255, 255}, fillPattern = FillPattern.Solid)}),
+      Documentation(info = "<html>
 <p>This model represents a cooling tower with variable speed fans. If <code>closedCircuit</code> is false, the model
 represents a cooling tower filled with metallic packing, where the incoming water is cooled by direct contact with humid air,
 by means of evaporation. Dynamic models with <code>Mp > 0</code> also represent heat storage in the packing and heat
@@ -5029,97 +3844,91 @@
 <p>The hold-up of water in the packaging is modelled assuming a simple linear relationship between the hold-up in each volume and the corresponding outgoing flow, which is calibrated by the <code>Mnom</code> and <code>M0</code> parameters. The energy storage in the water hold-up and in the packaging is accounted for.</p>
 <p>The behaviour of the fan is modelled by kinematic similarity; the air flow is proportional to the fan rpm, while the consumption is proportional to the cube of the fan rpm.</p>
 <p>Is it possible to neglect all dynamic behaviour and get a static model by setting <code>staticModel=true</code>.</p>
-</html>",   revisions="<html>
+</html>", revisions = "<html>
 <ul>
 <li><i>28 Jul 2017</i> <a href=\"mailto:francesco.casella@polimi.it\">Francesco Casella</a>:<br>First release.</li>
 </ul>
-</html>"));
-  end CoolingTower;
-
-  model ExpansionTankIdeal "Ideal expansion tank with prescribed pressure"
-    extends Icons.Water.ExpansionTankIdeal;
-    replaceable package Medium = Modelica.Media.Water.StandardWater constrainedby
-      Modelica.Media.Interfaces.PartialMedium  "Liquid medium model" annotation (
-       choicesAllMatching = true);
-    outer ThermoPower.System system "System wide properties";
-    parameter Boolean allowFlowReversal = system.allowFlowReversal "= true to allow flow reversal, false restricts to design direction" annotation (
-      Evaluate = true);
-    parameter SI.Pressure pf "Fixed flange pressure";
-    Medium.MassFlowRate wn "Net entering mass flow rate";
-
-    ThermoPower.Water.FlangeA WaterInfl(redeclare package Medium = Medium, m_flow(min = if allowFlowReversal then -Modelica.Constants.inf else 0)) annotation (
-      Placement(transformation(extent={{-60,-80},{-20,-40}},       rotation = 0),
-          iconTransformation(extent={{-60,-80},{-20,-40}})));
-    ThermoPower.Water.FlangeB WaterOutfl(redeclare package Medium = Medium, m_flow(max = if allowFlowReversal then +Modelica.Constants.inf else 0)) annotation (
-      Placement(transformation(extent={{20,-80},{60,-40}},       rotation = 0),
-          iconTransformation(extent={{20,-80},{60,-40}})));
-
-  equation
-    WaterInfl.h_outflow = inStream(WaterOutfl.h_outflow);
-    WaterOutfl.h_outflow = inStream(WaterInfl.h_outflow);
-    WaterInfl.p = pf;
-    WaterOutfl.p = pf;
-    wn = WaterInfl.m_flow + WaterOutfl.m_flow;
-    annotation (Icon(coordinateSystem(preserveAspectRatio=false)), Diagram(
-          coordinateSystem(preserveAspectRatio=false)),
-      Documentation(info="<html>
+</html>"));
+  end CoolingTower;
+
+  model ExpansionTankIdeal "Ideal expansion tank with prescribed pressure"
+    extends Icons.Water.ExpansionTankIdeal;
+    replaceable package Medium = Modelica.Media.Water.StandardWater constrainedby Modelica.Media.Interfaces.PartialMedium "Liquid medium model" annotation(
+       choicesAllMatching = true);
+    outer ThermoPower.System system "System wide properties";
+    parameter Boolean allowFlowReversal = system.allowFlowReversal "= true to allow flow reversal, false restricts to design direction" annotation(
+      Evaluate = true);
+    parameter SI.Pressure pf "Fixed flange pressure";
+    Medium.MassFlowRate wn "Net entering mass flow rate";
+    ThermoPower.Water.FlangeA WaterInfl(redeclare package Medium = Medium, m_flow(min = if allowFlowReversal then -Modelica.Constants.inf else 0)) annotation(
+      Placement(transformation(extent = {{-60, -80}, {-20, -40}}, rotation = 0), iconTransformation(extent = {{-60, -80}, {-20, -40}})));
+    ThermoPower.Water.FlangeB WaterOutfl(redeclare package Medium = Medium, m_flow(max = if allowFlowReversal then +Modelica.Constants.inf else 0)) annotation(
+      Placement(transformation(extent = {{20, -80}, {60, -40}}, rotation = 0), iconTransformation(extent = {{20, -80}, {60, -40}})));
+  equation
+    WaterInfl.h_outflow = inStream(WaterOutfl.h_outflow);
+    WaterOutfl.h_outflow = inStream(WaterInfl.h_outflow);
+    WaterInfl.p = pf;
+    WaterOutfl.p = pf;
+    wn = WaterInfl.m_flow + WaterOutfl.m_flow;
+    annotation(
+      Icon(coordinateSystem(preserveAspectRatio = false)),
+      Diagram(coordinateSystem(preserveAspectRatio = false)),
+      Documentation(info = "<html>
 <p>This model implements an ideal expansion tank, in wich the pressure at the bottom flanges is prescribed, while the water mass is free to change in order to compensaste the fluid expansion in the circuit connected to the expansion tank itself.</p>
 <p>Water flows in and out through the interfaces at the expansion tank bottom (flow reversal supported), the water entalpy is transferred through the flanges following to the water flow direction, whithout changes.</p>
 <h4>Parameters</h4>
 <ul>
 <li>pf: prescribed pressure at the bottom flanges.</li>
 </ul>
-</html>", revisions="<html>
+</html>", revisions = "<html>
 <ul>
 <li><i>12 Dec 2018</i> <a href=\"mailto:andrea.bartolini@dynamica-it.com\">Andrea Bartolini</a>:<br>First release.</li>
 </ul>
 <p>First Release.</p>
-</html>"));
-  end ExpansionTankIdeal;
-
-  function f_chen "Chen's correlation for two-phase flow in a tube"
-
-    input SI.MassFlowRate w "Mass flowrate";
-    input SI.Length D "Tube hydraulic diameter";
-    input SI.Area A "Tube cross-section";
-    input SI.DynamicViscosity muf "Liquid dynamic viscosity";
-    input SI.ThermalConductivity kf "Liquid thermal conductivity";
-    input SI.SpecificHeatCapacity cpf "Liquid cp";
-    input SI.Density rhof "Liquid density";
-    input SI.SurfaceTension sigma "Surface Tension";
-    input SI.Density rhog "Vapour density";
-    input SI.DynamicViscosity mug "Vapour dynamic viscosity";
-    input SI.Temperature DTsat "Saturation temperature difference (wall-bulk)";
-    input SI.Pressure Dpsat "Saturation pressure difference (wall-bulk)";
-    input SI.SpecificEnthalpy ifg "Latent heat of vaporization";
-    input SI.PerUnit x "Steam quality";
-    output SI.CoefficientOfHeatTransfer hTP
-      "Two-phase total heat transfer coefficient";
-  protected
-    Real invXtt;
-    Real F;
-    Real S;
-    Real Ref;
-    Real Prf;
-    Real ReTP;
-    SI.CoefficientOfHeatTransfer hC;
-    SI.CoefficientOfHeatTransfer hNcB;
-  algorithm
-    invXtt := (x/(1 - x))^0.9*(rhof/rhog)^0.5*(mug/muf)^0.1;
-    if invXtt < 0.1 then
-      F := 1;
-    else
-      F := 2.35*(invXtt + 0.213)^0.736;
-    end if;
-    Ref := (w/A*(1 - x)*D)/muf;
-    Prf := (muf*cpf/kf);
-    hC := 0.023*Ref^0.8*Prf^0.4*kf/D*F;
-    ReTP := F^1.25*Ref;
-    S := 1/(1 + 2.53e-6*ReTP^1.17);
-    hNcB := 0.00122*(kf^0.79*cpf^0.45*rhof^0.49)/(sigma^0.5*muf^0.29*ifg^0.24*
-      rhog^0.24)*max(0, DTsat)^0.24*max(0, Dpsat)^0.75*S;
-    hTP := hC + hNcB;
-    annotation (Documentation(info="<HTML>
+</html>"));
+  end ExpansionTankIdeal;
+
+  function f_chen "Chen's correlation for two-phase flow in a tube"
+    input SI.MassFlowRate w "Mass flowrate";
+    input SI.Length D "Tube hydraulic diameter";
+    input SI.Area A "Tube cross-section";
+    input SI.DynamicViscosity muf "Liquid dynamic viscosity";
+    input SI.ThermalConductivity kf "Liquid thermal conductivity";
+    input SI.SpecificHeatCapacity cpf "Liquid cp";
+    input SI.Density rhof "Liquid density";
+    input SI.SurfaceTension sigma "Surface Tension";
+    input SI.Density rhog "Vapour density";
+    input SI.DynamicViscosity mug "Vapour dynamic viscosity";
+    input SI.Temperature DTsat "Saturation temperature difference (wall-bulk)";
+    input SI.Pressure Dpsat "Saturation pressure difference (wall-bulk)";
+    input SI.SpecificEnthalpy ifg "Latent heat of vaporization";
+    input SI.PerUnit x "Steam quality";
+    output SI.CoefficientOfHeatTransfer hTP "Two-phase total heat transfer coefficient";
+  protected
+    Real invXtt;
+    Real F;
+    Real S;
+    Real Ref;
+    Real Prf;
+    Real ReTP;
+    SI.CoefficientOfHeatTransfer hC;
+    SI.CoefficientOfHeatTransfer hNcB;
+  algorithm
+    invXtt := (x / (1 - x)) ^ 0.9 * (rhof / rhog) ^ 0.5 * (mug / muf) ^ 0.1;
+    if invXtt < 0.1 then
+      F := 1;
+    else
+      F := 2.35 * (invXtt + 0.213) ^ 0.736;
+    end if;
+    Ref := w / A * (1 - x) * D / muf;
+    Prf := muf * cpf / kf;
+    hC := 0.023 * Ref ^ 0.8 * Prf ^ 0.4 * kf / D * F;
+    ReTP := F ^ 1.25 * Ref;
+    S := 1 / (1 + 2.53e-6 * ReTP ^ 1.17);
+    hNcB := 0.00122 * (kf ^ 0.79 * cpf ^ 0.45 * rhof ^ 0.49) / (sigma ^ 0.5 * muf ^ 0.29 * ifg ^ 0.24 * rhog ^ 0.24) * max(0, DTsat) ^ 0.24 * max(0, Dpsat) ^ 0.75 * S;
+    hTP := hC + hNcB;
+    annotation(
+      Documentation(info = "<HTML>
 <p>Chen's correlation for the computation of the heat transfer coefficient in two-phase flows.
 <p><b>Revision history:</b></p>
 <ul>
@@ -5127,22 +3936,23 @@
     by <a href=\"mailto:francesco.casella@polimi.it\">Francesco Casella</a>:<br>
        First release.</li>
 </ul>
-</HTML>"));
-  end f_chen;
-
-  function f_colebrook "Fanning friction factor for water/steam flows"
-    input SI.MassFlowRate w;
-    input Real D_A;
-    input Real e;
-    input SI.DynamicViscosity mu;
-    output SI.PerUnit f;
-  protected
-    SI.PerUnit Re;
-  algorithm
-    Re := abs(w)*D_A/mu;
-    Re := if Re > 2100 then Re else 2100;
-    f := 0.332/(log(e/3.7 + 5.47/Re^0.9)^2);
-    annotation (Documentation(info="<HTML>
+</HTML>"));
+  end f_chen;
+
+  function f_colebrook "Fanning friction factor for water/steam flows"
+    input SI.MassFlowRate w;
+    input Real D_A;
+    input Real e;
+    input SI.DynamicViscosity mu;
+    output SI.PerUnit f;
+  protected
+    SI.PerUnit Re;
+  algorithm
+    Re := abs(w) * D_A / mu;
+    Re := if Re > 2100 then Re else 2100;
+    f := 0.332 / log(e / 3.7 + 5.47 / Re ^ 0.9) ^ 2;
+    annotation(
+      Documentation(info = "<HTML>
 <p>The Fanning friction factor is computed by Colebrook's equation, assuming turbulent, one-phase flow. For low Reynolds numbers, the limit value for turbulent flow is returned.
 <p><b>Revision history:</b></p>
 <ul>
@@ -5150,28 +3960,28 @@
     by <a href=\"mailto:francesco.casella@polimi.it\">Francesco Casella</a>:<br>
        First release.</li>
 </ul>
-</HTML>"));
-  end f_colebrook;
-
-  function f_colebrook_2ph
-    "Fanning friction factor for a two phase water/steam flow"
-    input SI.MassFlowRate w;
-    input Real D_A;
-    input Real e;
-    input SI.DynamicViscosity mul;
-    input SI.DynamicViscosity muv;
-    input SI.PerUnit x;
-    output SI.PerUnit f;
-  protected
-    SI.PerUnit Re;
-  protected
-    SI.DynamicViscosity mu;
-  algorithm
-    mu := 1/(x/muv + (1 - x)/mul);
-    Re := w*D_A/mu;
-    Re := if Re > 2100 then Re else 2100;
-    f := 0.332/(log(e/3.7 + 5.47/Re^0.9)^2);
-    annotation (Documentation(info="<HTML>
+</HTML>"));
+  end f_colebrook;
+
+  function f_colebrook_2ph "Fanning friction factor for a two phase water/steam flow"
+    input SI.MassFlowRate w;
+    input Real D_A;
+    input Real e;
+    input SI.DynamicViscosity mul;
+    input SI.DynamicViscosity muv;
+    input SI.PerUnit x;
+    output SI.PerUnit f;
+  protected
+    SI.PerUnit Re;
+  protected
+    SI.DynamicViscosity mu;
+  algorithm
+    mu := 1 / (x / muv + (1 - x) / mul);
+    Re := w * D_A / mu;
+    Re := if Re > 2100 then Re else 2100;
+    f := 0.332 / log(e / 3.7 + 5.47 / Re ^ 0.9) ^ 2;
+    annotation(
+      Documentation(info = "<HTML>
 <p>The Fanning friction factor is computed by Colebrook's equation, assuming turbulent, homogeneous two-phase flow. For low Reynolds numbers, the limit value for turbulent flow is returned.
 <p><b>Revision history:</b></p>
 <ul>
@@ -5179,27 +3989,26 @@
     by <a href=\"mailto:francesco.casella@polimi.it\">Francesco Casella</a>:<br>
        First release.</li>
 </ul>
-</HTML>"));
-  end f_colebrook_2ph;
-
-  function f_dittus_boelter
-    "Dittus-Boelter correlation for one-phase flow in a tube"
-
-    input SI.MassFlowRate w;
-    input SI.Length D;
-    input SI.Area A;
-    input SI.DynamicViscosity mu;
-    input SI.ThermalConductivity k;
-    input SI.SpecificHeatCapacity cp;
-    output SI.CoefficientOfHeatTransfer hTC;
-  protected
-    SI.PerUnit Re;
-    SI.PerUnit Pr;
-  algorithm
-    Re := abs(w)*D/A/mu;
-    Pr := cp*mu/k;
-    hTC := 0.023*k/D*Re^0.8*Pr^0.4;
-    annotation (Documentation(info="<HTML>
+</HTML>"));
+  end f_colebrook_2ph;
+
+  function f_dittus_boelter "Dittus-Boelter correlation for one-phase flow in a tube"
+    input SI.MassFlowRate w;
+    input SI.Length D;
+    input SI.Area A;
+    input SI.DynamicViscosity mu;
+    input SI.ThermalConductivity k;
+    input SI.SpecificHeatCapacity cp;
+    output SI.CoefficientOfHeatTransfer hTC;
+  protected
+    SI.PerUnit Re;
+    SI.PerUnit Pr;
+  algorithm
+    Re := abs(w) * D / A / mu;
+    Pr := cp * mu / k;
+    hTC := 0.023 * k / D * Re ^ 0.8 * Pr ^ 0.4;
+    annotation(
+      Documentation(info = "<HTML>
 <p>Dittus-Boelter's correlation for the computation of the heat transfer coefficient in one-phase flows.
 <p><b>Revision history:</b></p>
 <ul>
@@ -5210,152 +4019,132 @@
     by <a href=\"mailto:francesco.casella@polimi.it\">Francesco Casella</a>:<br>
        First release.</li>
 </ul>
-</HTML>"));
-  end f_dittus_boelter;
-
-  model SteamTurbineStodola
-    "Steam turbine: Stodola's ellipse law and constant isentropic efficiency"
-    extends BaseClasses.SteamTurbineBase;
-    parameter SI.PerUnit eta_iso_nom=0.92 "Nominal isentropic efficiency";
-    parameter SI.Area Kt "Kt coefficient of Stodola's law";
-    Medium.Density rho "Inlet density";
-  equation
-    rho =  Medium.density(steamState_in);
-    w = homotopy(Kt*theta*sqrt(pin*rho)*Functions.sqrtReg(1 - (1/PR)^2),
-                 theta*wnom/pnom*pin) "Stodola's law";
-    eta_iso = eta_iso_nom "Constant efficiency";
-    annotation (Documentation(info="<html>
+</HTML>"));
+  end f_dittus_boelter;
+
+  model SteamTurbineStodola "Steam turbine: Stodola's ellipse law and constant isentropic efficiency"
+    extends BaseClasses.SteamTurbineBase;
+    parameter SI.PerUnit eta_iso_nom = 0.92 "Nominal isentropic efficiency";
+    parameter SI.Area Kt "Kt coefficient of Stodola's law";
+    Medium.Density rho "Inlet density";
+  equation
+    rho = Medium.density(steamState_in);
+    w = homotopy(Kt * theta * sqrt(pin * rho) * Functions.sqrtReg(1 - (1 / PR) ^ 2), theta * wnom / pnom * pin) "Stodola's law";
+    eta_iso = eta_iso_nom "Constant efficiency";
+    annotation(
+      Documentation(info = "<html>
 <p>This model extends <tt>SteamTurbineBase</tt> by adding the actual performance characteristics:
 <ul>
 <li>Stodola's law
 <li>Constant isentropic efficiency
 </ul></p>
 <p>The inlet flowrate is also proportional to the <tt>partialArc</tt> signal if the corresponding connector is wired. In this case, it is assumed that the flow rate is reduced by partial arc admission, not by throttling (i.e., no loss of thermodynamic efficiency occurs). To simulate throttling, insert a valve model before the turbine inlet.
-</html>", revisions="<html>
+</html>", revisions = "<html>
 <ul>
 <li><i>20 Apr 2005</i>
     by <a href=\"mailto:francesco.casella@polimi.it\">Francesco Casella</a>:<br>
        First release.</li>
 </ul>
-</html>"));
-  end SteamTurbineStodola;
-
-  model SteamTurbineUnit "Simplified HP+LP turbine unit for steam flows"
-    replaceable package Medium = StandardWater constrainedby
-      Modelica.Media.Interfaces.PartialMedium "Medium model"
-      annotation(choicesAllMatching = true);
-    extends Icons.Water.SteamTurbineUnit;
-    parameter Medium.AbsolutePressure pnom "Inlet nominal pressure";
-    parameter Medium.MassFlowRate wnom "Inlet nominal flow rate";
-    parameter SI.PerUnit eta_iso "Isentropic efficiency [PerUnit]";
-    parameter SI.PerUnit eta_mech=0.98 "Mechanical efficiency [PerUnit]";
-    parameter SI.PerUnit hpFraction
-      "Fraction of power provided by the HP turbine [PerUnit]";
-    parameter SI.Time T_HP "Time constant of HP mechanical power response";
-    parameter SI.Time T_LP "Time constant of LP mechanical power response";
-    parameter Boolean allowFlowReversal=system.allowFlowReversal
-      "= true to allow flow reversal, false restricts to design direction"
-      annotation(Evaluate=true);
-    outer ThermoPower.System system "System wide properties";
-    parameter SI.MassFlowRate wstart = wnom "Flow rate start value"
-        annotation (Dialog(tab="Initialization"));
-    parameter Medium.AbsolutePressure pstartin=pnom "Inlet start pressure"
-      annotation (Dialog(tab="Initialization"));
-    parameter Medium.SpecificEnthalpy hstartin "Inlet enthalpy start value"
-      annotation (Dialog(tab="Initialization"));
-    parameter Medium.SpecificEnthalpy hstartout "Outlet enthalpy start value"
-      annotation (Dialog(tab="Initialization"));
-    parameter SI.Power P_HPstart = wstart*(hstartin - hstartout)*hpFraction
-      "HP turbine power start value"
-        annotation (Dialog(tab="Initialization"));
-    parameter SI.Power P_LPstart = wstart*(hstartin - hstartout)*(1-hpFraction)
-      "LP turbine power start value"
-        annotation (Dialog(tab="Initialization"));
-    parameter ThermoPower.Choices.Init.Options initOpt=system.initOpt
-      "Initialization option" annotation (Dialog(tab="Initialization"));
-    Medium.ThermodynamicState fluidState_in(p(start=pstartin),h(start=hstartin));
-    FlangeA inlet(redeclare package Medium = Medium, m_flow(min=if
-            allowFlowReversal then -Modelica.Constants.inf else 0)) annotation (
-       Placement(transformation(extent={{-120,50},{-80,90}}, rotation=0)));
-    FlangeB outlet(redeclare package Medium = Medium, m_flow(max=if
-            allowFlowReversal then +Modelica.Constants.inf else 0)) annotation (
-       Placement(transformation(extent={{80,-90},{120,-50}}, rotation=0)));
-    Modelica.Mechanics.Rotational.Interfaces.Flange_a shaft_a annotation (
-        Placement(transformation(extent={{-110,-14},{-84,14}}, rotation=0)));
-    Modelica.Mechanics.Rotational.Interfaces.Flange_b shaft_b annotation (
-        Placement(transformation(extent={{86,-14},{112,14}}, rotation=0)));
-    Medium.MassFlowRate w "Mass flowrate";
-    SI.Angle phi "Shaft rotation angle";
-    SI.AngularVelocity omega "Shaft angular velocity";
-    SI.Torque tau "Net torque acting on the turbine";
-    Real Kv(unit="kg/(s.Pa)") "Turbine nominal admittance at full throttle";
-    Medium.SpecificEnthalpy hin(start=hstartin) "Inlet enthalpy";
-    Medium.SpecificEnthalpy hout(start=hstartout) "Outlet enthalpy";
-    Medium.SpecificEnthalpy hiso(start=hstartout) "Isentropic outlet enthalpy";
-    SI.Power Pm "Mechanical power input";
-    SI.Power P_HP(start = P_HPstart)
-      "Mechanical power produced by the HP turbine";
-    SI.Power P_LP(start = P_LPstart)
-      "Mechanical power produced by the LP turbine";
-    Modelica.Blocks.Interfaces.RealInput partialArc annotation (Placement(
-          transformation(extent={{-110,-88},{-74,-52}}, rotation=0)));
-  equation
-    if cardinality(partialArc) == 0 then
-      partialArc = 1 "Default value if not connected";
-    end if;
-    Kv = partialArc*wnom/pnom "Definition of Kv coefficient";
-    w = Kv*inlet.p "Flow characteristics";
-    hiso = Medium.isentropicEnthalpy(outlet.p, fluidState_in)
-      "Isentropic enthalpy";
-    hin - hout = eta_iso*(hin - hiso) "Computation of outlet enthalpy";
-    Pm = eta_mech*w*(hin - hout) "Mechanical power from the fluid";
-    T_HP*der(P_HP) = Pm*hpFraction - P_HP "Power output to HP turbine";
-    T_LP*der(P_LP) = Pm*(1 - hpFraction) - P_LP "Power output to LP turbine";
-    P_HP + P_LP = -tau*omega "Mechanical power balance";
-
-    // Mechanical boundary conditions
-    shaft_a.phi = phi;
-    shaft_b.phi = phi;
-    shaft_a.tau + shaft_b.tau = tau;
-    der(phi) = omega;
-
-    // Fluid boundary conditions and inlet fluid properties
-    fluidState_in = Medium.setState_phX(inlet.p, hin);
-    hin = inStream(inlet.h_outflow);
-    hout = outlet.h_outflow;
-    w = inlet.m_flow;
-
-    inlet.m_flow + outlet.m_flow = 0 "Mass balance";
-    assert(w >= 0, "The turbine model does not support flow reversal");
-
-    // The next equation is provided to close the balance but never actually used
-    inlet.h_outflow = outlet.h_outflow;
-  initial equation
-    if initOpt == ThermoPower.Choices.Init.Options.noInit then
-      // do nothing
-    elseif initOpt == ThermoPower.Choices.Init.Options.fixedState then
-      P_HP = P_HPstart;
-      P_LP = P_LPstart;
-    elseif initOpt == ThermoPower.Choices.Init.Options.steadyState then
-      der(P_HP) = 0;
-      der(P_LP) = 0;
-    else
-      assert(false, "Unsupported initialisation option");
-    end if;
-
-    annotation (
-      Icon(graphics={Text(extent={{-108,-80},{108,-110}}, textString="%name"),
-            Line(
-            points={{-74,-70},{-74,-70},{-56,-70},{-56,-30}},
-            color={0,0,0},
-            thickness=0.5)}),
-      Documentation(info="<HTML>
+</html>"));
+  end SteamTurbineStodola;
+
+  model SteamTurbineUnit "Simplified HP+LP turbine unit for steam flows"
+    replaceable package Medium = StandardWater constrainedby Modelica.Media.Interfaces.PartialMedium "Medium model" annotation(
+       choicesAllMatching = true);
+    extends Icons.Water.SteamTurbineUnit;
+    parameter Medium.AbsolutePressure pnom "Inlet nominal pressure";
+    parameter Medium.MassFlowRate wnom "Inlet nominal flow rate";
+    parameter SI.PerUnit eta_iso "Isentropic efficiency [PerUnit]";
+    parameter SI.PerUnit eta_mech = 0.98 "Mechanical efficiency [PerUnit]";
+    parameter SI.PerUnit hpFraction "Fraction of power provided by the HP turbine [PerUnit]";
+    parameter SI.Time T_HP "Time constant of HP mechanical power response";
+    parameter SI.Time T_LP "Time constant of LP mechanical power response";
+    parameter Boolean allowFlowReversal = system.allowFlowReversal "= true to allow flow reversal, false restricts to design direction" annotation(
+      Evaluate = true);
+    outer ThermoPower.System system "System wide properties";
+    parameter SI.MassFlowRate wstart = wnom "Flow rate start value" annotation(
+      Dialog(tab = "Initialization"));
+    parameter Medium.AbsolutePressure pstartin = pnom "Inlet start pressure" annotation(
+      Dialog(tab = "Initialization"));
+    parameter Medium.SpecificEnthalpy hstartin "Inlet enthalpy start value" annotation(
+      Dialog(tab = "Initialization"));
+    parameter Medium.SpecificEnthalpy hstartout "Outlet enthalpy start value" annotation(
+      Dialog(tab = "Initialization"));
+    parameter SI.Power P_HPstart = wstart * (hstartin - hstartout) * hpFraction "HP turbine power start value" annotation(
+      Dialog(tab = "Initialization"));
+    parameter SI.Power P_LPstart = wstart * (hstartin - hstartout) * (1 - hpFraction) "LP turbine power start value" annotation(
+      Dialog(tab = "Initialization"));
+    parameter ThermoPower.Choices.Init.Options initOpt = system.initOpt "Initialization option" annotation(
+      Dialog(tab = "Initialization"));
+    Medium.ThermodynamicState fluidState_in(p(start = pstartin), h(start = hstartin));
+    FlangeA inlet(redeclare package Medium = Medium, m_flow(min = if allowFlowReversal then -Modelica.Constants.inf else 0)) annotation(
+      Placement(transformation(extent = {{-120, 50}, {-80, 90}}, rotation = 0)));
+    FlangeB outlet(redeclare package Medium = Medium, m_flow(max = if allowFlowReversal then +Modelica.Constants.inf else 0)) annotation(
+      Placement(transformation(extent = {{80, -90}, {120, -50}}, rotation = 0)));
+    Modelica.Mechanics.Rotational.Interfaces.Flange_a shaft_a annotation(
+      Placement(transformation(extent = {{-110, -14}, {-84, 14}}, rotation = 0)));
+    Modelica.Mechanics.Rotational.Interfaces.Flange_b shaft_b annotation(
+      Placement(transformation(extent = {{86, -14}, {112, 14}}, rotation = 0)));
+    Medium.MassFlowRate w "Mass flowrate";
+    SI.Angle phi "Shaft rotation angle";
+    SI.AngularVelocity omega "Shaft angular velocity";
+    SI.Torque tau "Net torque acting on the turbine";
+    Real Kv(unit = "kg/(s.Pa)") "Turbine nominal admittance at full throttle";
+    Medium.SpecificEnthalpy hin(start = hstartin) "Inlet enthalpy";
+    Medium.SpecificEnthalpy hout(start = hstartout) "Outlet enthalpy";
+    Medium.SpecificEnthalpy hiso(start = hstartout) "Isentropic outlet enthalpy";
+    SI.Power Pm "Mechanical power input";
+    SI.Power P_HP(start = P_HPstart) "Mechanical power produced by the HP turbine";
+    SI.Power P_LP(start = P_LPstart) "Mechanical power produced by the LP turbine";
+    Modelica.Blocks.Interfaces.RealInput partialArc annotation(
+      Placement(transformation(extent = {{-110, -88}, {-74, -52}}, rotation = 0)));
+  equation
+    if cardinality(partialArc) == 0 then
+      partialArc = 1 "Default value if not connected";
+    end if;
+    Kv = partialArc * wnom / pnom "Definition of Kv coefficient";
+    w = Kv * inlet.p "Flow characteristics";
+    hiso = Medium.isentropicEnthalpy(outlet.p, fluidState_in) "Isentropic enthalpy";
+    hin - hout = eta_iso * (hin - hiso) "Computation of outlet enthalpy";
+    Pm = eta_mech * w * (hin - hout) "Mechanical power from the fluid";
+    T_HP * der(P_HP) = Pm * hpFraction - P_HP "Power output to HP turbine";
+    T_LP * der(P_LP) = Pm * (1 - hpFraction) - P_LP "Power output to LP turbine";
+    P_HP + P_LP = -tau * omega "Mechanical power balance";
+// Mechanical boundary conditions
+    shaft_a.phi = phi;
+    shaft_b.phi = phi;
+    shaft_a.tau + shaft_b.tau = tau;
+    der(phi) = omega;
+// Fluid boundary conditions and inlet fluid properties
+    fluidState_in = Medium.setState_phX(inlet.p, hin);
+    hin = inStream(inlet.h_outflow);
+    hout = outlet.h_outflow;
+    w = inlet.m_flow;
+    inlet.m_flow + outlet.m_flow = 0 "Mass balance";
+    assert(w >= 0, "The turbine model does not support flow reversal");
+// The next equation is provided to close the balance but never actually used
+    inlet.h_outflow = outlet.h_outflow;
+  initial equation
+    if initOpt == ThermoPower.Choices.Init.Options.noInit then
+// do nothing
+    elseif initOpt == ThermoPower.Choices.Init.Options.fixedState then
+      P_HP = P_HPstart;
+      P_LP = P_LPstart;
+    elseif initOpt == ThermoPower.Choices.Init.Options.steadyState then
+      der(P_HP) = 0;
+      der(P_LP) = 0;
+    else
+      assert(false, "Unsupported initialisation option");
+    end if;
+    annotation(
+      Icon(graphics = {Text(extent = {{-108, -80}, {108, -110}}, textString = "%name"), Line(points = {{-74, -70}, {-74, -70}, {-56, -70}, {-56, -30}}, color = {0, 0, 0}, thickness = 0.5)}),
+      Documentation(info = "<HTML>
 <p>This model describes a simplified steam turbine unit, with a high pressure and a low pressure turbine.<p>
 The inlet flowrate is proportional to the inlet pressure, and to the <tt>partialArc</tt> signal if the corresponding connector is wired. In this case, it is assumed that the flow rate is reduced by partial arc admission, not by throttling (i.e., no loss of thermodynamic efficiency occurs). To simulate throttling, insert a valve before the turbine unit inlet.
 <p>The model assumes that a fraction <tt>hpFraction</tt> of the available hydraulic power is converted by the HP turbine with a time constant of <tt>T_HP</tt>, while the remaining part is converted by the LP turbine with a time constant of <tt>L_HP</tt>.
 <p>This model does not include any shaft inertia by itself; if that is needed, connect a <tt>Modelica.Mechanics.Rotational.Inertia</tt> model to one of the shaft connectors.
 <p>The model requires the <tt>Modelica.Media</tt> library (<tt>ThermoFluid</tt> does not compute the isentropic enthalpy correctly).
-</HTML>", revisions="<html>
+</HTML>", revisions = "<html>
 <ul>
 <li><i>16 Dec 2004</i>
     by <a href=\"mailto:francesco.casella@polimi.it\">Francesco Casella</a>:<br>
@@ -5364,199 +4153,135 @@
     by <a href=\"mailto:francesco.casella@polimi.it\">Francesco Casella</a>:<br>
        First release.</li>
 </ul>
-</html>"),
-      Diagram(graphics));
-  end SteamTurbineUnit;
-
-  package Utility "Utility models"
-
-    model ClosedSystemInit
-      "Component for the steady-state initialization of closed systems"
-      replaceable package Medium = StandardWater constrainedby
-        Modelica.Media.Interfaces.PartialMedium "Medium model"
-        annotation(choicesAllMatching = true);
-      parameter Medium.AbsolutePressure pstart "Start value of pressure";
-      parameter Boolean initEquationFromInput = false
-        "Get initial condition residual from input connector"
-        annotation(Dialog(group="External inputs"), choices(checkBox=true));
-      parameter Boolean useHomotopy
-        "Use homotopy for residual-based initialization";
-      final parameter Medium.MassFlowRate w_b(fixed = false, start = 0)
-        "Initial balance flow rate eventually equal to zero";
-      outer ThermoPower.System system "System wide properties";
-
-      FlangeB flange(redeclare package Medium = Medium, m_flow(min = 0))
-         annotation (Placement(transformation(extent={{-20,-100},{20,-60}},
-                               rotation=0),
-                               iconTransformation(extent={{-20,-100},{20,-60}})));
-      Modelica.Blocks.Interfaces.RealInput initEquationResidual if initEquationFromInput
-        "Residual of initial equation" annotation (Placement(transformation(extent={
-                {-60,0},{-20,40}}), iconTransformation(extent={{-60,-10},{-40,10}})));
-    protected
-      Modelica.Blocks.Interfaces.RealInput initEquationResidual_int
-        "Hidden internal connector for conditional connection";
-    equation
-      0 = flange.m_flow + w_b "Mass balance";
-      flange.h_outflow = Medium.h_default
-        "Unused value as there is no flow out of the flange";
-
-      connect(initEquationResidual, initEquationResidual_int)
-        "Connects conditional input to hidden connector";
-
-      if not initEquationFromInput then
-        initEquationResidual_int = 0 "Not used";
-      end if;
-
-    initial equation
-      if initEquationFromInput then
-        if useHomotopy then
-          homotopy(initEquationResidual_int, (flange.p - pstart)/pstart) = 0
-            "Set initial value of residual to zero, simplified equation sets start value of pressure";
-        else
-          initEquationResidual_int = 0 "Set initial value of residual to zero";
-        end if;
-      else
-        flange.p = pstart "Set initial value of pressure";
-      end if;
-
-      annotation (Icon(coordinateSystem(preserveAspectRatio=false), graphics={
-            Line(
-              points={{0,0},{0,-60}},
-              color={28,108,200},
-              thickness=0.5),
-            Ellipse(
-              extent={{-40,40},{40,-40}},
-              lineColor={28,108,200},
-              fillColor={0,0,255},
-              fillPattern=FillPattern.Solid),
-            Text(
-              extent={{-32,24},{30,-24}},
-              lineColor={255,255,255},
-              lineThickness=0.5,
-              fillColor={0,0,255},
-              fillPattern=FillPattern.Solid,
-              textString="Init")}),                                  Diagram(
-            coordinateSystem(preserveAspectRatio=false)),
-        Documentation(info="<html>
+</html>"),
+      Diagram(graphics));
+  end SteamTurbineUnit;
+
+  package Utility "Utility models"
+    model ClosedSystemInit "Component for the steady-state initialization of closed systems"
+      replaceable package Medium = StandardWater constrainedby Modelica.Media.Interfaces.PartialMedium "Medium model" annotation(
+         choicesAllMatching = true);
+      parameter Medium.AbsolutePressure pstart "Start value of pressure";
+      parameter Boolean initEquationFromInput = false "Get initial condition residual from input connector" annotation(
+        Dialog(group = "External inputs"),
+        choices(checkBox = true));
+      parameter Boolean useHomotopy "Use homotopy for residual-based initialization";
+      final parameter Medium.MassFlowRate w_b(fixed = false, start = 0) "Initial balance flow rate eventually equal to zero";
+      outer ThermoPower.System system "System wide properties";
+      FlangeB flange(redeclare package Medium = Medium, m_flow(min = 0)) annotation(
+        Placement(transformation(extent = {{-20, -100}, {20, -60}}, rotation = 0), iconTransformation(extent = {{-20, -100}, {20, -60}})));
+      Modelica.Blocks.Interfaces.RealInput initEquationResidual if initEquationFromInput "Residual of initial equation" annotation(
+        Placement(transformation(extent = {{-60, 0}, {-20, 40}}), iconTransformation(extent = {{-60, -10}, {-40, 10}})));
+    protected
+      Modelica.Blocks.Interfaces.RealInput initEquationResidual_int "Hidden internal connector for conditional connection";
+    equation
+      0 = flange.m_flow + w_b "Mass balance";
+      flange.h_outflow = Medium.h_default "Unused value as there is no flow out of the flange";
+      connect(initEquationResidual, initEquationResidual_int) "Connects conditional input to hidden connector";
+      if not initEquationFromInput then
+        initEquationResidual_int = 0 "Not used";
+      end if;
+    initial equation
+      if initEquationFromInput then
+        if useHomotopy then
+          homotopy(initEquationResidual_int, (flange.p - pstart) / pstart) = 0 "Set initial value of residual to zero, simplified equation sets start value of pressure";
+        else
+          initEquationResidual_int = 0 "Set initial value of residual to zero";
+        end if;
+      else
+        flange.p = pstart "Set initial value of pressure";
+      end if;
+      annotation(
+        Icon(coordinateSystem(preserveAspectRatio = false), graphics = {Line(points = {{0, 0}, {0, -60}}, color = {28, 108, 200}, thickness = 0.5), Ellipse(extent = {{-40, 40}, {40, -40}}, lineColor = {28, 108, 200}, fillColor = {0, 0, 255}, fillPattern = FillPattern.Solid), Text(extent = {{-32, 24}, {30, -24}}, lineColor = {255, 255, 255}, lineThickness = 0.5, fillColor = {0, 0, 255}, fillPattern = FillPattern.Solid, textString = "Init")}),
+        Diagram(coordinateSystem(preserveAspectRatio = false)),
+        Documentation(info = "<html>
 <p>This component can be used for the steady-state initialization of closed-system where all components have steady-state initial conditions. Without this component such systems would give rise to undetermined initial conditions, i.e., the amount of fluid and the initial pressures in the system would be unspecified.</p>
 <p>Connect the component to one point of the system. If <code>initEquationFromInput = false</code>, the system is initialized with pressure equal to <code>pstart</code> at the connection point.</p>
 <p>It is possible to use a generic initial equation instead of <code>p = pstart</code>, e.g., to set the initial charge of a refrigeration circuit, by setting <code>initEquationFromInput = true</code> and connecting to the input the output of a <a href=\"Modelica://Modelica.Blocks.Sources.RealExpression\">Modelica.Blocks.Sources.RealExpression</a> component, containing the residual of the initial equation. In this case, if <code>useHomotopy = true</code>, the simplified initial equation is <code>(p - pstart)/pstart = 0</code>. To ensure a smooth homotopy transformation, it is recommended to write the residual in normalized form, i.e., with values have the order of magnitude of one, as for the simplified equation.</p>
-</html>"));
-    end ClosedSystemInit;
-  end Utility;
-
-  package BaseClasses "Contains partial models"
-    extends Modelica.Icons.BasesPackage;
-    partial model Flow1DBase
-      "Basic interface for 1-dimensional water/steam fluid flow models"
-      import ThermoPower.Choices.Flow1D.FFtypes;
-      replaceable package Medium = StandardWater constrainedby
-        Modelica.Media.Interfaces.PartialMedium "Medium model"
-        annotation(choicesAllMatching = true);
-      extends Icons.Water.Tube;
-      constant Real pi = Modelica.Constants.pi;
-      parameter Integer N(min=2) = 2 "Number of nodes for thermal variables";
-      parameter Integer Nw = N - 1 "Number of volumes on the wall interface";
-      parameter Integer Nt = 1 "Number of tubes in parallel";
-      parameter SI.Distance L "Tube length" annotation (Evaluate=true);
-      parameter SI.Position H=0 "Elevation of outlet over inlet";
-      parameter SI.Area A "Cross-sectional area (single tube)";
-      parameter SI.Length omega
-        "Perimeter of heat transfer surface (single tube)";
-      parameter SI.Length Dhyd = omega/pi "Hydraulic Diameter (single tube)";
-      parameter Medium.MassFlowRate wnom "Nominal mass flowrate (total)";
-      parameter ThermoPower.Choices.Flow1D.FFtypes FFtype=ThermoPower.Choices.Flow1D.FFtypes.NoFriction
-        "Friction Factor Type"
-        annotation (Evaluate=true);
-      parameter SI.PressureDifference dpnom = 0
-        "Nominal pressure drop (friction term only!)";
-      parameter Real Kfnom = 0
-        "Nominal hydraulic resistance coefficient (DP = Kfnom*w^2/rho)"
-       annotation(Dialog(enable = (FFtype == ThermoPower.Choices.Flow1D.FFtypes.Kfnom)));
-      parameter Medium.Density rhonom=0 "Nominal inlet density"
-        annotation(Dialog(enable = (FFtype == ThermoPower.Choices.Flow1D.FFtypes.OpPoint)));
-      parameter SI.PerUnit Cfnom=0 "Nominal Fanning friction factor"
-        annotation(Dialog(enable = (FFtype == ThermoPower.Choices.Flow1D.FFtypes.Cfnom)));
-      parameter SI.PerUnit e=0 "Relative roughness (ratio roughness/diameter)"
-        annotation(Dialog(enable = (FFtype == ThermoPower.Choices.Flow1D.FFtypes.Colebrook)));
-      parameter SI.PerUnit Kfc=1 "Friction factor correction coefficient";
-      parameter Boolean DynamicMomentum=false
-        "Inertial phenomena accounted for"
-        annotation (Evaluate=true);
-      parameter ThermoPower.Choices.Flow1D.HCtypes HydraulicCapacitance=ThermoPower.Choices.Flow1D.HCtypes.Downstream
-        "Location of the hydraulic capacitance";
-      parameter Boolean avoidInletEnthalpyDerivative=true
-        "Avoid inlet enthalpy derivative";
-      parameter Boolean allowFlowReversal=system.allowFlowReversal
-        "= true to allow flow reversal, false restricts to design direction"
-      annotation(Evaluate=true);
-      outer ThermoPower.System system "System wide properties";
-      parameter Choices.FluidPhase.FluidPhases FluidPhaseStart=Choices.FluidPhase.FluidPhases.Liquid
-        "Fluid phase (only for initialization!)"
-        annotation (Dialog(tab="Initialisation"));
-      parameter Medium.AbsolutePressure pstart=1e5 "Pressure start value"
-        annotation (Dialog(tab="Initialisation"));
-      parameter Medium.SpecificEnthalpy hstartin=if FluidPhaseStart == Choices.FluidPhase.FluidPhases.Liquid
-           then 1e5 else if FluidPhaseStart == Choices.FluidPhase.FluidPhases.Steam
-           then 3e6 else 1e6 "Inlet enthalpy start value"
-        annotation (Dialog(tab="Initialisation"));
-      parameter Medium.SpecificEnthalpy hstartout=if FluidPhaseStart == Choices.FluidPhase.FluidPhases.Liquid
-           then 1e5 else if FluidPhaseStart == Choices.FluidPhase.FluidPhases.Steam
-           then 3e6 else 1e6 "Outlet enthalpy start value"
-        annotation (Dialog(tab="Initialisation"));
-      parameter Medium.SpecificEnthalpy hstart[N]=linspace(
-              hstartin,
-              hstartout,
-              N) "Start value of enthalpy vector (initialized by default)"
-        annotation (Dialog(tab="Initialisation"));
-      parameter SI.PerUnit wnf=0.02
-        "Fraction of nominal flow rate at which linear friction equals turbulent friction";
-      parameter Choices.Init.Options initOpt=system.initOpt
-        "Initialisation option"
-        annotation (Dialog(tab="Initialisation"));
-      parameter Boolean noInitialPressure=false
-        "Remove initial equation on pressure"
-        annotation (Dialog(tab="Initialisation"),choices(checkBox=true));
-      constant SI.Acceleration g=Modelica.Constants.g_n;
-      function squareReg = ThermoPower.Functions.squareReg;
-
-      FlangeA infl(
-        h_outflow(start=hstartin),
-        redeclare package Medium = Medium,
-        m_flow(start=wnom, min=if allowFlowReversal then -Modelica.Constants.inf
-               else 0)) annotation (Placement(transformation(extent={{-120,-20},
-                {-80,20}}, rotation=0)));
-      FlangeB outfl(
-        h_outflow(start=hstartout),
-        redeclare package Medium = Medium,
-        m_flow(start=-wnom, max=if allowFlowReversal then +Modelica.Constants.inf
-               else 0)) annotation (Placement(transformation(extent={{80,-20},{
-                120,20}}, rotation=0)));
-      SI.Power Q "Total heat flow through the lateral boundary (all Nt tubes)";
-      SI.Time Tr "Residence time";
-      final parameter SI.PerUnit dzdx=H/L "Slope" annotation (Evaluate=true);
-      final parameter SI.Length l=L/(N - 1) "Length of a single volume";
-      final parameter SI.Volume V = Nt*A*L "Total volume (all Nt tubes)";
-    initial equation
-        assert(wnom > 0, "Please set a positive value for wnom");
-        assert(FFtype == FFtypes.NoFriction or dpnom > 0,
-        "dpnom=0 not valid, it is also used in the homotopy trasformation during the inizialization");
-        assert(not
-                  (FFtype == FFtypes.Kfnom     and not Kfnom > 0),  "Kfnom = 0 not valid, please set a positive value");
-        assert(not
-                  (FFtype == FFtypes.OpPoint   and not rhonom > 0), "rhonom = 0 not valid, please set a positive value");
-        assert(not
-                  (FFtype == FFtypes.Cfnom     and not Cfnom > 0),  "Cfnom = 0 not valid, please set a positive value");
-        assert(not
-                  (FFtype == FFtypes.Colebrook and not Dhyd > 0),   "Dhyd = 0 not valid, please set a positive value");
-        assert(not
-                  (FFtype == FFtypes.Colebrook and not e > 0),      "e = 0 not valid, please set a positive value");
-        annotation (Evaluate=true,
-        Documentation(info="<HTML>
+</html>"));
+    end ClosedSystemInit;
+  end Utility;
+
+  package BaseClasses "Contains partial models"
+    extends Modelica.Icons.BasesPackage;
+
+    partial model Flow1DBase "Basic interface for 1-dimensional water/steam fluid flow models"
+      import ThermoPower.Choices.Flow1D.FFtypes;
+      replaceable package Medium = StandardWater constrainedby Modelica.Media.Interfaces.PartialMedium "Medium model" annotation(
+         choicesAllMatching = true);
+      extends Icons.Water.Tube;
+      constant Real pi = Modelica.Constants.pi;
+      parameter Integer N(min = 2) = 2 "Number of nodes for thermal variables";
+      parameter Integer Nw = N - 1 "Number of volumes on the wall interface";
+      parameter Integer Nt = 1 "Number of tubes in parallel";
+      parameter SI.Distance L "Tube length" annotation(
+        Evaluate = true);
+      parameter SI.Position H = 0 "Elevation of outlet over inlet";
+      parameter SI.Area A "Cross-sectional area (single tube)";
+      parameter SI.Length omega "Perimeter of heat transfer surface (single tube)";
+      parameter SI.Length Dhyd = omega / pi "Hydraulic Diameter (single tube)";
+      parameter Medium.MassFlowRate wnom "Nominal mass flowrate (total)";
+      parameter ThermoPower.Choices.Flow1D.FFtypes FFtype = ThermoPower.Choices.Flow1D.FFtypes.NoFriction "Friction Factor Type" annotation(
+        Evaluate = true);
+      parameter SI.PressureDifference dpnom = 0 "Nominal pressure drop (friction term only!)";
+      parameter Real Kfnom = 0 "Nominal hydraulic resistance coefficient (DP = Kfnom*w^2/rho)" annotation(
+        Dialog(enable = FFtype == ThermoPower.Choices.Flow1D.FFtypes.Kfnom));
+      parameter Medium.Density rhonom = 0 "Nominal inlet density" annotation(
+        Dialog(enable = FFtype == ThermoPower.Choices.Flow1D.FFtypes.OpPoint));
+      parameter SI.PerUnit Cfnom = 0 "Nominal Fanning friction factor" annotation(
+        Dialog(enable = FFtype == ThermoPower.Choices.Flow1D.FFtypes.Cfnom));
+      parameter SI.PerUnit e = 0 "Relative roughness (ratio roughness/diameter)" annotation(
+        Dialog(enable = FFtype == ThermoPower.Choices.Flow1D.FFtypes.Colebrook));
+      parameter SI.PerUnit Kfc = 1 "Friction factor correction coefficient";
+      parameter Boolean DynamicMomentum = false "Inertial phenomena accounted for" annotation(
+        Evaluate = true);
+      parameter ThermoPower.Choices.Flow1D.HCtypes HydraulicCapacitance = ThermoPower.Choices.Flow1D.HCtypes.Downstream "Location of the hydraulic capacitance";
+      parameter Boolean avoidInletEnthalpyDerivative = true "Avoid inlet enthalpy derivative";
+      parameter Boolean allowFlowReversal = system.allowFlowReversal "= true to allow flow reversal, false restricts to design direction" annotation(
+        Evaluate = true);
+      outer ThermoPower.System system "System wide properties";
+      parameter Choices.FluidPhase.FluidPhases FluidPhaseStart = Choices.FluidPhase.FluidPhases.Liquid "Fluid phase (only for initialization!)" annotation(
+        Dialog(tab = "Initialisation"));
+      parameter Medium.AbsolutePressure pstart = 1e5 "Pressure start value" annotation(
+        Dialog(tab = "Initialisation"));
+      parameter Medium.SpecificEnthalpy hstartin = if FluidPhaseStart == Choices.FluidPhase.FluidPhases.Liquid then 1e5 else if FluidPhaseStart == Choices.FluidPhase.FluidPhases.Steam then 3e6 else 1e6 "Inlet enthalpy start value" annotation(
+        Dialog(tab = "Initialisation"));
+      parameter Medium.SpecificEnthalpy hstartout = if FluidPhaseStart == Choices.FluidPhase.FluidPhases.Liquid then 1e5 else if FluidPhaseStart == Choices.FluidPhase.FluidPhases.Steam then 3e6 else 1e6 "Outlet enthalpy start value" annotation(
+        Dialog(tab = "Initialisation"));
+      parameter Medium.SpecificEnthalpy hstart[N] = linspace(hstartin, hstartout, N) "Start value of enthalpy vector (initialized by default)" annotation(
+        Dialog(tab = "Initialisation"));
+      parameter SI.PerUnit wnf = 0.02 "Fraction of nominal flow rate at which linear friction equals turbulent friction";
+      parameter Choices.Init.Options initOpt = system.initOpt "Initialisation option" annotation(
+        Dialog(tab = "Initialisation"));
+      parameter Boolean noInitialPressure = false "Remove initial equation on pressure" annotation(
+        Dialog(tab = "Initialisation"),
+        choices(checkBox = true));
+      constant SI.Acceleration g = Modelica.Constants.g_n;
+      function squareReg = ThermoPower.Functions.squareReg;
+      FlangeA infl(h_outflow(start = hstartin), redeclare package Medium = Medium, m_flow(start = wnom, min = if allowFlowReversal then -Modelica.Constants.inf else 0)) annotation(
+        Placement(transformation(extent = {{-120, -20}, {-80, 20}}, rotation = 0)));
+      FlangeB outfl(h_outflow(start = hstartout), redeclare package Medium = Medium, m_flow(start = -wnom, max = if allowFlowReversal then +Modelica.Constants.inf else 0)) annotation(
+        Placement(transformation(extent = {{80, -20}, {120, 20}}, rotation = 0)));
+      SI.Power Q "Total heat flow through the lateral boundary (all Nt tubes)";
+      SI.Time Tr "Residence time";
+      final parameter SI.PerUnit dzdx = H / L "Slope" annotation(
+        Evaluate = true);
+      final parameter SI.Length l = L / (N - 1) "Length of a single volume";
+      final parameter SI.Volume V = Nt * A * L "Total volume (all Nt tubes)";
+    initial equation
+      assert(wnom > 0, "Please set a positive value for wnom");
+      assert(FFtype == FFtypes.NoFriction or dpnom > 0, "dpnom=0 not valid, it is also used in the homotopy trasformation during the inizialization");
+      assert(not (FFtype == FFtypes.Kfnom and not Kfnom > 0), "Kfnom = 0 not valid, please set a positive value");
+      assert(not (FFtype == FFtypes.OpPoint and not rhonom > 0), "rhonom = 0 not valid, please set a positive value");
+      assert(not (FFtype == FFtypes.Cfnom and not Cfnom > 0), "Cfnom = 0 not valid, please set a positive value");
+      assert(not (FFtype == FFtypes.Colebrook and not Dhyd > 0), "Dhyd = 0 not valid, please set a positive value");
+      assert(not (FFtype == FFtypes.Colebrook and not e > 0), "e = 0 not valid, please set a positive value");
+      annotation(
+        Evaluate = true,
+        Documentation(info = "<HTML>
 Basic interface of the <tt>Flow1D</tt> models, containing the common parameters and connectors.
 </HTML>
-",     revisions=
-             "<html>
+        ", revisions = "<html>
 <ul>
 <li><i>23 Jul 2007</i>
     by <a href=\"mailto:francesco.casella@polimi.it\">Francesco Casella</a>:<br>
@@ -5574,134 +4299,102 @@
     by <a href=\"mailto:francesco.casella@polimi.it\">Francesco Casella</a>:<br>
        Created.</li>
 </ul>
-</html>"),
-        Diagram(graphics),
-        Icon(graphics));
-    end Flow1DBase;
-
-    partial model ValveBase "Base model for valves"
-      extends Icons.Water.Valve;
-      replaceable package Medium = StandardWater constrainedby
-        Modelica.Media.Interfaces.PartialMedium "Medium model"
-        annotation(choicesAllMatching = true);
-      Medium.ThermodynamicState fluidState;
-      parameter ThermoPower.Choices.Valve.CvTypes CvData=ThermoPower.Choices.Valve.CvTypes.Av
-        "Selection of flow coefficient"
-       annotation (Dialog(group="Flow Coefficient"),
-                   Evaluate = true);
-      final parameter Boolean fixedAv=
-        (if CvData == ThermoPower.Choices.Valve.CvTypes.Av then true else false)
-        annotation(Evaluate = true);
-      parameter SI.Area Av(
-        fixed=fixedAv,
-        start=wnom/(sqrt(rhonom*dpnom)*FlowChar(thetanom)))
-        "Av (metric) flow coefficient"
-        annotation (Dialog(group="Flow Coefficient",
-                           enable=(CvData == ThermoPower.Choices.Valve.CvTypes.Av)));
-      parameter Real Kv(unit="m3/h") = 0 "Kv (metric) flow coefficient"
-        annotation (Dialog(group="Flow Coefficient",
-                           enable=(CvData == ThermoPower.Choices.Valve.CvTypes.Kv)));
-      parameter Real Cv=0 "Cv (US) flow coefficient [USG/min]"
-        annotation (Dialog(group="Flow Coefficient",
-                           enable=(CvData == ThermoPower.Choices.Valve.CvTypes.Cv)));
-      parameter Boolean useThetaInput = true
-        "Use the input connector for the valve opening"
-        annotation(Dialog(group = "Valve Opening"), choices(checkBox = true));
-      parameter SI.PerUnit theta_fix = 1
-        "Fixed opening value when the input connector not used"
-        annotation(Dialog(group= "Valve Opening", enable = not useThetaInput));
-      parameter Medium.AbsolutePressure pnom "Nominal inlet pressure"
-        annotation (Dialog(group="Nominal operating point"));
-      parameter SI.PressureDifference dpnom "Nominal pressure drop"
-        annotation (Dialog(group="Nominal operating point"));
-      parameter Medium.MassFlowRate wnom "Nominal mass flowrate"
-        annotation (Dialog(group="Nominal operating point"));
-      parameter Medium.Density rhonom=1000 "Nominal density"
-        annotation (Dialog(group="Nominal operating point",
-                           enable=(CvData == ThermoPower.Choices.Valve.CvTypes.OpPoint)));
-      parameter SI.PerUnit thetanom=1 "Nominal valve opening"
-        annotation (Dialog(group="Nominal operating point"));
-      parameter SI.Power Qnom=0 "Nominal heat loss to ambient"
-        annotation (Dialog(group="Nominal operating point"), Evaluate=true);
-      parameter Boolean CheckValve=false "Reverse flow stopped";
-      parameter Real b=0.01 "Regularisation factor";
-      replaceable function FlowChar =
-          ThermoPower.Functions.ValveCharacteristics.linear
-        constrainedby ThermoPower.Functions.ValveCharacteristics.baseFun
-        "Flow characteristic"
-        annotation (choicesAllMatching=true);
-      parameter Boolean allowFlowReversal=system.allowFlowReversal
-        "= true to allow flow reversal, false restricts to design direction"
-      annotation(Evaluate=true);
-      outer ThermoPower.System system "System wide properties";
-      parameter Medium.AbsolutePressure pin_start=pnom
-        "Inlet pressure start value"
-        annotation (Dialog(tab="Initialisation"));
-      parameter Medium.AbsolutePressure pout_start=pnom - dpnom
-        "Inlet pressure start value"
-        annotation (Dialog(tab="Initialisation"));
-      Medium.MassFlowRate w "Mass flow rate";
-      Units.LiquidDensity rho "Inlet density";
-      Medium.Temperature Tin;
-      SI.PressureDifference dp "Pressure drop across the valve";
-      SI.PerUnit theta_act "Actual valve opening";
-    protected
-      function sqrtR = Functions.sqrtReg (delta=b*dpnom);
-    public
-      FlangeA inlet(
-        m_flow(start=wnom, min=if allowFlowReversal then -Modelica.Constants.inf
-               else 0),
-        p(start=pin_start),
-        redeclare package Medium = Medium) annotation (Placement(transformation(
-              extent={{-120,-20},{-80,20}}, rotation=0)));
-      FlangeB outlet(
-        m_flow(start=-wnom, max=if allowFlowReversal then +Modelica.Constants.inf
-               else 0),
-        p(start=pout_start),
-        redeclare package Medium = Medium) annotation (Placement(transformation(
-              extent={{80,-20},{120,20}}, rotation=0)));
-      Modelica.Blocks.Interfaces.RealInput theta if useThetaInput
-        "Valve opening in per unit"
-        annotation (Placement(transformation(
-            origin={0,80},
-            extent={{-20,-20},{20,20}},
-            rotation=270)));
-    protected
-      Modelica.Blocks.Interfaces.RealInput theta_int
-        "Protected connector for conditional input connector handling";
-
-    initial equation
-      if CvData == ThermoPower.Choices.Valve.CvTypes.Kv then
-        Av = 2.7778e-5*Kv;
-      elseif CvData == ThermoPower.Choices.Valve.CvTypes.Cv then
-        Av = 2.4027e-5*Cv;
-      end if;
-      // assert(CvData>=0 and CvData<=3, "Invalid CvData");
-    equation
-      inlet.m_flow + outlet.m_flow = 0 "Mass balance";
-      w = inlet.m_flow;
-
-      // Fluid properties
-      fluidState = Medium.setState_phX(inlet.p, inStream(inlet.h_outflow));
-      Tin = Medium.temperature(fluidState);
-      rho = Medium.density(fluidState);
-
-      // Energy balance
-      outlet.h_outflow = inStream(inlet.h_outflow) - Qnom/wnom;
-      inlet.h_outflow = inStream(outlet.h_outflow) - Qnom/wnom;
-
-      dp = inlet.p - outlet.p "Definition of dp";
-
-      // Valve opening
-      connect(theta, theta_int); // automatically removed if theta is disabled
-      if not useThetaInput then
-        theta_int = theta_fix;   // provide actual opening value from parameter
-      end if;
-      theta_act = theta_int;
-      annotation (
-        Icon(graphics={Text(extent={{-100,-40},{100,-80}}, textString="%name")}),
-        Diagram(graphics),
-        Documentation(info="<HTML>
+</html>"),
+        Diagram(graphics),
+        Icon(graphics));
+    end Flow1DBase;
+
+    partial model ValveBase "Base model for valves"
+      extends Icons.Water.Valve;
+      replaceable package Medium = StandardWater constrainedby Modelica.Media.Interfaces.PartialMedium "Medium model" annotation(
+         choicesAllMatching = true);
+      Medium.ThermodynamicState fluidState;
+      parameter ThermoPower.Choices.Valve.CvTypes CvData = ThermoPower.Choices.Valve.CvTypes.Av "Selection of flow coefficient" annotation(
+        Dialog(group = "Flow Coefficient"),
+        Evaluate = true);
+      final parameter Boolean fixedAv = if CvData == ThermoPower.Choices.Valve.CvTypes.Av then true else false annotation(
+        Evaluate = true);
+      parameter SI.Area Av(fixed = fixedAv, start = wnom / (sqrt(rhonom * dpnom) * FlowChar(thetanom))) "Av (metric) flow coefficient" annotation(
+        Dialog(group = "Flow Coefficient", enable = CvData == ThermoPower.Choices.Valve.CvTypes.Av));
+      parameter Real Kv(unit = "m3/h") = 0 "Kv (metric) flow coefficient" annotation(
+        Dialog(group = "Flow Coefficient", enable = CvData == ThermoPower.Choices.Valve.CvTypes.Kv));
+      parameter Real Cv = 0 "Cv (US) flow coefficient [USG/min]" annotation(
+        Dialog(group = "Flow Coefficient", enable = CvData == ThermoPower.Choices.Valve.CvTypes.Cv));
+      parameter Boolean useThetaInput = true "Use the input connector for the valve opening" annotation(
+        Dialog(group = "Valve Opening"),
+        choices(checkBox = true));
+      parameter SI.PerUnit theta_fix = 1 "Fixed opening value when the input connector not used" annotation(
+        Dialog(group = "Valve Opening", enable = not useThetaInput));
+      parameter Medium.AbsolutePressure pnom "Nominal inlet pressure" annotation(
+        Dialog(group = "Nominal operating point"));
+      parameter SI.PressureDifference dpnom "Nominal pressure drop" annotation(
+        Dialog(group = "Nominal operating point"));
+      parameter Medium.MassFlowRate wnom "Nominal mass flowrate" annotation(
+        Dialog(group = "Nominal operating point"));
+      parameter Medium.Density rhonom = 1000 "Nominal density" annotation(
+        Dialog(group = "Nominal operating point", enable = CvData == ThermoPower.Choices.Valve.CvTypes.OpPoint));
+      parameter SI.PerUnit thetanom = 1 "Nominal valve opening" annotation(
+        Dialog(group = "Nominal operating point"));
+      parameter SI.Power Qnom = 0 "Nominal heat loss to ambient" annotation(
+        Dialog(group = "Nominal operating point"),
+        Evaluate = true);
+      parameter Boolean CheckValve = false "Reverse flow stopped";
+      parameter Real b = 0.01 "Regularisation factor";
+      replaceable function FlowChar = ThermoPower.Functions.ValveCharacteristics.linear constrainedby ThermoPower.Functions.ValveCharacteristics.baseFun "Flow characteristic" annotation(
+         choicesAllMatching = true);
+      parameter Boolean allowFlowReversal = system.allowFlowReversal "= true to allow flow reversal, false restricts to design direction" annotation(
+        Evaluate = true);
+      outer ThermoPower.System system "System wide properties";
+      parameter Medium.AbsolutePressure pin_start = pnom "Inlet pressure start value" annotation(
+        Dialog(tab = "Initialisation"));
+      parameter Medium.AbsolutePressure pout_start = pnom - dpnom "Inlet pressure start value" annotation(
+        Dialog(tab = "Initialisation"));
+      Medium.MassFlowRate w "Mass flow rate";
+      Units.LiquidDensity rho "Inlet density";
+      Medium.Temperature Tin;
+      SI.PressureDifference dp "Pressure drop across the valve";
+      SI.PerUnit theta_act "Actual valve opening";
+    protected
+      function sqrtR = Functions.sqrtReg(delta = b * dpnom);
+    public
+      FlangeA inlet(m_flow(start = wnom, min = if allowFlowReversal then -Modelica.Constants.inf else 0), p(start = pin_start), redeclare package Medium = Medium) annotation(
+        Placement(transformation(extent = {{-120, -20}, {-80, 20}}, rotation = 0)));
+      FlangeB outlet(m_flow(start = -wnom, max = if allowFlowReversal then +Modelica.Constants.inf else 0), p(start = pout_start), redeclare package Medium = Medium) annotation(
+        Placement(transformation(extent = {{80, -20}, {120, 20}}, rotation = 0)));
+      Modelica.Blocks.Interfaces.RealInput theta if useThetaInput "Valve opening in per unit" annotation(
+        Placement(transformation(origin = {0, 80}, extent = {{-20, -20}, {20, 20}}, rotation = 270)));
+    protected
+      Modelica.Blocks.Interfaces.RealInput theta_int "Protected connector for conditional input connector handling";
+    initial equation
+      if CvData == ThermoPower.Choices.Valve.CvTypes.Kv then
+        Av = 2.7778e-5 * Kv;
+      elseif CvData == ThermoPower.Choices.Valve.CvTypes.Cv then
+        Av = 2.4027e-5 * Cv;
+      end if;
+// assert(CvData>=0 and CvData<=3, "Invalid CvData");
+    equation
+      inlet.m_flow + outlet.m_flow = 0 "Mass balance";
+      w = inlet.m_flow;
+// Fluid properties
+      fluidState = Medium.setState_phX(inlet.p, inStream(inlet.h_outflow));
+      Tin = Medium.temperature(fluidState);
+      rho = Medium.density(fluidState);
+// Energy balance
+      outlet.h_outflow = inStream(inlet.h_outflow) - Qnom / wnom;
+      inlet.h_outflow = inStream(outlet.h_outflow) - Qnom / wnom;
+      dp = inlet.p - outlet.p "Definition of dp";
+// Valve opening
+      connect(theta, theta_int);
+// automatically removed if theta is disabled
+      if not useThetaInput then
+        theta_int = theta_fix;
+// provide actual opening value from parameter
+      end if;
+      theta_act = theta_int;
+      annotation(
+        Icon(graphics = {Text(extent = {{-100, -40}, {100, -80}}, textString = "%name")}),
+        Diagram(graphics),
+        Documentation(info = "<HTML>
 <p>This is the base model for the <tt>ValveLiq</tt>, <tt>ValveLiqChoked</tt>, and <tt>ValveVap</tt> valve models. The model is based on the IEC 534 / ISA S.75 standards for valve sizing.
 <p>The model optionally supports reverse flow conditions (assuming symmetrical behaviour) or check valve operation, and has been suitably modified to avoid numerical singularities at zero pressure drop.</p>
 <p>An optional heat loss to the ambient can be included, proportional to the mass flow rate; <tt>Qnom</tt> specifies the heat loss at nominal flow rate.</p>
@@ -5715,7 +4408,7 @@
 <p>The nominal pressure drop <tt>dpnom</tt> must always be specified; to avoid numerical singularities, the flow characteristic is modified for pressure drops less than <tt>b*dpnom</tt> (the default value is 1% of the nominal pressure drop). Increase this parameter if numerical instabilities occur in valves with very low pressure drops.
 <p>If <tt>CheckValve</tt> is true, then the flow is stopped when the outlet pressure is higher than the inlet pressure; otherwise, reverse flow takes place.
 <p>The default flow characteristic <tt>FlowChar</tt> is linear; it can be replaced by functions taken from <tt>Functions.ValveCharacteristics</tt>, or by any suitable user-defined function extending <tt>Functions.ValveCharacteristics.baseFun</tt>.
-</HTML>", revisions="<html>
+</HTML>", revisions = "<html>
 <ul>
 <li><i>17 Jul 2012</i>
     by <a href=\"mailto:francesco.casella@polimi.it\">Francesco Casella</a>:<br>
@@ -5744,201 +4437,152 @@
     by <a href=\"mailto:francesco.casella@polimi.it\">Francesco Casella</a>:<br>
        First release.</li>
 </ul>
-</html>"));
-    end ValveBase;
-
-    partial model PumpBase "Base model for centrifugal pumps"
-      extends Icons.Water.Pump;
-      replaceable package Medium = StandardWater constrainedby
-        Modelica.Media.Interfaces.PartialMedium "Medium model"
-        annotation(choicesAllMatching = true);
-      Medium.ThermodynamicState inletFluidState
-        "Thermodynamic state of the fluid at the inlet";
-      replaceable function flowCharacteristic =
-          ThermoPower.Functions.PumpCharacteristics.baseFlow
-        "Head vs. q_flow characteristic at nominal speed and density"
-        annotation (Dialog(group="Characteristics"),choicesAllMatching=true);
-      parameter Boolean usePowerCharacteristic=false
-        "Use powerCharacteristic (vs. efficiencyCharacteristic)"
-        annotation (Dialog(group="Characteristics"));
-      replaceable function powerCharacteristic =
-          Functions.PumpCharacteristics.constantPower constrainedby
-        ThermoPower.Functions.PumpCharacteristics.basePower
-        "Power consumption vs. q_flow at nominal speed and density" annotation (
-         Dialog(group="Characteristics", enable=usePowerCharacteristic),
-          choicesAllMatching=true);
-      replaceable function efficiencyCharacteristic =
-          Functions.PumpCharacteristics.constantEfficiency (eta_nom=0.8)
-        constrainedby ThermoPower.Functions.PumpCharacteristics.baseEfficiency
-        "Efficiency vs. q_flow at nominal speed and density" annotation (Dialog(
-            group="Characteristics", enable=not usePowerCharacteristic),
-          choicesAllMatching=true);
-      parameter Integer Np0(min=1) = 1 "Nominal number of pumps in parallel";
-      parameter Boolean use_in_Np = false
-        "Use connector input for the pressure"
-        annotation(Dialog(group="External inputs"), choices(checkBox=true));
-      parameter Units.LiquidDensity rho0=1000 "Nominal Liquid Density"
-        annotation (Dialog(group="Characteristics"));
-      parameter NonSI.AngularVelocity_rpm n0 "Nominal rotational speed"
-        annotation (Dialog(group="Characteristics"));
-      parameter SI.Volume V=0 "Pump Internal Volume" annotation (Evaluate=true);
-      parameter Boolean CheckValve=false "Reverse flow stopped";
-      parameter Boolean allowFlowReversal=system.allowFlowReversal
-        "= true to allow flow reversal, false restricts to design direction"
-      annotation(Evaluate=true);
-      outer ThermoPower.System system "System wide properties";
-      parameter Medium.MassFlowRate wstart=w0 "Mass Flow Rate Start Value"
-        annotation (Dialog(tab="Initialisation"));
-      parameter Medium.SpecificEnthalpy hstart=1e5
-        "Specific Enthalpy Start Value"
-        annotation (Dialog(tab="Initialisation"));
-      parameter Choices.Init.Options initOpt=system.initOpt
-        "Initialisation option"
-        annotation (Dialog(tab="Initialisation"));
-      parameter Boolean noInitialPressure=false
-        "Remove initial equation on pressure"
-        annotation (Dialog(tab="Initialisation"),choices(checkBox=true));
-      constant SI.Acceleration g=Modelica.Constants.g_n;
-      parameter Medium.MassFlowRate w0 "Nominal mass flow rate"
-        annotation (Dialog(group="Characteristics"));
-      parameter SI.Pressure dp0 "Nominal pressure increase"
-        annotation (Dialog(group="Characteristics"));
-      final parameter SI.VolumeFlowRate q_single0=w0/(Np0*rho0)
-        "Nominal volume flow rate (single pump)"
-        annotation(Evaluate = true);
-      final parameter SI.Height head0=dp0/(rho0*g) "Nominal pump head"
-        annotation(Evaluate = true);
-      final parameter Real d_head_dq_0=
-        (flowCharacteristic(q_single0*1.05) - flowCharacteristic(q_single0*0.95))/
-        (q_single0*0.1)
-        "Approximate derivative of flow characteristic w.r.t. volume flow"
-        annotation(Evaluate = true);
-      final parameter Real d_head_dn_0 = 2/n0*head0 - q_single0/n0*d_head_dq_0
-        "Approximate derivative of the flow characteristic w.r.t. rotational speed"
-        annotation(Evaluate = true);
-
-      Medium.MassFlowRate w_single(start=wstart/Np0)
-        "Mass flow rate (single pump)";
-      Medium.MassFlowRate w=Np*w_single "Mass flow rate (total)";
-      SI.VolumeFlowRate q_single(start=wstart/(Np0*rho0))
-        "Volume flow rate (single pump)";
-      SI.VolumeFlowRate q=Np*q_single "Volume flow rate (total)";
-      SI.PressureDifference dp "Outlet pressure minus inlet pressure";
-      SI.Height head "Pump head";
-      Medium.SpecificEnthalpy h(start=hstart) "Fluid specific enthalpy";
-      Medium.SpecificEnthalpy hin "Enthalpy of entering fluid";
-      Medium.SpecificEnthalpy hout "Enthalpy of outgoing fluid";
-      Units.LiquidDensity rho "Liquid density";
-      Medium.Temperature Tin "Liquid inlet temperature";
-      NonSI.AngularVelocity_rpm n "Shaft r.p.m.";
-      Integer Np(min=1) "Number of pumps in parallel";
-      SI.Power W_single "Power Consumption (single pump)";
-      SI.Power W=Np*W_single "Power Consumption (total)";
-      SI.Power Qloss = 0 "Heat loss (single pump)";
-      constant SI.Power W_eps=1e-8
-        "Small coefficient to avoid numerical singularities";
-      constant NonSI.AngularVelocity_rpm n_eps=1e-6;
-      SI.PerUnit eta "Pump efficiency";
-      SI.PerUnit s(start = 1) "Auxiliary non-dimensional variable";
-      FlangeA infl(redeclare package Medium = Medium, m_flow(min=if
-              allowFlowReversal then -Modelica.Constants.inf else 0))
-        annotation (Placement(transformation(extent={{-100,0},{-60,40}},
-              rotation=0)));
-      FlangeB outfl(redeclare package Medium = Medium, m_flow(max=if
-              allowFlowReversal then +Modelica.Constants.inf else 0))
-        annotation (Placement(transformation(extent={{40,50},{80,90}}, rotation=
-               0)));
-      Modelica.Blocks.Interfaces.IntegerInput in_Np if use_in_Np
-        "Number of  parallel pumps"
-        annotation (Placement(transformation(
-            origin={28,80},
-            extent={{-10,-10},{10,10}},
-            rotation=270)));
-    protected
-      Modelica.Blocks.Interfaces.IntegerInput int_Np
-        "Internal connector with number of parallel pumps";
-
-    equation
-      // Flow equations
-      q_single = w_single/homotopy(rho, rho0);
-      head = dp/(homotopy(rho, rho0)*g);
-      if noEvent(s > 0 or (not CheckValve)) then
-        // Flow characteristics when check valve is open
-        q_single = s*q_single0;
-        head = homotopy((n/n0)^2*flowCharacteristic(q_single*n0/(n + n_eps)),
-                         head0 + d_head_dq_0*(q_single - q_single0) +
-                                 d_head_dn_0*(n - n0));
-      else
-        // Flow characteristics when check valve is closed
-        head = homotopy((n/n0)^2*flowCharacteristic(0) - s*head0,
-                         head0 + d_head_dq_0*(q_single - q_single0) +
-                                 d_head_dn_0*(n - n0));
-        q_single = 0;
-      end if;
-
-      // Power consumption
-      if usePowerCharacteristic then
-        W_single = (n/n0)^3*(rho/rho0)*
-                    powerCharacteristic(q_single*n0/(n + n_eps))
-          "Power consumption (single pump)";
-        eta = (dp*q_single)/(W_single + W_eps) "Hydraulic efficiency";
-      else
-        eta = efficiencyCharacteristic(q_single*n0/(n + n_eps));
-        W_single = dp*q_single/eta;
-      end if;
-
-      // Fluid properties
-      inletFluidState = Medium.setState_phX(infl.p, hin);
-      rho = Medium.density(inletFluidState);
-      Tin = Medium.temperature(inletFluidState);
-
-      // Boundary conditions
-      dp = outfl.p - infl.p;
-      w = infl.m_flow "Pump total flow rate";
-      hin = homotopy(if not allowFlowReversal then inStream(infl.h_outflow)
-                     else if w >= 0 then inStream(infl.h_outflow)
-                     else inStream(outfl.h_outflow),
-                     inStream(infl.h_outflow));
-      infl.h_outflow = hout;
-      outfl.h_outflow = hout;
-      h = hout;
-
-      // Mass and energy balances
-      infl.m_flow + outfl.m_flow = 0 "Mass balance";
-      if V > 0 then
-        (rho*V*der(h)) = (outfl.m_flow/Np)*hout + (infl.m_flow/Np)*hin +
-          W_single - Qloss "Energy balance";
-      else
-        0 = (outfl.m_flow/Np)*hout + (infl.m_flow/Np)*hin + W_single - Qloss
-          "Energy balance";
-      end if;
-
-      // Number of pumps in parallel
-      connect(in_Np, int_Np);
-      if not use_in_Np then
-        int_Np = Np0;
-      end if;
-      Np = int_Np;
-
-    initial equation
-      if initOpt == Choices.Init.Options.noInit then
-        // do nothing
-      elseif initOpt == Choices.Init.Options.fixedState then
-        if V > 0 then
-          h = hstart;
-        end if;
-      elseif initOpt == Choices.Init.Options.steadyState then
-        if V > 0 then
-          der(h) = 0;
-        end if;
-      else
-        assert(false, "Unsupported initialisation option");
-      end if;
-
-      annotation (
-        Icon(graphics),
-        Diagram(graphics),
-        Documentation(info="<HTML>
+</html>"));
+    end ValveBase;
+
+    partial model PumpBase "Base model for centrifugal pumps"
+      extends Icons.Water.Pump;
+      replaceable package Medium = StandardWater constrainedby Modelica.Media.Interfaces.PartialMedium "Medium model" annotation(
+         choicesAllMatching = true);
+      Medium.ThermodynamicState inletFluidState "Thermodynamic state of the fluid at the inlet";
+      replaceable function flowCharacteristic = ThermoPower.Functions.PumpCharacteristics.baseFlow "Head vs. q_flow characteristic at nominal speed and density" annotation(
+        Dialog(group = "Characteristics"),
+        choicesAllMatching = true);
+      parameter Boolean usePowerCharacteristic = false "Use powerCharacteristic (vs. efficiencyCharacteristic)" annotation(
+        Dialog(group = "Characteristics"));
+      replaceable function powerCharacteristic = Functions.PumpCharacteristics.constantPower constrainedby ThermoPower.Functions.PumpCharacteristics.basePower "Power consumption vs. q_flow at nominal speed and density" annotation(
+         Dialog(group = "Characteristics", enable = usePowerCharacteristic),
+         choicesAllMatching = true);
+      replaceable function efficiencyCharacteristic = Functions.PumpCharacteristics.constantEfficiency(eta_nom = 0.8) constrainedby ThermoPower.Functions.PumpCharacteristics.baseEfficiency "Efficiency vs. q_flow at nominal speed and density" annotation(
+         Dialog(group = "Characteristics", enable = not usePowerCharacteristic),
+         choicesAllMatching = true);
+      parameter Integer Np0(min = 1) = 1 "Nominal number of pumps in parallel";
+      parameter Boolean use_in_Np = false "Use connector input for the pressure" annotation(
+        Dialog(group = "External inputs"),
+        choices(checkBox = true));
+      parameter Units.LiquidDensity rho0 = 1000 "Nominal Liquid Density" annotation(
+        Dialog(group = "Characteristics"));
+      parameter NonSI.AngularVelocity_rpm n0 "Nominal rotational speed" annotation(
+        Dialog(group = "Characteristics"));
+      parameter SI.Volume V = 0 "Pump Internal Volume" annotation(
+        Evaluate = true);
+      parameter Boolean CheckValve = false "Reverse flow stopped";
+      parameter Boolean allowFlowReversal = system.allowFlowReversal "= true to allow flow reversal, false restricts to design direction" annotation(
+        Evaluate = true);
+      outer ThermoPower.System system "System wide properties";
+      parameter Medium.MassFlowRate wstart = w0 "Mass Flow Rate Start Value" annotation(
+        Dialog(tab = "Initialisation"));
+      parameter Medium.SpecificEnthalpy hstart = 1e5 "Specific Enthalpy Start Value" annotation(
+        Dialog(tab = "Initialisation"));
+      parameter Choices.Init.Options initOpt = system.initOpt "Initialisation option" annotation(
+        Dialog(tab = "Initialisation"));
+      parameter Boolean noInitialPressure = false "Remove initial equation on pressure" annotation(
+        Dialog(tab = "Initialisation"),
+        choices(checkBox = true));
+      constant SI.Acceleration g = Modelica.Constants.g_n;
+      parameter Medium.MassFlowRate w0 "Nominal mass flow rate" annotation(
+        Dialog(group = "Characteristics"));
+      parameter SI.Pressure dp0 "Nominal pressure increase" annotation(
+        Dialog(group = "Characteristics"));
+      final parameter SI.VolumeFlowRate q_single0 = w0 / (Np0 * rho0) "Nominal volume flow rate (single pump)" annotation(
+        Evaluate = true);
+      final parameter SI.Height head0 = dp0 / (rho0 * g) "Nominal pump head" annotation(
+        Evaluate = true);
+      final parameter Real d_head_dq_0 = (flowCharacteristic(q_single0 * 1.05) - flowCharacteristic(q_single0 * 0.95)) / (q_single0 * 0.1) "Approximate derivative of flow characteristic w.r.t. volume flow" annotation(
+        Evaluate = true);
+      final parameter Real d_head_dn_0 = 2 / n0 * head0 - q_single0 / n0 * d_head_dq_0 "Approximate derivative of the flow characteristic w.r.t. rotational speed" annotation(
+        Evaluate = true);
+      Medium.MassFlowRate w_single(start = wstart / Np0) "Mass flow rate (single pump)";
+      Medium.MassFlowRate w = Np * w_single "Mass flow rate (total)";
+      SI.VolumeFlowRate q_single(start = wstart / (Np0 * rho0)) "Volume flow rate (single pump)";
+      SI.VolumeFlowRate q = Np * q_single "Volume flow rate (total)";
+      SI.PressureDifference dp "Outlet pressure minus inlet pressure";
+      SI.Height head "Pump head";
+      Medium.SpecificEnthalpy h(start = hstart) "Fluid specific enthalpy";
+      Medium.SpecificEnthalpy hin "Enthalpy of entering fluid";
+      Medium.SpecificEnthalpy hout "Enthalpy of outgoing fluid";
+      Units.LiquidDensity rho "Liquid density";
+      Medium.Temperature Tin "Liquid inlet temperature";
+      NonSI.AngularVelocity_rpm n "Shaft r.p.m.";
+      Integer Np(min = 1) "Number of pumps in parallel";
+      SI.Power W_single "Power Consumption (single pump)";
+      SI.Power W = Np * W_single "Power Consumption (total)";
+      SI.Power Qloss = 0 "Heat loss (single pump)";
+      constant SI.Power W_eps = 1e-8 "Small coefficient to avoid numerical singularities";
+      constant NonSI.AngularVelocity_rpm n_eps = 1e-6;
+      SI.PerUnit eta "Pump efficiency";
+      SI.PerUnit s(start = 1) "Auxiliary non-dimensional variable";
+      FlangeA infl(redeclare package Medium = Medium, m_flow(min = if allowFlowReversal then -Modelica.Constants.inf else 0)) annotation(
+        Placement(transformation(extent = {{-100, 0}, {-60, 40}}, rotation = 0)));
+      FlangeB outfl(redeclare package Medium = Medium, m_flow(max = if allowFlowReversal then +Modelica.Constants.inf else 0)) annotation(
+        Placement(transformation(extent = {{40, 50}, {80, 90}}, rotation = 0)));
+      Modelica.Blocks.Interfaces.IntegerInput in_Np if use_in_Np "Number of  parallel pumps" annotation(
+        Placement(transformation(origin = {28, 80}, extent = {{-10, -10}, {10, 10}}, rotation = 270)));
+    protected
+      Modelica.Blocks.Interfaces.IntegerInput int_Np "Internal connector with number of parallel pumps";
+    equation
+// Flow equations
+      q_single = w_single / homotopy(rho, rho0);
+      head = dp / (homotopy(rho, rho0) * g);
+      if noEvent(s > 0 or not CheckValve) then
+// Flow characteristics when check valve is open
+        q_single = s * q_single0;
+        head = homotopy((n / n0) ^ 2 * flowCharacteristic(q_single * n0 / (n + n_eps)), head0 + d_head_dq_0 * (q_single - q_single0) + d_head_dn_0 * (n - n0));
+      else
+// Flow characteristics when check valve is closed
+        head = homotopy((n / n0) ^ 2 * flowCharacteristic(0) - s * head0, head0 + d_head_dq_0 * (q_single - q_single0) + d_head_dn_0 * (n - n0));
+        q_single = 0;
+      end if;
+// Power consumption
+      if usePowerCharacteristic then
+        W_single = (n / n0) ^ 3 * (rho / rho0) * powerCharacteristic(q_single * n0 / (n + n_eps)) "Power consumption (single pump)";
+        eta = dp * q_single / (W_single + W_eps) "Hydraulic efficiency";
+      else
+        eta = efficiencyCharacteristic(q_single * n0 / (n + n_eps));
+        W_single = dp * q_single / eta;
+      end if;
+// Fluid properties
+      inletFluidState = Medium.setState_phX(infl.p, hin);
+      rho = Medium.density(inletFluidState);
+      Tin = Medium.temperature(inletFluidState);
+// Boundary conditions
+      dp = outfl.p - infl.p;
+      w = infl.m_flow "Pump total flow rate";
+      hin = homotopy(if not allowFlowReversal then inStream(infl.h_outflow) else if w >= 0 then inStream(infl.h_outflow) else inStream(outfl.h_outflow), inStream(infl.h_outflow));
+      infl.h_outflow = hout;
+      outfl.h_outflow = hout;
+      h = hout;
+// Mass and energy balances
+      infl.m_flow + outfl.m_flow = 0 "Mass balance";
+      if V > 0 then
+        rho * V * der(h) = outfl.m_flow / Np * hout + infl.m_flow / Np * hin + W_single - Qloss "Energy balance";
+      else
+        0 = outfl.m_flow / Np * hout + infl.m_flow / Np * hin + W_single - Qloss "Energy balance";
+      end if;
+// Number of pumps in parallel
+      connect(in_Np, int_Np);
+      if not use_in_Np then
+        int_Np = Np0;
+      end if;
+      Np = int_Np;
+    initial equation
+      if initOpt == Choices.Init.Options.noInit then
+// do nothing
+      elseif initOpt == Choices.Init.Options.fixedState then
+        if V > 0 then
+          h = hstart;
+        end if;
+      elseif initOpt == Choices.Init.Options.steadyState then
+        if V > 0 then
+          der(h) = 0;
+        end if;
+      else
+        assert(false, "Unsupported initialisation option");
+      end if;
+      annotation(
+        Icon(graphics),
+        Diagram(graphics),
+        Documentation(info = "<HTML>
 <p>This is the base model for the <tt>Pump</tt> and <tt>
 PumpMech</tt> pump models.
 <p>The model describes a centrifugal pump, or a group of <tt>Np</tt> identical pumps in parallel. The pump model is based on the theory of kinematic similarity: the pump characteristics are given for nominal operating conditions (rotational speed and fluid density), and then adapted to actual operating condition, according to the similarity equations.
@@ -5959,7 +4603,7 @@
 <p>It is possible to take into account the heat capacity of the fluid inside the pump by specifying its volume <tt>V</tt> at nominal conditions; this is necessary to avoid singularities in the computation of the outlet enthalpy in case of zero flow rate. If zero flow rate conditions are always avoided, this dynamic effect can be neglected by leaving the default value <tt>V = 0</tt>, thus avoiding a fast state variable in the model.
 <p>The <tt>CheckValve</tt> parameter determines whether the pump has a built-in check valve or not.
 <p>If <tt>computeNPSHa = true</tt>, the available net positive suction head is also computed; this requires a two-phase medium model to provide the fluid saturation pressure.
-</HTML>", revisions="<html>
+</HTML>", revisions = "<html>
 <ul>
 <li><i>31 Oct 2006</i>
     by <a href=\"mailto:francesco.casella@polimi.it\">Francesco Casella</a>:<br>
@@ -5987,138 +4631,97 @@
     by <a href=\"mailto:francesco.schiavo@polimi.it\">Francesco Schiavo</a>:<br>
        First release.</li>
 </ul>
-</html>"));
-    end PumpBase;
-
-    partial model SteamTurbineBase "Steam turbine"
-      replaceable package Medium = ThermoPower.Water.StandardWater
-        constrainedby Modelica.Media.Interfaces.PartialMedium "Medium model"
-        annotation(choicesAllMatching = true);
-      parameter Boolean explicitIsentropicEnthalpy=true
-        "Outlet enthalpy computed by isentropicEnthalpy function";
-      parameter Medium.MassFlowRate wstart=wnom "Mass flow rate start value"
-        annotation (Dialog(tab="Initialisation"));
-      parameter SI.PerUnit PRstart "Pressure ratio start value"
-        annotation (Dialog(tab="Initialisation"));
-      parameter Medium.MassFlowRate wnom "Inlet nominal flowrate";
-      parameter Medium.AbsolutePressure pnom "Nominal inlet pressure";
-      parameter Real eta_mech=0.98 "Mechanical efficiency";
-      parameter Boolean usePartialArcInput = false
-        "Use the input connector for the partial arc opening";
-
-      outer ThermoPower.System system "System wide properties";
-
-      Medium.ThermodynamicState steamState_in;
-      Medium.ThermodynamicState steamState_iso;
-
-      SI.Angle phi(start=0) "shaft rotation angle";
-      SI.Torque tau "net torque acting on the turbine";
-      SI.AngularVelocity omega "shaft angular velocity";
-      Medium.MassFlowRate w "Mass flow rate";
-      Medium.SpecificEnthalpy hin "Inlet enthalpy";
-      Medium.SpecificEnthalpy hout "Outlet enthalpy";
-      Medium.SpecificEnthalpy hiso "Isentropic outlet enthalpy";
-      Medium.SpecificEntropy sin "Inlet entropy";
-      Medium.AbsolutePressure pin(start=pnom) "Outlet pressure";
-      Medium.AbsolutePressure pout(start=pnom/PRstart) "Outlet pressure";
-      SI.PerUnit PR "pressure ratio";
-      SI.Power Pm "Mechanical power input";
-      SI.PerUnit eta_iso "Isentropic efficiency";
-      SI.PerUnit theta "Partial arc opening in p.u.";
-
-      Modelica.Blocks.Interfaces.RealInput partialArc if usePartialArcInput
-        "Partial arc opening in p.u." annotation (Placement(
-            transformation(extent={{-60,-50},{-40,-30}}, rotation=0)));
-      Modelica.Mechanics.Rotational.Interfaces.Flange_a shaft_a annotation (
-          Placement(transformation(extent={{-76,-10},{-56,10}}, rotation=0)));
-      Modelica.Mechanics.Rotational.Interfaces.Flange_b shaft_b annotation (
-          Placement(transformation(extent={{54,-10},{74,10}}, rotation=0)));
-      FlangeA inlet(redeclare package Medium = Medium, m_flow(min=0))
-        annotation (Placement(transformation(extent={{-100,60},{-60,100}},
-              rotation=0)));
-      FlangeB outlet(redeclare package Medium = Medium, m_flow(max=0))
-        annotation (Placement(transformation(extent={{60,60},{100,100}},
-              rotation=0)));
-    protected
-      Modelica.Blocks.Interfaces.RealInput partialArc_int "Internal connector for partial arc input";
-    equation
-      PR = pin/pout "Pressure ratio";
-      theta = partialArc_int;
-      if not usePartialArcInput then
-        partialArc_int = 1 "Default value if not connector input is disabled";
-        // otherwise partialArc_int is connected to partialArc input connector
-      end if;
-      if explicitIsentropicEnthalpy then
-        hiso = Medium.isentropicEnthalpy(pout, steamState_in)
-          "Isentropic enthalpy";
-        //dummy assignments
-        sin = 0;
-        steamState_iso = Medium.setState_phX(Medium.p_default,Medium.h_default);
-      else
-        sin = Medium.specificEntropy(steamState_in);
-        steamState_iso = Medium.setState_ps(pout, sin);
-        hiso = Medium.specificEnthalpy(steamState_iso);
-      end if;
-      hin - hout = eta_iso*(hin - hiso) "Computation of outlet enthalpy";
-      Pm = eta_mech*w*(hin - hout) "Mechanical power from the steam";
-      Pm = -tau*omega "Mechanical power balance";
-
-      inlet.m_flow + outlet.m_flow = 0 "Mass balance";
-
-      assert(w >= -wnom/100, "The turbine model does not support flow reversal");
-
-      // Mechanical boundary conditions
-      shaft_a.phi = phi;
-      shaft_b.phi = phi;
-      shaft_a.tau + shaft_b.tau = tau;
-      der(phi) = omega;
-
-      // steam boundary conditions and inlet steam properties
-      steamState_in = Medium.setState_phX(pin, inStream(inlet.h_outflow));
-      hin = inStream(inlet.h_outflow);
-      hout = outlet.h_outflow;
-      pin = inlet.p;
-      pout = outlet.p;
-      w = inlet.m_flow;
-
-      // The next equation is provided to close the balance but never actually used
-      inlet.h_outflow = outlet.h_outflow;
-      connect(partialArc, partialArc_int);
-      annotation (
-        Icon(graphics={
-            Polygon(
-              points={{-28,76},{-28,28},{-22,28},{-22,82},{-60,82},{-60,76},{-28,
-                  76}},
-              lineColor={0,0,0},
-              lineThickness=0.5,
-              fillColor={0,0,255},
-              fillPattern=FillPattern.Solid),
-            Polygon(
-              points={{26,56},{32,56},{32,76},{60,76},{60,82},{26,82},{26,56}},
-              lineColor={0,0,0},
-              lineThickness=0.5,
-              fillColor={0,0,255},
-              fillPattern=FillPattern.Solid),
-            Rectangle(
-              extent={{-60,8},{60,-8}},
-              lineColor={0,0,0},
-              fillPattern=FillPattern.Sphere,
-              fillColor={160,160,164}),
-            Polygon(
-              points={{-28,28},{-28,-26},{32,-60},{32,60},{-28,28}},
-              lineColor={0,0,0},
-              lineThickness=0.5,
-              fillColor={0,0,255},
-              fillPattern=FillPattern.Solid),
-            Text(extent={{-130,-60},{128,-100}}, textString="%name")}),
-        Diagram(graphics),
-        Documentation(info="<html>
+</html>"));
+    end PumpBase;
+
+    partial model SteamTurbineBase "Steam turbine"
+      replaceable package Medium = ThermoPower.Water.StandardWater constrainedby Modelica.Media.Interfaces.PartialMedium "Medium model" annotation(
+         choicesAllMatching = true);
+      parameter Boolean explicitIsentropicEnthalpy = true "Outlet enthalpy computed by isentropicEnthalpy function";
+      parameter Medium.MassFlowRate wstart = wnom "Mass flow rate start value" annotation(
+        Dialog(tab = "Initialisation"));
+      parameter SI.PerUnit PRstart "Pressure ratio start value" annotation(
+        Dialog(tab = "Initialisation"));
+      parameter Medium.MassFlowRate wnom "Inlet nominal flowrate";
+      parameter Medium.AbsolutePressure pnom "Nominal inlet pressure";
+      parameter Real eta_mech = 0.98 "Mechanical efficiency";
+      parameter Boolean usePartialArcInput = false "Use the input connector for the partial arc opening";
+      outer ThermoPower.System system "System wide properties";
+      Medium.ThermodynamicState steamState_in;
+      Medium.ThermodynamicState steamState_iso;
+      SI.Angle phi(start = 0) "shaft rotation angle";
+      SI.Torque tau "net torque acting on the turbine";
+      SI.AngularVelocity omega "shaft angular velocity";
+      Medium.MassFlowRate w "Mass flow rate";
+      Medium.SpecificEnthalpy hin "Inlet enthalpy";
+      Medium.SpecificEnthalpy hout "Outlet enthalpy";
+      Medium.SpecificEnthalpy hiso "Isentropic outlet enthalpy";
+      Medium.SpecificEntropy sin "Inlet entropy";
+      Medium.AbsolutePressure pin(start = pnom) "Outlet pressure";
+      Medium.AbsolutePressure pout(start = pnom / PRstart) "Outlet pressure";
+      SI.PerUnit PR "pressure ratio";
+      SI.Power Pm "Mechanical power input";
+      SI.PerUnit eta_iso "Isentropic efficiency";
+      SI.PerUnit theta "Partial arc opening in p.u.";
+      Modelica.Blocks.Interfaces.RealInput partialArc if usePartialArcInput "Partial arc opening in p.u." annotation(
+        Placement(transformation(extent = {{-60, -50}, {-40, -30}}, rotation = 0)));
+      Modelica.Mechanics.Rotational.Interfaces.Flange_a shaft_a annotation(
+        Placement(transformation(extent = {{-76, -10}, {-56, 10}}, rotation = 0)));
+      Modelica.Mechanics.Rotational.Interfaces.Flange_b shaft_b annotation(
+        Placement(transformation(extent = {{54, -10}, {74, 10}}, rotation = 0)));
+      FlangeA inlet(redeclare package Medium = Medium, m_flow(min = 0)) annotation(
+        Placement(transformation(extent = {{-100, 60}, {-60, 100}}, rotation = 0)));
+      FlangeB outlet(redeclare package Medium = Medium, m_flow(max = 0)) annotation(
+        Placement(transformation(extent = {{60, 60}, {100, 100}}, rotation = 0)));
+    protected
+      Modelica.Blocks.Interfaces.RealInput partialArc_int "Internal connector for partial arc input";
+    equation
+      PR = pin / pout "Pressure ratio";
+      theta = partialArc_int;
+      if not usePartialArcInput then
+        partialArc_int = 1 "Default value if not connector input is disabled";
+// otherwise partialArc_int is connected to partialArc input connector
+      end if;
+      if explicitIsentropicEnthalpy then
+        hiso = Medium.isentropicEnthalpy(pout, steamState_in) "Isentropic enthalpy";
+//dummy assignments
+        sin = 0;
+        steamState_iso = Medium.setState_phX(Medium.p_default, Medium.h_default);
+      else
+        sin = Medium.specificEntropy(steamState_in);
+        steamState_iso = Medium.setState_ps(pout, sin);
+        hiso = Medium.specificEnthalpy(steamState_iso);
+      end if;
+      hin - hout = eta_iso * (hin - hiso) "Computation of outlet enthalpy";
+      Pm = eta_mech * w * (hin - hout) "Mechanical power from the steam";
+      Pm = -tau * omega "Mechanical power balance";
+      inlet.m_flow + outlet.m_flow = 0 "Mass balance";
+      assert(w >= (-wnom / 100), "The turbine model does not support flow reversal");
+// Mechanical boundary conditions
+      shaft_a.phi = phi;
+      shaft_b.phi = phi;
+      shaft_a.tau + shaft_b.tau = tau;
+      der(phi) = omega;
+// steam boundary conditions and inlet steam properties
+      steamState_in = Medium.setState_phX(pin, inStream(inlet.h_outflow));
+      hin = inStream(inlet.h_outflow);
+      hout = outlet.h_outflow;
+      pin = inlet.p;
+      pout = outlet.p;
+      w = inlet.m_flow;
+// The next equation is provided to close the balance but never actually used
+      inlet.h_outflow = outlet.h_outflow;
+      connect(partialArc, partialArc_int);
+      annotation(
+        Icon(graphics = {Polygon(points = {{-28, 76}, {-28, 28}, {-22, 28}, {-22, 82}, {-60, 82}, {-60, 76}, {-28, 76}}, lineColor = {0, 0, 0}, lineThickness = 0.5, fillColor = {0, 0, 255}, fillPattern = FillPattern.Solid), Polygon(points = {{26, 56}, {32, 56}, {32, 76}, {60, 76}, {60, 82}, {26, 82}, {26, 56}}, lineColor = {0, 0, 0}, lineThickness = 0.5, fillColor = {0, 0, 255}, fillPattern = FillPattern.Solid), Rectangle(extent = {{-60, 8}, {60, -8}}, lineColor = {0, 0, 0}, fillPattern = FillPattern.Sphere, fillColor = {160, 160, 164}), Polygon(points = {{-28, 28}, {-28, -26}, {32, -60}, {32, 60}, {-28, 28}}, lineColor = {0, 0, 0}, lineThickness = 0.5, fillColor = {0, 0, 255}, fillPattern = FillPattern.Solid), Text(extent = {{-130, -60}, {128, -100}}, textString = "%name")}),
+        Diagram(graphics),
+        Documentation(info = "<html>
 <p>This base model contains the basic interface, parameters and definitions for steam turbine models. It lacks the actual performance characteristics, i.e. two more equations to determine the flow rate and the efficiency.
 <p>This model does not include any shaft inertia by itself; if that is needed, connect a <tt>Modelica.Mechanics.Rotational.Inertia</tt> model to one of the shaft connectors.
 <p><b>Modelling options</b></p>
 <p>The following options are available to calculate the enthalpy of the outgoing steam:
 <ul><li><tt>explicitIsentropicEnthalpy = true</tt>: the isentropic enthalpy <tt>hout_iso</tt> is calculated by the <tt>Medium.isentropicEnthalpy</tt> function. <li><tt>explicitIsentropicEnthalpy = false</tt>: the isentropic enthalpy is given equating the specific entropy of the inlet steam <tt>steam_in</tt> and of a fictional steam state <tt>steam_iso</tt>, which has the same pressure of the outgoing steam, both computed with the function <tt>Medium.specificEntropy</tt>.</pp></ul>
-</html>", revisions="<html>
+</html>", revisions = "<html>
 <ul>
 <li><i>20 Apr 2005</i>
     by <a href=\"mailto:francesco.casella@polimi.it\">Francesco Casella</a>:<br>
@@ -6127,285 +4730,240 @@
     by <a href=\"mailto:francesco.casella@polimi.it\">Francesco Casella</a>:<br>
        Small changes in alias variables.</li>
 </ul>
-</html>"));
-    end SteamTurbineBase;
-
-    partial model EvaporatorBase
-      "Basic interface for 1-dimensional water/steam fluid flow models"
-      replaceable package Medium = StandardWater constrainedby
-        Modelica.Media.Interfaces.PartialTwoPhaseMedium "Medium model";
-      Medium.BaseProperties fluid_in "Fluid properties at the inlet";
-      Medium.BaseProperties fluid_out "Fluid properties at the outlet";
-      Medium.SaturationProperties sat "Saturation properties";
-      extends Icons.Water.Tube;
-      parameter Integer N(min=2) = 2 "Number of nodes for thermal variables";
-      parameter Integer Nt=1 "Number of tubes in parallel";
-      parameter SI.Distance L "Tube length";
-      parameter SI.Position H=0 "Elevation of outlet over inlet";
-      parameter SI.Area A "Cross-sectional area (single tube)";
-      parameter SI.Length omega
-        "Perimeter of heat transfer surface (single tube)";
-      parameter SI.Length Dhyd "Hydraulic Diameter (single tube)";
-      parameter SI.MassFlowRate wnom "Nominal mass flowrate (total)";
-      parameter Integer FFtype
-        "Friction Factor Type (0: Kf; 1:OpPoint, 2:Cfnom, 3:Colebrook)";
-      parameter Real Kfnom=0 "Nominal hydraulic resistance coefficient";
-      parameter SI.Pressure dpnom=0
-        "Nominal pressure drop (friction term only!)";
-      parameter Medium.Density rhonom=0 "Nominal inlet density";
-      parameter SI.PerUnit Cfnom=0 "Nominal Fanning friction factor";
-      parameter SI.PerUnit e=0 "Relative roughness (ratio roughness/diameter)";
-      parameter Boolean DynamicMomentum=false
-        "Inertial phenomena accounted for";
-      parameter Integer HydraulicCapacitance=2 "1: Upstream, 2: Downstream";
-      parameter SI.Length csilstart "Liquid boundary start position";
-      parameter SI.Length csivstart "Vapour boundary start position";
-      parameter Medium.SpecificEnthalpy hstartin=1e5
-        "Inlet enthalpy start value";
-      parameter Medium.SpecificEnthalpy hstartout=1e5
-        "Outlet enthalpy start value";
-      parameter Medium.AbsolutePressure pstartin=1e5
-        "Inlet pressure start value";
-      parameter Medium.AbsolutePressure pstartout=1e5
-        "Outlet pressure start value";
-      parameter Real wnf=0.01
-        "Fraction of nominal flow rate at which linear friction equals turbulent friction";
-      parameter SI.PerUnit Kfc=1 "Friction factor correction coefficient";
-      constant SI.Acceleration g=Modelica.Constants.g_n;
+</html>"));
+    end SteamTurbineBase;
+
+    partial model EvaporatorBase "Basic interface for 1-dimensional water/steam fluid flow models"
+      replaceable package Medium = StandardWater constrainedby Modelica.Media.Interfaces.PartialTwoPhaseMedium "Medium model";
+      Medium.BaseProperties fluid_in "Fluid properties at the inlet";
+      Medium.BaseProperties fluid_out "Fluid properties at the outlet";
+      Medium.SaturationProperties sat "Saturation properties";
+      extends Icons.Water.Tube;
+      parameter Integer N(min = 2) = 2 "Number of nodes for thermal variables";
+      parameter Integer Nt = 1 "Number of tubes in parallel";
+      parameter SI.Distance L "Tube length";
+      parameter SI.Position H = 0 "Elevation of outlet over inlet";
+      parameter SI.Area A "Cross-sectional area (single tube)";
+      parameter SI.Length omega "Perimeter of heat transfer surface (single tube)";
+      parameter SI.Length Dhyd "Hydraulic Diameter (single tube)";
+      parameter SI.MassFlowRate wnom "Nominal mass flowrate (total)";
+      parameter Integer FFtype "Friction Factor Type (0: Kf; 1:OpPoint, 2:Cfnom, 3:Colebrook)";
+      parameter Real Kfnom = 0 "Nominal hydraulic resistance coefficient";
+      parameter SI.Pressure dpnom = 0 "Nominal pressure drop (friction term only!)";
+      parameter Medium.Density rhonom = 0 "Nominal inlet density";
+      parameter SI.PerUnit Cfnom = 0 "Nominal Fanning friction factor";
+      parameter SI.PerUnit e = 0 "Relative roughness (ratio roughness/diameter)";
+      parameter Boolean DynamicMomentum = false "Inertial phenomena accounted for";
+      parameter Integer HydraulicCapacitance = 2 "1: Upstream, 2: Downstream";
+      parameter SI.Length csilstart "Liquid boundary start position";
+      parameter SI.Length csivstart "Vapour boundary start position";
+      parameter Medium.SpecificEnthalpy hstartin = 1e5 "Inlet enthalpy start value";
+      parameter Medium.SpecificEnthalpy hstartout = 1e5 "Outlet enthalpy start value";
+      parameter Medium.AbsolutePressure pstartin = 1e5 "Inlet pressure start value";
+      parameter Medium.AbsolutePressure pstartout = 1e5 "Outlet pressure start value";
+      parameter Real wnf = 0.01 "Fraction of nominal flow rate at which linear friction equals turbulent friction";
+      parameter SI.PerUnit Kfc = 1 "Friction factor correction coefficient";
+      constant SI.Acceleration g = Modelica.Constants.g_n;
       /*
-  FlangeA infl(p(start=pstartin),w(start=wnom),hAB(start=hstartin),
-    redeclare package Medium = Medium)
-    annotation (extent=[-120, -20; -80, 20]);
-  FlangeB outfl(p(start=pstartout),w(start=-wnom),hBA(start=hstartout),
-    redeclare package Medium = Medium)
-    annotation (extent=[80, -20; 120, 20]);
-  replaceable ThermoPower.Thermal.DHT wall(N=N)
-    annotation (extent=[-40, 40; 40, 60]);
-*/
-      Medium.AbsolutePressure p(start=pstartin, stateSelect=StateSelect.prefer);
-      Medium.MassFlowRate win(start=wnom) "Inlet flow rate";
-      Medium.MassFlowRate wlb(start=wnom)
-        "Flowrate from liquid volume to boiling volume";
-      Medium.MassFlowRate wbv(start=wnom)
-        "Flowrate from boiling volume to vapour volume";
-      Medium.MassFlowRate wout(start=wnom) "Outlet flow rate";
-      Medium.SpecificEnthalpy hin(start=hstartin) "Inlet specific enthalpy";
-      Medium.SpecificEnthalpy hout(start=hstartout, stateSelect=StateSelect.prefer)
-        "Outlet specific enthalpy";
-      Medium.SpecificEnthalpy hls "Saturated liquid specific enthalpy";
-      Medium.SpecificEnthalpy hvs "Saturated vapour specific enthalpy";
-      Medium.SpecificEnthalpy hlb;
-      Medium.SpecificEnthalpy hbv;
-      Medium.Density rhoin "Inlet density";
-      Medium.Density rhoout "Outlet density";
-      Medium.Density rhols "Saturated liquid density";
-      Medium.Density rhovs "Saturated vapour density";
-      SI.Volume Vl "Liquid volume";
-      SI.Volume Vb "Boiling volume";
-      SI.Volume Vv "Vapour volume";
-      SI.Mass Ml "Mass of the liquid volume";
-      SI.Mass Mb "Mass of the boiling volume";
-      SI.Mass Mbl "Mass of liquid in the boiling volume";
-      SI.Mass Mbv "Mass of vapour in the boiling volume";
-      SI.Mass Mv "Mass of the vapour volume";
-      SI.Energy El "Energy of the liquid volume";
-      SI.Energy Eb "Energy of the boiling volume";
-      SI.Energy Ev "Energy of the vapour volume";
-      SI.Power Q "Total power balance";
-      Medium.MassFlowRate M_flow "Total mass flow balance";
-      SI.Power Ql "Thermal power to the liquid volume";
-      SI.Power Qb "Thermal power to the boiling volume";
-      SI.Power Qv "Thermal power to the vapour volume";
-      SI.Length csil(start=csilstart, stateSelect=StateSelect.prefer)
-        "Abscissa of liqid boundary";
-      SI.Length csiv(start=csivstart, stateSelect=StateSelect.prefer)
-        "Abscissa of vapour boundary";
-      SI.Time Tr "Residence time";
-
-    equation
-      Vl = A*csil "Volume of subcooled liquid";
-      Vb = A*(csiv - csil) "Volume of boiling liquid";
-      Vv = A*(L - csiv) "Volume of superheated vapour";
-      Ml = (rhoin + (if hout > hls then rhols else rhoout))/2*Vl
-        "Mass of subcooled liquid";
-      Mb = (if (hout > hvs) then rhols*rhovs/(rhols - rhovs)*log(rhols/rhovs)
-         else if (hout > hls + 1e-3) then rhols*rhoout/(rhols - rhoout)*log(rhols
-        /rhoout) else rhols)*Vb "Mass of boiling liquid";
-      Mbv = (if (hout > hvs) then rhols*rhovs/(rhols - rhovs)*(1 - rhovs/(rhols
-         - rhovs)*log(rhols/rhovs)) else if (hout > hls + 1e-3) then rhols*rhovs/
-        (rhols - rhovs)*(1 - rhoout/(rhols - rhoout)*log(rhols/rhoout)) else if (
-        hout > hls) then rhovs/(rhols - rhovs)*(rhols - rhoout)/2 else 0)*Vb
-        "Mass of vapour in boiling liquid";
-      Mbl = Mb - Mbv "Mass of liquid in boiling liquid";
-      Mv = Vv*(rhovs + rhoout)/2 "Mass of superheated vapour";
-      El = Ml*(hin + (if hout > hls then hls else hout))/2 - p*Vl
-        "Energy of subcooled liquid";
-      Eb = Mbl*hls + Mbv*hvs - p*Vb "Energy of boiling water";
-      Ev = Mv*(hvs + hout)/2 - p*Vv "Energy of superheated vapour";
-      der(Ml) = win - wlb "Liquid volume mass balance";
-      if hout > hls then
-        der(Mb) = wlb - wbv "Boiling volume mass balance";
-      else
-        der(csil) = 0;
-      end if;
-      if hout > hvs then
-        der(Mv) = wbv - wout "Superheated volume mass balance";
-      else
-        der(csiv) = 0;
-      end if;
-      der(El) = win*hin - wlb*hlb - p*der(Vl) + Ql
-        "Liquid volume energy balance";
-      if hout > hls then
-        der(Eb) = wlb*hlb - wbv*hbv - p*der(Vb) + Qb
-          "Boiling volume energy balance";
-      else
-        wlb = wout;
-      end if;
-      if hout > hvs then
-        der(Ev) = wbv*hbv - wout*hout - p*der(Vv) + Qv
-          "Superheated volume energy balance";
-      else
-        wbv = wout;
-      end if;
-      hlb = if (hout > hls) then hls else hout
-        "Enthalpy at the liquid-boiling interface";
-      hbv = if (hout > hvs) then hvs else hout
-        "Enthalpy at the boiling-vapour interface";
-      Tr = (Ml + Mb + Mv)/win "Residence time";
-
-      // Fluid properties
-      sat.psat = p;
-      sat.Tsat = Medium.saturationTemperature(p);
-      fluid_in.p = p;
-      fluid_in.h = hin;
-      fluid_out.p = p;
-      fluid_out.h = hout;
-
-      rhoin = fluid_in.d;
-      rhoout = fluid_out.d;
-      rhols = Medium.bubbleDensity(sat);
-      rhovs = Medium.dewDensity(sat);
-      hls = Medium.bubbleEnthalpy(sat);
-      hvs = Medium.dewEnthalpy(sat);
-
-      // Temporary boundary conditions
-      Q = Ql + Qb + Qv + win*hin - wout*hout - der(El) - der(Eb) - der(Ev);
-      M_flow = win - wout - der(Ml) - der(Mb) - der(Mv);
-      annotation (Documentation(info="<html>
+        FlangeA infl(p(start=pstartin),w(start=wnom),hAB(start=hstartin),
+          redeclare package Medium = Medium)
+          annotation (extent=[-120, -20; -80, 20]);
+        FlangeB outfl(p(start=pstartout),w(start=-wnom),hBA(start=hstartout),
+          redeclare package Medium = Medium)
+          annotation (extent=[80, -20; 120, 20]);
+        replaceable ThermoPower.Thermal.DHT wall(N=N)
+          annotation (extent=[-40, 40; 40, 60]);
+      */
+      Medium.AbsolutePressure p(start = pstartin, stateSelect = StateSelect.prefer);
+      Medium.MassFlowRate win(start = wnom) "Inlet flow rate";
+      Medium.MassFlowRate wlb(start = wnom) "Flowrate from liquid volume to boiling volume";
+      Medium.MassFlowRate wbv(start = wnom) "Flowrate from boiling volume to vapour volume";
+      Medium.MassFlowRate wout(start = wnom) "Outlet flow rate";
+      Medium.SpecificEnthalpy hin(start = hstartin) "Inlet specific enthalpy";
+      Medium.SpecificEnthalpy hout(start = hstartout, stateSelect = StateSelect.prefer) "Outlet specific enthalpy";
+      Medium.SpecificEnthalpy hls "Saturated liquid specific enthalpy";
+      Medium.SpecificEnthalpy hvs "Saturated vapour specific enthalpy";
+      Medium.SpecificEnthalpy hlb;
+      Medium.SpecificEnthalpy hbv;
+      Medium.Density rhoin "Inlet density";
+      Medium.Density rhoout "Outlet density";
+      Medium.Density rhols "Saturated liquid density";
+      Medium.Density rhovs "Saturated vapour density";
+      SI.Volume Vl "Liquid volume";
+      SI.Volume Vb "Boiling volume";
+      SI.Volume Vv "Vapour volume";
+      SI.Mass Ml "Mass of the liquid volume";
+      SI.Mass Mb "Mass of the boiling volume";
+      SI.Mass Mbl "Mass of liquid in the boiling volume";
+      SI.Mass Mbv "Mass of vapour in the boiling volume";
+      SI.Mass Mv "Mass of the vapour volume";
+      SI.Energy El "Energy of the liquid volume";
+      SI.Energy Eb "Energy of the boiling volume";
+      SI.Energy Ev "Energy of the vapour volume";
+      SI.Power Q "Total power balance";
+      Medium.MassFlowRate M_flow "Total mass flow balance";
+      SI.Power Ql "Thermal power to the liquid volume";
+      SI.Power Qb "Thermal power to the boiling volume";
+      SI.Power Qv "Thermal power to the vapour volume";
+      SI.Length csil(start = csilstart, stateSelect = StateSelect.prefer) "Abscissa of liqid boundary";
+      SI.Length csiv(start = csivstart, stateSelect = StateSelect.prefer) "Abscissa of vapour boundary";
+      SI.Time Tr "Residence time";
+    equation
+      Vl = A * csil "Volume of subcooled liquid";
+      Vb = A * (csiv - csil) "Volume of boiling liquid";
+      Vv = A * (L - csiv) "Volume of superheated vapour";
+      Ml = (rhoin + (if hout > hls then rhols else rhoout)) / 2 * Vl "Mass of subcooled liquid";
+      Mb = (if hout > hvs then rhols * rhovs / (rhols - rhovs) * log(rhols / rhovs) else if hout > hls + 1e-3 then rhols * rhoout / (rhols - rhoout) * log(rhols / rhoout) else rhols) * Vb "Mass of boiling liquid";
+      Mbv = (if hout > hvs then rhols * rhovs / (rhols - rhovs) * (1 - rhovs / (rhols - rhovs) * log(rhols / rhovs)) else if hout > hls + 1e-3 then rhols * rhovs / (rhols - rhovs) * (1 - rhoout / (rhols - rhoout) * log(rhols / rhoout)) else if hout > hls then rhovs / (rhols - rhovs) * (rhols - rhoout) / 2 else 0) * Vb "Mass of vapour in boiling liquid";
+      Mbl = Mb - Mbv "Mass of liquid in boiling liquid";
+      Mv = Vv * (rhovs + rhoout) / 2 "Mass of superheated vapour";
+      El = Ml * (hin + (if hout > hls then hls else hout)) / 2 - p * Vl "Energy of subcooled liquid";
+      Eb = Mbl * hls + Mbv * hvs - p * Vb "Energy of boiling water";
+      Ev = Mv * (hvs + hout) / 2 - p * Vv "Energy of superheated vapour";
+      der(Ml) = win - wlb "Liquid volume mass balance";
+      if hout > hls then
+        der(Mb) = wlb - wbv "Boiling volume mass balance";
+      else
+        der(csil) = 0;
+      end if;
+      if hout > hvs then
+        der(Mv) = wbv - wout "Superheated volume mass balance";
+      else
+        der(csiv) = 0;
+      end if;
+      der(El) = win * hin - wlb * hlb - p * der(Vl) + Ql "Liquid volume energy balance";
+      if hout > hls then
+        der(Eb) = wlb * hlb - wbv * hbv - p * der(Vb) + Qb "Boiling volume energy balance";
+      else
+        wlb = wout;
+      end if;
+      if hout > hvs then
+        der(Ev) = wbv * hbv - wout * hout - p * der(Vv) + Qv "Superheated volume energy balance";
+      else
+        wbv = wout;
+      end if;
+      hlb = if hout > hls then hls else hout "Enthalpy at the liquid-boiling interface";
+      hbv = if hout > hvs then hvs else hout "Enthalpy at the boiling-vapour interface";
+      Tr = (Ml + Mb + Mv) / win "Residence time";
+// Fluid properties
+      sat.psat = p;
+      sat.Tsat = Medium.saturationTemperature(p);
+      fluid_in.p = p;
+      fluid_in.h = hin;
+      fluid_out.p = p;
+      fluid_out.h = hout;
+      rhoin = fluid_in.d;
+      rhoout = fluid_out.d;
+      rhols = Medium.bubbleDensity(sat);
+      rhovs = Medium.dewDensity(sat);
+      hls = Medium.bubbleEnthalpy(sat);
+      hvs = Medium.dewEnthalpy(sat);
+// Temporary boundary conditions
+      Q = Ql + Qb + Qv + win * hin - wout * hout - der(El) - der(Eb) - der(Ev);
+      M_flow = win - wout - der(Ml) - der(Mb) - der(Mv);
+      annotation(
+        Documentation(info = "<html>
 This model is not yet complete
-</html>"));
-    end EvaporatorBase;
-  end BaseClasses;
-
-  model Drum2States
-    extends Icons.Water.Drum;
-    extends Modelica.Icons.ObsoleteModel;
-    replaceable package Medium = StandardWater constrainedby
-      Modelica.Media.Interfaces.PartialTwoPhaseMedium "Medium model"
-      annotation(choicesAllMatching = true);
-    parameter SI.Volume Vd "Drum volume";
-    parameter SI.Volume Vdcr "Volume of downcomer and risers";
-    parameter SI.Mass Mmd "Drum metal mass";
-    parameter SI.Mass Mmdcr "Metal mass of downcomer and risers";
-    parameter Medium.SpecificHeatCapacity cm
-      "Specific heat capacity of the metal";
-    parameter Boolean allowFlowReversal=system.allowFlowReversal
-      "= true to allow flow reversal, false restricts to design direction"
-      annotation(Evaluate=true);
-    outer ThermoPower.System system "System wide properties";
-    parameter SI.Pressure pstart "Pressure start value"
-      annotation (Dialog(tab="Initialisation"));
-    parameter SI.Volume Vldstart "Start value of drum water volume"
-      annotation (Dialog(tab="Initialisation"));
-    parameter Choices.Init.Options initOpt=system.initOpt
-      "Initialisation option"
-      annotation (Dialog(tab="Initialisation"));
-    parameter Boolean noInitialPressure=false
-      "Remove initial equation on pressure"
-      annotation (Dialog(tab="Initialisation"),choices(checkBox=true));
-
-    Medium.SaturationProperties sat "Saturation conditions";
-    FlangeA feed(redeclare package Medium = Medium, m_flow(min=if
-            allowFlowReversal then -Modelica.Constants.inf else 0)) annotation (
-       Placement(transformation(extent={{-110,-64},{-70,-24}}, rotation=0)));
-    FlangeB steam(redeclare package Medium = Medium, m_flow(max=if
-            allowFlowReversal then +Modelica.Constants.inf else 0)) annotation (
-       Placement(transformation(extent={{48,52},{88,92}}, rotation=0)));
-    Modelica.Thermal.HeatTransfer.Interfaces.HeatPort_a heat
-      "Metal wall thermal port" annotation (Placement(transformation(extent={{-28,
-              -100},{28,-80}}, rotation=0)));
-    SI.Mass Ml "Liquid water mass";
-    SI.Mass Mv "Steam mass";
-    SI.Mass M "Total liquid+steam mass";
-    SI.Energy E "Total energy";
-    SI.Volume Vt "Total volume";
-    SI.Volume Vl(start=Vldstart + Vdcr) "Liquid water total volume";
-    SI.Volume Vld(start=Vldstart, stateSelect=StateSelect.prefer)
-      "Liquid water volume in the drum";
-    SI.Volume Vv "Steam volume";
-    Medium.AbsolutePressure p(start=pstart,stateSelect=StateSelect.prefer)
-      "Drum pressure";
-    Medium.MassFlowRate qf "Feedwater mass flowrate";
-    Medium.MassFlowRate qs "Steam mass flowrate";
-    SI.HeatFlowRate Q "Heat flow to the risers";
-    Medium.SpecificEnthalpy hf "Feedwater specific enthalpy";
-    Medium.SpecificEnthalpy hl "Specific enthalpy of saturated liquid";
-    Medium.SpecificEnthalpy hv "Specific enthalpy of saturated steam";
-    Medium.Temperature Ts "Saturation temperature";
-    Units.LiquidDensity rhol "Density of saturated liquid";
-    Units.GasDensity rhov "Density of saturated steam";
-  equation
-    Ml = Vl*rhol "Mass of liquid";
-    Mv = Vv*rhov "Mass of vapour";
-    M = Ml + Mv "Total mass";
-    E = Ml*hl + Mv*hv - p*Vt + (Mmd + Mmdcr)*cm*Ts "Total energy";
-    Ts = sat.Tsat "Saturation temperature";
-    der(M) = qf - qs "Mass balance";
-    der(E) = Q + qf*hf - qs*hv "Energy balance";
-    Vl = Vld + Vdcr "Liquid volume";
-    Vt = Vd + Vdcr "Total volume";
-    Vt = Vl + Vv "Total volume";
-
-    // Boundary conditions
-    p = feed.p;
-    p = steam.p;
-    hf = homotopy(if not allowFlowReversal then inStream(feed.h_outflow) else
-      actualStream(feed.h_outflow), inStream(feed.h_outflow));
-    feed.m_flow = qf;
-    -steam.m_flow = qs;
-    feed.h_outflow = hl;
-    steam.h_outflow = hv;
-    Q = heat.Q_flow;
-    heat.T = Ts;
-
-    // Fluid properties
-    sat.psat = p;
-    sat.Tsat = Medium.saturationTemperature(p);
-    rhol = Medium.bubbleDensity(sat);
-    rhov = Medium.dewDensity(sat);
-    hl = Medium.bubbleEnthalpy(sat);
-    hv = Medium.dewEnthalpy(sat);
-  initial equation
-    if initOpt == Choices.Init.Options.noInit then
-      // do nothing
-    elseif initOpt == Choices.Init.Options.fixedState then
-      if not noInitialPressure then
-        p = pstart;
-      end if;
-      Vld = Vldstart;
-    elseif initOpt == Choices.Init.Options.steadyState then
-      if not noInitialPressure then
-        der(p) = 0;
-      end if;
-      der(Vld) = 0;
-    else
-      assert(false, "Unsupported initialisation option");
-    end if;
-    annotation (
-      Diagram(graphics),
-      Documentation(info="<HTML>
+</html>"));
+    end EvaporatorBase;
+  end BaseClasses;
+
+  model Drum2States
+    extends Icons.Water.Drum;
+    extends Modelica.Icons.ObsoleteModel;
+    replaceable package Medium = StandardWater constrainedby Modelica.Media.Interfaces.PartialTwoPhaseMedium "Medium model" annotation(
+       choicesAllMatching = true);
+    parameter SI.Volume Vd "Drum volume";
+    parameter SI.Volume Vdcr "Volume of downcomer and risers";
+    parameter SI.Mass Mmd "Drum metal mass";
+    parameter SI.Mass Mmdcr "Metal mass of downcomer and risers";
+    parameter Medium.SpecificHeatCapacity cm "Specific heat capacity of the metal";
+    parameter Boolean allowFlowReversal = system.allowFlowReversal "= true to allow flow reversal, false restricts to design direction" annotation(
+      Evaluate = true);
+    outer ThermoPower.System system "System wide properties";
+    parameter SI.Pressure pstart "Pressure start value" annotation(
+      Dialog(tab = "Initialisation"));
+    parameter SI.Volume Vldstart "Start value of drum water volume" annotation(
+      Dialog(tab = "Initialisation"));
+    parameter Choices.Init.Options initOpt = system.initOpt "Initialisation option" annotation(
+      Dialog(tab = "Initialisation"));
+    parameter Boolean noInitialPressure = false "Remove initial equation on pressure" annotation(
+      Dialog(tab = "Initialisation"),
+      choices(checkBox = true));
+    Medium.SaturationProperties sat "Saturation conditions";
+    FlangeA feed(redeclare package Medium = Medium, m_flow(min = if allowFlowReversal then -Modelica.Constants.inf else 0)) annotation(
+      Placement(transformation(extent = {{-110, -64}, {-70, -24}}, rotation = 0)));
+    FlangeB steam(redeclare package Medium = Medium, m_flow(max = if allowFlowReversal then +Modelica.Constants.inf else 0)) annotation(
+      Placement(transformation(extent = {{48, 52}, {88, 92}}, rotation = 0)));
+    Modelica.Thermal.HeatTransfer.Interfaces.HeatPort_a heat "Metal wall thermal port" annotation(
+      Placement(transformation(extent = {{-28, -100}, {28, -80}}, rotation = 0)));
+    SI.Mass Ml "Liquid water mass";
+    SI.Mass Mv "Steam mass";
+    SI.Mass M "Total liquid+steam mass";
+    SI.Energy E "Total energy";
+    SI.Volume Vt "Total volume";
+    SI.Volume Vl(start = Vldstart + Vdcr) "Liquid water total volume";
+    SI.Volume Vld(start = Vldstart, stateSelect = StateSelect.prefer) "Liquid water volume in the drum";
+    SI.Volume Vv "Steam volume";
+    Medium.AbsolutePressure p(start = pstart, stateSelect = StateSelect.prefer) "Drum pressure";
+    Medium.MassFlowRate qf "Feedwater mass flowrate";
+    Medium.MassFlowRate qs "Steam mass flowrate";
+    SI.HeatFlowRate Q "Heat flow to the risers";
+    Medium.SpecificEnthalpy hf "Feedwater specific enthalpy";
+    Medium.SpecificEnthalpy hl "Specific enthalpy of saturated liquid";
+    Medium.SpecificEnthalpy hv "Specific enthalpy of saturated steam";
+    Medium.Temperature Ts "Saturation temperature";
+    Units.LiquidDensity rhol "Density of saturated liquid";
+    Units.GasDensity rhov "Density of saturated steam";
+  equation
+    Ml = Vl * rhol "Mass of liquid";
+    Mv = Vv * rhov "Mass of vapour";
+    M = Ml + Mv "Total mass";
+    E = Ml * hl + Mv * hv - p * Vt + (Mmd + Mmdcr) * cm * Ts "Total energy";
+    Ts = sat.Tsat "Saturation temperature";
+    der(M) = qf - qs "Mass balance";
+    der(E) = Q + qf * hf - qs * hv "Energy balance";
+    Vl = Vld + Vdcr "Liquid volume";
+    Vt = Vd + Vdcr "Total volume";
+    Vt = Vl + Vv "Total volume";
+// Boundary conditions
+    p = feed.p;
+    p = steam.p;
+    hf = homotopy(if not allowFlowReversal then inStream(feed.h_outflow) else actualStream(feed.h_outflow), inStream(feed.h_outflow));
+    feed.m_flow = qf;
+    -steam.m_flow = qs;
+    feed.h_outflow = hl;
+    steam.h_outflow = hv;
+    Q = heat.Q_flow;
+    heat.T = Ts;
+// Fluid properties
+    sat.psat = p;
+    sat.Tsat = Medium.saturationTemperature(p);
+    rhol = Medium.bubbleDensity(sat);
+    rhov = Medium.dewDensity(sat);
+    hl = Medium.bubbleEnthalpy(sat);
+    hv = Medium.dewEnthalpy(sat);
+  initial equation
+    if initOpt == Choices.Init.Options.noInit then
+// do nothing
+    elseif initOpt == Choices.Init.Options.fixedState then
+      if not noInitialPressure then
+        p = pstart;
+      end if;
+      Vld = Vldstart;
+    elseif initOpt == Choices.Init.Options.steadyState then
+      if not noInitialPressure then
+        der(p) = 0;
+      end if;
+      der(Vld) = 0;
+    else
+      assert(false, "Unsupported initialisation option");
+    end if;
+    annotation(
+      Diagram(graphics),
+      Documentation(info = "<HTML>
 <p>Simplified model of a drum for drum boilers. This model assumes thermodynamic equilibrium between the liquid and vapour volumes. The model has two state variables (i.e., pressure and liquid volume).
-</HTML>", revisions="<html>
+</HTML>", revisions = "<html>
 <ul>
 <li><i>30 May 2005</i>
     by <a href=\"mailto:francesco.casella@polimi.it\">Francesco Casella</a>:<br>
@@ -6420,189 +4978,156 @@
     by <a href=\"mailto:francesco.casella@polimi.it\">Francesco Casella</a>:<br>
        First release.</li>
 </ul>
-</html>"),
-      Icon(graphics));
-  end Drum2States;
-
-  model Flow1D
-    "1-dimensional fluid flow model for water/steam (finite volumes)"
-    extends BaseClasses.Flow1DBase;
-    extends Modelica.Icons.ObsoleteModel;
-    replaceable ThermoPower.Thermal.DHT wall(N=N) annotation (Dialog(enable=
-            false), Placement(transformation(extent={{-40,40},{40,60}},
-            rotation=0)));
-    import ThermoPower.Choices.Flow1D.FFtypes;
-    import ThermoPower.Choices.Flow1D.HCtypes;
-    Medium.ThermodynamicState fluidState[N]
-      "Thermodynamic state of the fluid at the nodes";
-    SI.Length omega_hyd "Wet perimeter (single tube)";
-    SI.Pressure Dpfric "Pressure drop due to friction (total)";
-    SI.Pressure Dpfric1
-      "Pressure drop due to friction (from inlet to capacitance)";
-    SI.Pressure Dpfric2
-      "Pressure drop due to friction (from capacitance to outlet)";
-    SI.Pressure Dpstat "Pressure drop due to static head";
-    SI.MassFlowRate win "Flow rate at the inlet (single tube)";
-    SI.MassFlowRate wout "Flow rate at the outlet (single tube)";
-    Real Kf "Hydraulic friction coefficient";
-    Real dwdt "Dynamic momentum term";
-    Real Cf "Fanning friction factor";
-    Medium.AbsolutePressure p(start=pstart)
-      "Fluid pressure for property calculations";
-    SI.MassFlowRate w(start=wnom/Nt) "Mass flowrate (single tube)";
-    SI.MassFlowRate wbar[N - 1](each start=wnom/Nt);
-    SI.Velocity u[N] "Fluid velocity";
-    Medium.Temperature T[N] "Fluid temperature";
-    Medium.SpecificEnthalpy h[N](start=hstart)
-      "Fluid specific enthalpy at the nodes";
-    Medium.SpecificEnthalpy htilde[N - 1](start=hstart[2:N])
-      "Enthalpy state variables";
-    Medium.Density rho[N] "Fluid nodal density";
-    SI.Mass M "Fluid mass";
-    Real dMdt[N - 1] "Time derivative of mass in each cell between two nodes";
-  protected
-    SI.Density rhobar[N - 1] "Fluid average density";
-    SI.SpecificVolume vbar[N - 1] "Fluid average specific volume";
-    SI.HeatFlux phibar[N - 1] "Average heat flux";
-    SI.DerDensityByEnthalpy drdh[N] "Derivative of density by enthalpy";
-    SI.DerDensityByEnthalpy drbdh[N - 1]
-      "Derivative of average density by enthalpy";
-    SI.DerDensityByPressure drdp[N] "Derivative of density by pressure";
-    SI.DerDensityByPressure drbdp[N - 1]
-      "Derivative of average density by pressure";
-  equation
-    //All equations are referred to a single tube
-    // Friction factor selection
-    omega_hyd = 4*A/Dhyd;
-    if FFtype == FFtypes.Kfnom then
-      Kf = Kfnom*Kfc;
-    elseif FFtype == FFtypes.OpPoint then
-      Kf = dpnom*rhonom/(wnom/Nt)^2*Kfc;
-    elseif FFtype == FFtypes.Cfnom then
-      Cf = Cfnom*Kfc;
-    elseif FFtype == FFtypes.Colebrook then
-      Cf = f_colebrook(
-          w,
-          Dhyd/A,
-          e,
-          Medium.dynamicViscosity(fluidState[integer(N/2)]))*Kfc;
-    elseif FFtype == FFtypes.NoFriction then
-      Cf = 0;
-    end if;
-    Kf = Cf*omega_hyd*L/(2*A^3)
-      "Relationship between friction coefficient and Fanning friction factor";
-    assert(Kf >= 0, "Negative friction coefficient");
-
-    // Dynamic momentum term
-    if DynamicMomentum then
-      dwdt = der(w);
-    else
-      dwdt = 0;
-    end if;
-
-    sum(dMdt) = (infl.m_flow + outfl.m_flow)/Nt "Mass balance";
-    L/A*dwdt + (outfl.p - infl.p) + Dpstat + Dpfric = 0 "Momentum balance";
-    Dpfric = Dpfric1 + Dpfric2 "Total pressure drop due to friction";
-    if FFtype == FFtypes.NoFriction then
-      Dpfric1 = 0;
-      Dpfric2 = 0;
-    elseif HydraulicCapacitance == HCtypes.Middle then
-      //assert((N-1)-integer((N-1)/2)*2 == 0, "N must be odd");
-      Dpfric1 = homotopy(Kf*squareReg(win, wnom/Nt*wnf)*sum(vbar[1:integer((N
-         - 1)/2)])/(N - 1), dpnom/2/(wnom/Nt)*win)
-        "Pressure drop from inlet to capacitance";
-      Dpfric2 = homotopy(Kf*squareReg(wout, wnom/Nt*wnf)*sum(vbar[1 + integer((
-        N - 1)/2):N - 1])/(N - 1), dpnom/2/(wnom/Nt)*wout)
-        "Pressure drop from capacitance to outlet";
-    elseif HydraulicCapacitance == HCtypes.Upstream then
-      Dpfric1 = 0 "Pressure drop from inlet to capacitance";
-      Dpfric2 = homotopy(Kf*squareReg(wout, wnom/Nt*wnf)*sum(vbar)/(N - 1),
-        dpnom/(wnom/Nt)*wout) "Pressure drop from capacitance to outlet";
-    elseif HydraulicCapacitance == HCtypes.Downstream then
-      Dpfric1 = homotopy(Kf*squareReg(win, wnom/Nt*wnf)*sum(vbar)/(N - 1),
-        dpnom/(wnom/Nt)*win) "Pressure drop from inlet to capacitance";
-      Dpfric2 = 0 "Pressure drop from capacitance to outlet";
-    else
-      assert(false, "Unsupported HydraulicCapacitance option");
-    end if "Pressure drop due to friction";
-    Dpstat = if abs(dzdx) < 1e-6 then 0 else g*l*dzdx*sum(rhobar)
-      "Pressure drop due to static head";
-    for j in 1:N - 1 loop
-      if Medium.singleState then
-        A*l*rhobar[j]*der(htilde[j]) + wbar[j]*(h[j + 1] - h[j]) = l*omega*
-          phibar[j] "Energy balance (pressure effects neglected)";
-      else
-        A*l*rhobar[j]*der(htilde[j]) + wbar[j]*(h[j + 1] - h[j]) - A*l*der(p) =
-          l*omega*phibar[j] "Energy balance";
-      end if;
-      dMdt[j] = A*l*(drbdh[j]*der(htilde[j]) + drbdp[j]*der(p))
-        "Mass derivative for each volume";
-      // Average volume quantities
-      rhobar[j] = (rho[j] + rho[j + 1])/2;
-      drbdp[j] = (drdp[j] + drdp[j + 1])/2;
-      drbdh[j] = (drdh[j] + drdh[j + 1])/2;
-      vbar[j] = 1/rhobar[j];
-      wbar[j] = homotopy(infl.m_flow/Nt - sum(dMdt[1:j - 1]) - dMdt[j]/2, wnom/
-        Nt);
-    end for;
-
-    // Fluid property calculations
-    for j in 1:N loop
-      fluidState[j] = Medium.setState_phX(p, h[j]);
-      T[j] = Medium.temperature(fluidState[j]);
-      rho[j] = Medium.density(fluidState[j]);
-      drdp[j] = if Medium.singleState then 0 else Medium.density_derp_h(
-        fluidState[j]);
-      drdh[j] = Medium.density_derh_p(fluidState[j]);
-      u[j] = w/(rho[j]*A);
-    end for;
-
-    // Boundary conditions
-    win = infl.m_flow/Nt;
-    wout = -outfl.m_flow/Nt;
-    if HydraulicCapacitance == HCtypes.Middle then
-      p = infl.p - Dpfric1 - Dpstat/2;
-      w = win;
-    elseif HydraulicCapacitance == HCtypes.Upstream then
-      p = infl.p;
-      w = -outfl.m_flow/Nt;
-    elseif HydraulicCapacitance == HCtypes.Downstream then
-      p = outfl.p;
-      w = win;
-    else
-      assert(false, "Unsupported HydraulicCapacitance option");
-    end if;
-    infl.h_outflow = htilde[1];
-    outfl.h_outflow = htilde[N - 1];
-
-    h[1] = inStream(infl.h_outflow);
-    h[2:N] = htilde;
-
-    T = wall.T;
-    phibar = (wall.phi[1:N - 1] + wall.phi[2:N])/2;
-
-    Q = Nt*l*omega*sum(phibar) "Total heat flow through lateral boundary";
-    M = sum(rhobar)*A*l "Total fluid mass";
-    Tr = noEvent(M/max(win, Modelica.Constants.eps)) "Residence time";
-  initial equation
-    if initOpt == Choices.Init.Options.noInit then
-      // do nothing
-    elseif initOpt == Choices.Init.Options.steadyState then
-      der(htilde) = zeros(N - 1);
-      if (not Medium.singleState) then
-        der(p) = 0;
-      end if;
-    elseif initOpt == Choices.Init.Options.steadyStateNoP then
-      der(htilde) = zeros(N - 1);
-    elseif initOpt == Choices.Init.Options.steadyStateNoT and not Medium.singleState then
-      der(p) = 0;
-    else
-      assert(false, "Unsupported initialisation option");
-    end if;
-    annotation (
-      Diagram(graphics),
-      Icon(graphics={Text(extent={{-100,-52},{100,-80}}, textString="%name")}),
-      Documentation(info="<HTML>
+</html>"),
+      Icon(graphics));
+  end Drum2States;
+
+  model Flow1D "1-dimensional fluid flow model for water/steam (finite volumes)"
+    extends BaseClasses.Flow1DBase;
+    extends Modelica.Icons.ObsoleteModel;
+    replaceable ThermoPower.Thermal.DHT wall(N = N) annotation(
+      Dialog(enable = false),
+      Placement(transformation(extent = {{-40, 40}, {40, 60}}, rotation = 0)));
+    import ThermoPower.Choices.Flow1D.FFtypes;
+    import ThermoPower.Choices.Flow1D.HCtypes;
+    Medium.ThermodynamicState fluidState[N] "Thermodynamic state of the fluid at the nodes";
+    SI.Length omega_hyd "Wet perimeter (single tube)";
+    SI.Pressure Dpfric "Pressure drop due to friction (total)";
+    SI.Pressure Dpfric1 "Pressure drop due to friction (from inlet to capacitance)";
+    SI.Pressure Dpfric2 "Pressure drop due to friction (from capacitance to outlet)";
+    SI.Pressure Dpstat "Pressure drop due to static head";
+    SI.MassFlowRate win "Flow rate at the inlet (single tube)";
+    SI.MassFlowRate wout "Flow rate at the outlet (single tube)";
+    Real Kf "Hydraulic friction coefficient";
+    Real dwdt "Dynamic momentum term";
+    Real Cf "Fanning friction factor";
+    Medium.AbsolutePressure p(start = pstart) "Fluid pressure for property calculations";
+    SI.MassFlowRate w(start = wnom / Nt) "Mass flowrate (single tube)";
+    SI.MassFlowRate wbar[N - 1](each start = wnom / Nt);
+    SI.Velocity u[N] "Fluid velocity";
+    Medium.Temperature T[N] "Fluid temperature";
+    Medium.SpecificEnthalpy h[N](start = hstart) "Fluid specific enthalpy at the nodes";
+    Medium.SpecificEnthalpy htilde[N - 1](start = hstart[2:N]) "Enthalpy state variables";
+    Medium.Density rho[N] "Fluid nodal density";
+    SI.Mass M "Fluid mass";
+    Real dMdt[N - 1] "Time derivative of mass in each cell between two nodes";
+  protected
+    SI.Density rhobar[N - 1] "Fluid average density";
+    SI.SpecificVolume vbar[N - 1] "Fluid average specific volume";
+    SI.HeatFlux phibar[N - 1] "Average heat flux";
+    SI.DerDensityByEnthalpy drdh[N] "Derivative of density by enthalpy";
+    SI.DerDensityByEnthalpy drbdh[N - 1] "Derivative of average density by enthalpy";
+    SI.DerDensityByPressure drdp[N] "Derivative of density by pressure";
+    SI.DerDensityByPressure drbdp[N - 1] "Derivative of average density by pressure";
+  equation
+//All equations are referred to a single tube
+// Friction factor selection
+    omega_hyd = 4 * A / Dhyd;
+    if FFtype == FFtypes.Kfnom then
+      Kf = Kfnom * Kfc;
+    elseif FFtype == FFtypes.OpPoint then
+      Kf = dpnom * rhonom / (wnom / Nt) ^ 2 * Kfc;
+    elseif FFtype == FFtypes.Cfnom then
+      Cf = Cfnom * Kfc;
+    elseif FFtype == FFtypes.Colebrook then
+      Cf = f_colebrook(w, Dhyd / A, e, Medium.dynamicViscosity(fluidState[integer(N / 2)])) * Kfc;
+    elseif FFtype == FFtypes.NoFriction then
+      Cf = 0;
+    end if;
+    Kf = Cf * omega_hyd * L / (2 * A ^ 3) "Relationship between friction coefficient and Fanning friction factor";
+    assert(Kf >= 0, "Negative friction coefficient");
+// Dynamic momentum term
+    if DynamicMomentum then
+      dwdt = der(w);
+    else
+      dwdt = 0;
+    end if;
+    sum(dMdt) = (infl.m_flow + outfl.m_flow) / Nt "Mass balance";
+    L / A * dwdt + outfl.p - infl.p + Dpstat + Dpfric = 0 "Momentum balance";
+    Dpfric = Dpfric1 + Dpfric2 "Total pressure drop due to friction";
+    if FFtype == FFtypes.NoFriction then
+      Dpfric1 = 0;
+      Dpfric2 = 0;
+    elseif HydraulicCapacitance == HCtypes.Middle then
+//assert((N-1)-integer((N-1)/2)*2 == 0, "N must be odd");
+      Dpfric1 = homotopy(Kf * squareReg(win, wnom / Nt * wnf) * sum(vbar[1:integer((N - 1) / 2)]) / (N - 1), dpnom / 2 / (wnom / Nt) * win) "Pressure drop from inlet to capacitance";
+      Dpfric2 = homotopy(Kf * squareReg(wout, wnom / Nt * wnf) * sum(vbar[1 + integer((N - 1) / 2):N - 1]) / (N - 1), dpnom / 2 / (wnom / Nt) * wout) "Pressure drop from capacitance to outlet";
+    elseif HydraulicCapacitance == HCtypes.Upstream then
+      Dpfric1 = 0 "Pressure drop from inlet to capacitance";
+      Dpfric2 = homotopy(Kf * squareReg(wout, wnom / Nt * wnf) * sum(vbar) / (N - 1), dpnom / (wnom / Nt) * wout) "Pressure drop from capacitance to outlet";
+    elseif HydraulicCapacitance == HCtypes.Downstream then
+      Dpfric1 = homotopy(Kf * squareReg(win, wnom / Nt * wnf) * sum(vbar) / (N - 1), dpnom / (wnom / Nt) * win) "Pressure drop from inlet to capacitance";
+      Dpfric2 = 0 "Pressure drop from capacitance to outlet";
+    else
+      assert(false, "Unsupported HydraulicCapacitance option");
+    end if "Pressure drop due to friction";
+    Dpstat = if abs(dzdx) < 1e-6 then 0 else g * l * dzdx * sum(rhobar) "Pressure drop due to static head";
+    for j in 1:N - 1 loop
+      if Medium.singleState then
+        A * l * rhobar[j] * der(htilde[j]) + wbar[j] * (h[j + 1] - h[j]) = l * omega * phibar[j] "Energy balance (pressure effects neglected)";
+      else
+        A * l * rhobar[j] * der(htilde[j]) + wbar[j] * (h[j + 1] - h[j]) - A * l * der(p) = l * omega * phibar[j] "Energy balance";
+      end if;
+      dMdt[j] = A * l * (drbdh[j] * der(htilde[j]) + drbdp[j] * der(p)) "Mass derivative for each volume";
+// Average volume quantities
+      rhobar[j] = (rho[j] + rho[j + 1]) / 2;
+      drbdp[j] = (drdp[j] + drdp[j + 1]) / 2;
+      drbdh[j] = (drdh[j] + drdh[j + 1]) / 2;
+      vbar[j] = 1 / rhobar[j];
+      wbar[j] = homotopy(infl.m_flow / Nt - sum(dMdt[1:j - 1]) - dMdt[j] / 2, wnom / Nt);
+    end for;
+// Fluid property calculations
+    for j in 1:N loop
+      fluidState[j] = Medium.setState_phX(p, h[j]);
+      T[j] = Medium.temperature(fluidState[j]);
+      rho[j] = Medium.density(fluidState[j]);
+      drdp[j] = if Medium.singleState then 0 else Medium.density_derp_h(fluidState[j]);
+      drdh[j] = Medium.density_derh_p(fluidState[j]);
+      u[j] = w / (rho[j] * A);
+    end for;
+// Boundary conditions
+    win = infl.m_flow / Nt;
+    wout = -outfl.m_flow / Nt;
+    if HydraulicCapacitance == HCtypes.Middle then
+      p = infl.p - Dpfric1 - Dpstat / 2;
+      w = win;
+    elseif HydraulicCapacitance == HCtypes.Upstream then
+      p = infl.p;
+      w = -outfl.m_flow / Nt;
+    elseif HydraulicCapacitance == HCtypes.Downstream then
+      p = outfl.p;
+      w = win;
+    else
+      assert(false, "Unsupported HydraulicCapacitance option");
+    end if;
+    infl.h_outflow = htilde[1];
+    outfl.h_outflow = htilde[N - 1];
+    h[1] = inStream(infl.h_outflow);
+    h[2:N] = htilde;
+    T = wall.T;
+    phibar = (wall.phi[1:N - 1] + wall.phi[2:N]) / 2;
+    Q = Nt * l * omega * sum(phibar) "Total heat flow through lateral boundary";
+    M = sum(rhobar) * A * l "Total fluid mass";
+    Tr = noEvent(M / max(win, Modelica.Constants.eps)) "Residence time";
+  initial equation
+    if initOpt == Choices.Init.Options.noInit then
+// do nothing
+    elseif initOpt == Choices.Init.Options.steadyState then
+      der(htilde) = zeros(N - 1);
+      if not Medium.singleState then
+        der(p) = 0;
+      end if;
+    elseif initOpt == Choices.Init.Options.steadyStateNoP then
+      der(htilde) = zeros(N - 1);
+    elseif initOpt == Choices.Init.Options.steadyStateNoT and not Medium.singleState then
+      der(p) = 0;
+    else
+      assert(false, "Unsupported initialisation option");
+    end if;
+    annotation(
+      Diagram(graphics),
+      Icon(graphics = {Text(extent = {{-100, -52}, {100, -80}}, textString = "%name")}),
+      Documentation(info = "<HTML>
 <p>This model describes the flow of water or steam in a rigid tube. The basic modelling assumptions are:
 <ul><li>The fluid state is always one-phase (i.e. subcooled liquid or superheated steam).
 <li>Uniform velocity is assumed on the cross section, leading to a 1-D distributed parameter model.
@@ -6630,7 +5155,7 @@
 <p>Start values for the pressure and flowrate state variables are specified by <tt>pstart</tt>, <tt>wstart</tt>. The start values for the node enthalpies are linearly distributed from <tt>hstartin</tt> at the inlet to <tt>hstartout</tt> at the outlet.
 <p>A bank of <tt>Nt</tt> identical tubes working in parallel can be modelled by setting <tt>Nt > 1</tt>. The geometric parameters always refer to a <i>single</i> tube.
 <p>This models makes the temperature and external heat flow distributions available to connected components through the <tt>wall</tt> connector. If other variables (e.g. the heat transfer coefficient) are needed by external components to compute the actual heat flow, the <tt>wall</tt> connector can be replaced by an extended version of the <tt>DHT</tt> connector.
-</HTML>", revisions="<html>
+</HTML>", revisions = "<html>
 <ul>
 <li><i>16 Sep 2005</i>
     by <a href=\"mailto:francesco.casella@polimi.it\">Francesco Casella</a>:<br>
@@ -6661,37 +5186,31 @@
        First release.</li>
 </ul>
 </html>
-"));
-  end Flow1D;
-
-  model Flow1DDB
-    "1-dimensional fluid flow model for water or steam flow (finite volumes, Dittus-Boelter heat transfer)"
-    extends Flow1D(redeclare Thermal.DHThtc wall);
-    Medium.DynamicViscosity mu[N] "Dynamic viscosity";
-    Medium.ThermalConductivity k[N] "Thermal conductivity";
-    Medium.SpecificHeatCapacity cp[N] "Heat capacity at constant pressure";
-  equation
-    for j in 1:N loop
-      // Additional fluid properties
-      mu[j] = Medium.dynamicViscosity(fluidState[j]);
-      k[j] = Medium.thermalConductivity(fluidState[j]);
-      cp[j] = Medium.heatCapacity_cp(fluidState[j]);
-      wall.gamma[j] = f_dittus_boelter(
-          w,
-          Dhyd,
-          A,
-          mu[j],
-          k[j],
-          cp[j]) "Heat transfer on the wall connector";
-    end for;
-    annotation (Documentation(info="<HTML>
+      "));
+  end Flow1D;
+
+  model Flow1DDB "1-dimensional fluid flow model for water or steam flow (finite volumes, Dittus-Boelter heat transfer)"
+    extends Flow1D(redeclare Thermal.DHThtc wall);
+    Medium.DynamicViscosity mu[N] "Dynamic viscosity";
+    Medium.ThermalConductivity k[N] "Thermal conductivity";
+    Medium.SpecificHeatCapacity cp[N] "Heat capacity at constant pressure";
+  equation
+    for j in 1:N loop
+// Additional fluid properties
+      mu[j] = Medium.dynamicViscosity(fluidState[j]);
+      k[j] = Medium.thermalConductivity(fluidState[j]);
+      cp[j] = Medium.heatCapacity_cp(fluidState[j]);
+      wall.gamma[j] = f_dittus_boelter(w, Dhyd, A, mu[j], k[j], cp[j]) "Heat transfer on the wall connector";
+    end for;
+    annotation(
+      Documentation(info = "<HTML>
 <p>This model extends <tt>Flow1D</tt> by computing the distribution of the heat transfer coefficient <tt>gamma</tt> and making it available through an extended version of the <tt>wall</tt> connector.
 <p>This model can be used in the case of one-phase water or steam flow. Dittus-Boelter's equation [1] is used to compute the heat transfer coefficient.
 <p><b>References:</b></p>
 <ol>
 <li>J. C. Collier: <i>Convective Boiling and Condensation</i>, 2nd ed.,McGraw Hill, 1981, pp. 146.
 </ol>
-</HTML>", revisions="<html>
+</HTML>", revisions = "<html>
 <ul>
 <li><i>24 Mar 2005</i>
     by <a href=\"mailto:francesco.casella@polimi.it\">Francesco Casella</a>:<br>
@@ -6709,301 +5228,228 @@
     by <a href=\"mailto:francesco.casella@polimi.it\">Francesco Casella</a>:<br>
        First release.</li>
 </ul>
-</html>"));
-  end Flow1DDB;
-
-  model Flow1D2ph
-    "1-dimensional fluid flow model for water/steam (finite volumes, 2-phase)"
-    extends Modelica.Icons.ObsoleteModel;
-    extends BaseClasses.Flow1DBase(redeclare replaceable package Medium =
-          StandardWater                constrainedby
-        Modelica.Media.Interfaces.PartialTwoPhaseMedium
-                        "Medium model",
-        FluidPhaseStart=Choices.FluidPhase.FluidPhases.TwoPhases);
-    replaceable ThermoPower.Thermal.DHT wall(N=N) annotation (Dialog(enable=
-            false), Placement(transformation(extent={{-40,40},{40,60}},
-            rotation=0)));
-    import ThermoPower.Choices.Flow1D.FFtypes;
-    import ThermoPower.Choices.Flow1D.HCtypes;
-    // package SmoothMedium = Medium (final smoothModel=true);
-    constant SI.Pressure pzero=10 "Small deltap for calculations";
-    constant SI.Pressure pc=Medium.fluidConstants[1].criticalPressure;
-    constant SI.SpecificEnthalpy hzero=1e-3 "Small value for deltah";
-    // SmoothMedium.ThermodynamicState fluidState[N]
-    //   "Thermodynamic state of the fluid at the nodes";
-    Medium.ThermodynamicState fluidState[N]
-      "Thermodynamic state of the fluid at the nodes";
-    Medium.SaturationProperties sat "Properties of saturated fluid";
-    SI.Length omega_hyd "Wet perimeter (single tube)";
-    SI.Pressure Dpfric "Pressure drop due to friction";
-    SI.Pressure Dpstat "Pressure drop due to static head";
-    Real Kf[N - 1] "Friction coefficient";
-    Real Kfl[N - 1] "Linear friction coefficient";
-    Real Cf[N - 1] "Fanning friction factor";
-    Real dwdt "Dynamic momentum term";
-    Medium.AbsolutePressure p(start=pstart, stateSelect=StateSelect.prefer)
-      "Fluid pressure for property calculations";
-    SI.Pressure dpf[N - 1] "Pressure drop due to friction between two nodes";
-    SI.MassFlowRate w(start=wnom/Nt) "Mass flowrate (single tube)";
-    SI.MassFlowRate wbar[N - 1](each start=wnom/Nt);
-    SI.Velocity u[N] "Fluid velocity";
-    Medium.Temperature T[N] "Fluid temperature";
-    Medium.Temperature Ts "Saturated water temperature";
-    Medium.SpecificEnthalpy h[N](start=hstart) "Fluid specific enthalpy";
-    Medium.SpecificEnthalpy htilde[N - 1](start=hstart[2:N],
-                                          each stateSelect=StateSelect.prefer)
-      "Enthalpy state variables";
-    Medium.SpecificEnthalpy hl "Saturated liquid temperature";
-    Medium.SpecificEnthalpy hv "Saturated vapour temperature";
-    Real x[N] "Steam quality";
-    Medium.Density rho[N] "Fluid density";
-    Units.LiquidDensity rhol "Saturated liquid density";
-    Units.GasDensity rhov "Saturated vapour density";
-    SI.Mass M "Fluid mass";
-    SI.Power Qj[N-1];  //DA CANCELLARE
-  protected
-    SI.DerEnthalpyByPressure dhldp
-      "Derivative of saturated liquid enthalpy by pressure";
-    SI.DerEnthalpyByPressure dhvdp
-      "Derivative of saturated vapour enthalpy by pressure";
-    SI.Density rhobar[N - 1] "Fluid average density";
-    SI.DerDensityByPressure drdp[N] "Derivative of density by pressure";
-    SI.DerDensityByPressure drbdp[N - 1]
-      "Derivative of average density by pressure";
-    SI.DerDensityByPressure drldp
-      "Derivative of saturated liquid density by pressure";
-    SI.DerDensityByPressure drvdp
-      "Derivative of saturated vapour density by pressure";
-    SI.SpecificVolume vbar[N - 1] "Average specific volume";
-    SI.HeatFlux phibar[N - 1] "Average heat flux";
-    SI.DerDensityByEnthalpy drdh[N] "Derivative of density by enthalpy";
-    SI.DerDensityByEnthalpy drbdh1[N - 1]
-      "Derivative of average density by left enthalpy";
-    SI.DerDensityByEnthalpy drbdh2[N - 1]
-      "Derivative of average density by right enthalpy";
-    Real AA;
-    Real AA1;
-    Real dMdt[N - 1] "Derivative of fluid mass in each volume";
-  equation
-    //All equations are referred to a single tube
-    omega_hyd = 4*A/Dhyd;
-    // Friction factor selection
-    for j in 1:(N - 1) loop
-      if FFtype == FFtypes.Kfnom then
-        Kf[j] = Kfnom*Kfc/(N - 1);
-        Cf[j] = 2*Kf[j]*A^3/(omega_hyd*l);
-      elseif FFtype == FFtypes.OpPoint then
-        Kf[j] = dpnom*rhonom/(wnom/Nt)^2/(N - 1)*Kfc;
-        Cf[j] = 2*Kf[j]*A^3/(omega_hyd*l);
-      elseif FFtype == FFtypes.Cfnom then
-        Kf[j] = Cfnom*omega_hyd*l/(2*A^3)*Kfc;
-        Cf[j] = 2*Kf[j]*A^3/(omega_hyd*l);
-      elseif FFtype == FFtypes.Colebrook then
-        Cf[j] = if noEvent(htilde[j] < hl or htilde[j] > hv) then f_colebrook(
-            w,
-            Dhyd/A,
-            e,
-            Medium.dynamicViscosity(fluidState[j]))*Kfc else f_colebrook_2ph(
-            w,
-            Dhyd/A,
-            e,
-            Medium.dynamicViscosity(Medium.setBubbleState(sat, 1)),
-            Medium.dynamicViscosity(Medium.setDewState(sat, 1)),
-            x[j])*Kfc;
-        Kf[j] = Cf[j]*omega_hyd*l/(2*A^3);
-      elseif FFtype == FFtypes.NoFriction then
-        Cf[j] = 0;
-        Kf[j] = 0;
-      else
-        assert(FFtype <> FFtypes.NoFriction, "Unsupported FFtype");
-        Cf[j] = 0;
-        Kf[j] = 0;
-      end if;
-      assert(Kf[j] >= 0, "Negative friction coefficient");
-      Kfl[j] = wnom/Nt*wnf*Kf[j];
-    end for;
-
-    // Dynamic momentum term
-    if DynamicMomentum then
-      dwdt = der(w);
-    else
-      dwdt = 0;
-    end if;
-
-    sum(dMdt) = (infl.m_flow/Nt + outfl.m_flow/Nt) "Mass balance";
-    sum(dpf) = Dpfric "Total pressure drop due to friction";
-    Dpstat = if abs(dzdx) < 1e-6 then 0 else g*l*dzdx*sum(rhobar)
-      "Pressure drop due to static head";
-    L/A*dwdt + (outfl.p - infl.p) + Dpstat + Dpfric = 0 "Momentum balance";
-    for j in 1:(N - 1) loop
-      A*l*rhobar[j]*der(htilde[j]) + wbar[j]*(h[j + 1] - h[j]) - A*l*der(p) = l
-        *omega*phibar[j] "Energy balance";
-      Qj[j] = l*omega*phibar[j];
-      dMdt[j] = A*l*(drbdh1[j]*der(h[j]) + drbdh2[j]*der(h[j + 1]) + drbdp[j]*
-        der(p)) "Mass balance for each volume";
-      // Average volume quantities
-      vbar[j] = 1/rhobar[j] "Average specific volume";
-      wbar[j] = homotopy(infl.m_flow/Nt - sum(dMdt[1:j - 1]) - dMdt[j]/2, wnom/
-        Nt);
-      dpf[j] = (if FFtype == FFtypes.NoFriction then 0 else homotopy(smooth(1,
-        Kf[j]*squareReg(w, wnom/Nt*wnf))*vbar[j], dpnom/(N - 1)/(wnom/Nt)*w));
-      if avoidInletEnthalpyDerivative and j == 1 then
-        // first volume properties computed by the outlet properties
-        rhobar[j] = rho[j + 1];
-        drbdp[j] = drdp[j + 1];
-        drbdh1[j] = 0;
-        drbdh2[j] = drdh[j + 1];
-      elseif noEvent((h[j] < hl and h[j + 1] < hl) or (h[j] > hv and h[j + 1]
-           > hv) or p >= (pc - pzero) or abs(h[j + 1] - h[j]) < hzero) then
-        // 1-phase or almost uniform properties
-        rhobar[j] = (rho[j] + rho[j + 1])/2;
-        drbdp[j] = (drdp[j] + drdp[j + 1])/2;
-        drbdh1[j] = drdh[j]/2;
-        drbdh2[j] = drdh[j + 1]/2;
-      elseif noEvent(h[j] >= hl and h[j] <= hv and h[j + 1] >= hl and h[j + 1]
-           <= hv) then
-        // 2-phase
-        rhobar[j] = AA*log(rho[j]/rho[j + 1])/(h[j + 1] - h[j]);
-        drbdp[j] = (AA1*log(rho[j]/rho[j + 1]) + AA*(1/rho[j]*drdp[j] - 1/rho[j
-           + 1]*drdp[j + 1]))/(h[j + 1] - h[j]);
-        drbdh1[j] = (rhobar[j] - rho[j])/(h[j + 1] - h[j]);
-        drbdh2[j] = (rho[j + 1] - rhobar[j])/(h[j + 1] - h[j]);
-      elseif noEvent(h[j] < hl and h[j + 1] >= hl and h[j + 1] <= hv) then
-        // liquid/2-phase
-        rhobar[j] = ((rho[j] + rhol)*(hl - h[j])/2 + AA*log(rhol/rho[j + 1]))/(
-          h[j + 1] - h[j]);
-        drbdp[j] = ((drdp[j] + drldp)*(hl - h[j])/2 + (rho[j] + rhol)/2*dhldp
-           + AA1*log(rhol/rho[j + 1]) + AA*(1/rhol*drldp - 1/rho[j + 1]*drdp[j
-           + 1]))/(h[j + 1] - h[j]);
-        drbdh1[j] = (rhobar[j] - (rho[j] + rhol)/2 + drdh[j]*(hl - h[j])/2)/(h[
-          j + 1] - h[j]);
-        drbdh2[j] = (rho[j + 1] - rhobar[j])/(h[j + 1] - h[j]);
-      elseif noEvent(h[j] >= hl and h[j] <= hv and h[j + 1] > hv) then
-        // 2-phase/vapour
-        rhobar[j] = (AA*log(rho[j]/rhov) + (rhov + rho[j + 1])*(h[j + 1] - hv)/
-          2)/(h[j + 1] - h[j]);
-        drbdp[j] = (AA1*log(rho[j]/rhov) + AA*(1/rho[j]*drdp[j] - 1/rhov*drvdp)
-           + (drvdp + drdp[j + 1])*(h[j + 1] - hv)/2 - (rhov + rho[j + 1])/2*
-          dhvdp)/(h[j + 1] - h[j]);
-        drbdh1[j] = (rhobar[j] - rho[j])/(h[j + 1] - h[j]);
-        drbdh2[j] = ((rhov + rho[j + 1])/2 - rhobar[j] + drdh[j + 1]*(h[j + 1]
-           - hv)/2)/(h[j + 1] - h[j]);
-      elseif noEvent(h[j] < hl and h[j + 1] > hv) then
-        // liquid/2-phase/vapour
-        rhobar[j] = ((rho[j] + rhol)*(hl - h[j])/2 + AA*log(rhol/rhov) + (rhov
-           + rho[j + 1])*(h[j + 1] - hv)/2)/(h[j + 1] - h[j]);
-        drbdp[j] = ((drdp[j] + drldp)*(hl - h[j])/2 + (rho[j] + rhol)/2*dhldp
-           + AA1*log(rhol/rhov) + AA*(1/rhol*drldp - 1/rhov*drvdp) + (drvdp +
-          drdp[j + 1])*(h[j + 1] - hv)/2 - (rhov + rho[j + 1])/2*dhvdp)/(h[j +
-          1] - h[j]);
-        drbdh1[j] = (rhobar[j] - (rho[j] + rhol)/2 + drdh[j]*(hl - h[j])/2)/(h[
-          j + 1] - h[j]);
-        drbdh2[j] = ((rhov + rho[j + 1])/2 - rhobar[j] + drdh[j + 1]*(h[j + 1]
-           - hv)/2)/(h[j + 1] - h[j]);
-      elseif noEvent(h[j] >= hl and h[j] <= hv and h[j + 1] < hl) then
-        // 2-phase/liquid
-        rhobar[j] = (AA*log(rho[j]/rhol) + (rhol + rho[j + 1])*(h[j + 1] - hl)/
-          2)/(h[j + 1] - h[j]);
-        drbdp[j] = (AA1*log(rho[j]/rhol) + AA*(1/rho[j]*drdp[j] - 1/rhol*drldp)
-           + (drldp + drdp[j + 1])*(h[j + 1] - hl)/2 - (rhol + rho[j + 1])/2*
-          dhldp)/(h[j + 1] - h[j]);
-        drbdh1[j] = (rhobar[j] - rho[j])/(h[j + 1] - h[j]);
-        drbdh2[j] = ((rhol + rho[j + 1])/2 - rhobar[j] + drdh[j + 1]*(h[j + 1]
-           - hl)/2)/(h[j + 1] - h[j]);
-      elseif noEvent(h[j] > hv and h[j + 1] < hl) then
-        // vapour/2-phase/liquid
-        rhobar[j] = ((rho[j] + rhov)*(hv - h[j])/2 + AA*log(rhov/rhol) + (rhol
-           + rho[j + 1])*(h[j + 1] - hl)/2)/(h[j + 1] - h[j]);
-        drbdp[j] = ((drdp[j] + drvdp)*(hv - h[j])/2 + (rho[j] + rhov)/2*dhvdp
-           + AA1*log(rhov/rhol) + AA*(1/rhov*drvdp - 1/rhol*drldp) + (drldp +
-          drdp[j + 1])*(h[j + 1] - hl)/2 - (rhol + rho[j + 1])/2*dhldp)/(h[j +
-          1] - h[j]);
-        drbdh1[j] = (rhobar[j] - (rho[j] + rhov)/2 + drdh[j]*(hv - h[j])/2)/(h[
-          j + 1] - h[j]);
-        drbdh2[j] = ((rhol + rho[j + 1])/2 - rhobar[j] + drdh[j + 1]*(h[j + 1]
-           - hl)/2)/(h[j + 1] - h[j]);
-      else
-        // vapour/2-phase
-        rhobar[j] = ((rho[j] + rhov)*(hv - h[j])/2 + AA*log(rhov/rho[j + 1]))/(
-          h[j + 1] - h[j]);
-        drbdp[j] = ((drdp[j] + drvdp)*(hv - h[j])/2 + (rho[j] + rhov)/2*dhvdp
-           + AA1*log(rhov/rho[j + 1]) + AA*(1/rhov*drvdp - 1/rho[j + 1]*drdp[j
-           + 1]))/(h[j + 1] - h[j]);
-        drbdh1[j] = (rhobar[j] - (rho[j] + rhov)/2 + drdh[j]*(hv - h[j])/2)/(h[
-          j + 1] - h[j]);
-        drbdh2[j] = (rho[j + 1] - rhobar[j])/(h[j + 1] - h[j]);
-      end if;
-    end for;
-
-    // Saturated fluid property calculations
-    sat = Medium.setSat_p(p);
-    Ts = sat.Tsat;
-    rhol = Medium.bubbleDensity(sat);
-    rhov = Medium.dewDensity(sat);
-    hl = Medium.bubbleEnthalpy(sat);
-    hv = Medium.dewEnthalpy(sat);
-    drldp = Medium.dBubbleDensity_dPressure(sat);
-    drvdp = Medium.dDewDensity_dPressure(sat);
-    dhldp = Medium.dBubbleEnthalpy_dPressure(sat);
-    dhvdp = Medium.dDewEnthalpy_dPressure(sat);
-    AA = (hv - hl)/(1/rhov - 1/rhol);
-    AA1 = ((dhvdp - dhldp)*(rhol - rhov)*rhol*rhov - (hv - hl)*(rhov^2*drldp -
-      rhol^2*drvdp))/(rhol - rhov)^2;
-
-    // Fluid property calculations
-    for j in 1:N loop
-      fluidState[j] = Medium.setState_phX(p, h[j]);
-      T[j] = Medium.temperature(fluidState[j]);
-      rho[j] = Medium.density(fluidState[j]);
-      drdp[j] = Medium.density_derp_h(fluidState[j]);
-      drdh[j] = Medium.density_derh_p(fluidState[j]);
-      u[j] = w/(rho[j]*A);
-      x[j] = noEvent(if h[j] <= hl then 0 else if h[j] >= hv then 1 else (h[j]
-         - hl)/(hv - hl));
-    end for;
-
-    // Selection of representative pressure and flow rate variables
-    if HydraulicCapacitance == HCtypes.Upstream then
-      p = infl.p;
-      w = -outfl.m_flow/Nt;
-    else
-      p = outfl.p;
-      w = infl.m_flow/Nt;
-    end if;
-
-    // Boundary conditions
-    infl.h_outflow = htilde[1];
-    outfl.h_outflow = htilde[N - 1];
-    h[1] = inStream(infl.h_outflow);
-    h[2:N] = htilde;
-    T = wall.T;
-    phibar = (wall.phi[1:N - 1] + wall.phi[2:N])/2;
-
-    Q = Nt*l*omega*sum(phibar) "Total heat flow through lateral boundary";
-    M = sum(rhobar)*A*l "Fluid mass (single tube)";
-    Tr = noEvent(M/max(infl.m_flow/Nt, Modelica.Constants.eps))
-      "Residence time";
-
-  initial equation
-    if initOpt == Choices.Init.Options.noInit then
-      // do nothing
-    elseif initOpt == Choices.Init.Options.steadyState then
-      der(htilde) = zeros(N - 1);
-      if (not Medium.singleState) then
-        der(p) = 0;
-      end if;
-    elseif initOpt == Choices.Init.Options.steadyStateNoP then
-      der(htilde) = zeros(N - 1);
-    elseif initOpt == Choices.Init.Options.steadyStateNoT and not Medium.singleState then
-      der(p) = 0;
-    else
-      assert(false, "Unsupported initialisation option");
-    end if;
-
-    annotation (
-      Diagram(graphics),
-      Icon(graphics={Text(extent={{-100,-54},{100,-80}}, textString="%name")}),
-      Documentation(info="<HTML>
+</html>"));
+  end Flow1DDB;
+
+  model Flow1D2ph "1-dimensional fluid flow model for water/steam (finite volumes, 2-phase)"
+    extends Modelica.Icons.ObsoleteModel;
+    extends BaseClasses.Flow1DBase(redeclare replaceable package Medium = StandardWater constrainedby Modelica.Media.Interfaces.PartialTwoPhaseMedium "Medium model", FluidPhaseStart = Choices.FluidPhase.FluidPhases.TwoPhases);
+    replaceable ThermoPower.Thermal.DHT wall(N = N) annotation(
+      Dialog(enable = false),
+      Placement(transformation(extent = {{-40, 40}, {40, 60}}, rotation = 0)));
+    import ThermoPower.Choices.Flow1D.FFtypes;
+    import ThermoPower.Choices.Flow1D.HCtypes;
+    // package SmoothMedium = Medium (final smoothModel=true);
+    constant SI.Pressure pzero = 10 "Small deltap for calculations";
+    constant SI.Pressure pc = Medium.fluidConstants[1].criticalPressure;
+    constant SI.SpecificEnthalpy hzero = 1e-3 "Small value for deltah";
+    // SmoothMedium.ThermodynamicState fluidState[N]
+    //   "Thermodynamic state of the fluid at the nodes";
+    Medium.ThermodynamicState fluidState[N] "Thermodynamic state of the fluid at the nodes";
+    Medium.SaturationProperties sat "Properties of saturated fluid";
+    SI.Length omega_hyd "Wet perimeter (single tube)";
+    SI.Pressure Dpfric "Pressure drop due to friction";
+    SI.Pressure Dpstat "Pressure drop due to static head";
+    Real Kf[N - 1] "Friction coefficient";
+    Real Kfl[N - 1] "Linear friction coefficient";
+    Real Cf[N - 1] "Fanning friction factor";
+    Real dwdt "Dynamic momentum term";
+    Medium.AbsolutePressure p(start = pstart, stateSelect = StateSelect.prefer) "Fluid pressure for property calculations";
+    SI.Pressure dpf[N - 1] "Pressure drop due to friction between two nodes";
+    SI.MassFlowRate w(start = wnom / Nt) "Mass flowrate (single tube)";
+    SI.MassFlowRate wbar[N - 1](each start = wnom / Nt);
+    SI.Velocity u[N] "Fluid velocity";
+    Medium.Temperature T[N] "Fluid temperature";
+    Medium.Temperature Ts "Saturated water temperature";
+    Medium.SpecificEnthalpy h[N](start = hstart) "Fluid specific enthalpy";
+    Medium.SpecificEnthalpy htilde[N - 1](start = hstart[2:N], each stateSelect = StateSelect.prefer) "Enthalpy state variables";
+    Medium.SpecificEnthalpy hl "Saturated liquid temperature";
+    Medium.SpecificEnthalpy hv "Saturated vapour temperature";
+    Real x[N] "Steam quality";
+    Medium.Density rho[N] "Fluid density";
+    Units.LiquidDensity rhol "Saturated liquid density";
+    Units.GasDensity rhov "Saturated vapour density";
+    SI.Mass M "Fluid mass";
+    SI.Power Qj[N - 1];
+    //DA CANCELLARE
+  protected
+    SI.DerEnthalpyByPressure dhldp "Derivative of saturated liquid enthalpy by pressure";
+    SI.DerEnthalpyByPressure dhvdp "Derivative of saturated vapour enthalpy by pressure";
+    SI.Density rhobar[N - 1] "Fluid average density";
+    SI.DerDensityByPressure drdp[N] "Derivative of density by pressure";
+    SI.DerDensityByPressure drbdp[N - 1] "Derivative of average density by pressure";
+    SI.DerDensityByPressure drldp "Derivative of saturated liquid density by pressure";
+    SI.DerDensityByPressure drvdp "Derivative of saturated vapour density by pressure";
+    SI.SpecificVolume vbar[N - 1] "Average specific volume";
+    SI.HeatFlux phibar[N - 1] "Average heat flux";
+    SI.DerDensityByEnthalpy drdh[N] "Derivative of density by enthalpy";
+    SI.DerDensityByEnthalpy drbdh1[N - 1] "Derivative of average density by left enthalpy";
+    SI.DerDensityByEnthalpy drbdh2[N - 1] "Derivative of average density by right enthalpy";
+    Real AA;
+    Real AA1;
+    Real dMdt[N - 1] "Derivative of fluid mass in each volume";
+  equation
+//All equations are referred to a single tube
+    omega_hyd = 4 * A / Dhyd;
+// Friction factor selection
+    for j in 1:N - 1 loop
+      if FFtype == FFtypes.Kfnom then
+        Kf[j] = Kfnom * Kfc / (N - 1);
+        Cf[j] = 2 * Kf[j] * A ^ 3 / (omega_hyd * l);
+      elseif FFtype == FFtypes.OpPoint then
+        Kf[j] = dpnom * rhonom / (wnom / Nt) ^ 2 / (N - 1) * Kfc;
+        Cf[j] = 2 * Kf[j] * A ^ 3 / (omega_hyd * l);
+      elseif FFtype == FFtypes.Cfnom then
+        Kf[j] = Cfnom * omega_hyd * l / (2 * A ^ 3) * Kfc;
+        Cf[j] = 2 * Kf[j] * A ^ 3 / (omega_hyd * l);
+      elseif FFtype == FFtypes.Colebrook then
+        Cf[j] = if noEvent(htilde[j] < hl or htilde[j] > hv) then f_colebrook(w, Dhyd / A, e, Medium.dynamicViscosity(fluidState[j])) * Kfc else f_colebrook_2ph(w, Dhyd / A, e, Medium.dynamicViscosity(Medium.setBubbleState(sat, 1)), Medium.dynamicViscosity(Medium.setDewState(sat, 1)), x[j]) * Kfc;
+        Kf[j] = Cf[j] * omega_hyd * l / (2 * A ^ 3);
+      elseif FFtype == FFtypes.NoFriction then
+        Cf[j] = 0;
+        Kf[j] = 0;
+      else
+        assert(FFtype <> FFtypes.NoFriction, "Unsupported FFtype");
+        Cf[j] = 0;
+        Kf[j] = 0;
+      end if;
+      assert(Kf[j] >= 0, "Negative friction coefficient");
+      Kfl[j] = wnom / Nt * wnf * Kf[j];
+    end for;
+// Dynamic momentum term
+    if DynamicMomentum then
+      dwdt = der(w);
+    else
+      dwdt = 0;
+    end if;
+    sum(dMdt) = infl.m_flow / Nt + outfl.m_flow / Nt "Mass balance";
+    sum(dpf) = Dpfric "Total pressure drop due to friction";
+    Dpstat = if abs(dzdx) < 1e-6 then 0 else g * l * dzdx * sum(rhobar) "Pressure drop due to static head";
+    L / A * dwdt + outfl.p - infl.p + Dpstat + Dpfric = 0 "Momentum balance";
+    for j in 1:N - 1 loop
+      A * l * rhobar[j] * der(htilde[j]) + wbar[j] * (h[j + 1] - h[j]) - A * l * der(p) = l * omega * phibar[j] "Energy balance";
+      Qj[j] = l * omega * phibar[j];
+      dMdt[j] = A * l * (drbdh1[j] * der(h[j]) + drbdh2[j] * der(h[j + 1]) + drbdp[j] * der(p)) "Mass balance for each volume";
+// Average volume quantities
+      vbar[j] = 1 / rhobar[j] "Average specific volume";
+      wbar[j] = homotopy(infl.m_flow / Nt - sum(dMdt[1:j - 1]) - dMdt[j] / 2, wnom / Nt);
+      dpf[j] = if FFtype == FFtypes.NoFriction then 0 else homotopy(smooth(1, Kf[j] * squareReg(w, wnom / Nt * wnf)) * vbar[j], dpnom / (N - 1) / (wnom / Nt) * w);
+      if avoidInletEnthalpyDerivative and j == 1 then
+// first volume properties computed by the outlet properties
+        rhobar[j] = rho[j + 1];
+        drbdp[j] = drdp[j + 1];
+        drbdh1[j] = 0;
+        drbdh2[j] = drdh[j + 1];
+      elseif noEvent(h[j] < hl and h[j + 1] < hl or h[j] > hv and h[j + 1] > hv or p >= pc - pzero or abs(h[j + 1] - h[j]) < hzero) then
+// 1-phase or almost uniform properties
+        rhobar[j] = (rho[j] + rho[j + 1]) / 2;
+        drbdp[j] = (drdp[j] + drdp[j + 1]) / 2;
+        drbdh1[j] = drdh[j] / 2;
+        drbdh2[j] = drdh[j + 1] / 2;
+      elseif noEvent(h[j] >= hl and h[j] <= hv and h[j + 1] >= hl and h[j + 1] <= hv) then
+// 2-phase
+        rhobar[j] = AA * log(rho[j] / rho[j + 1]) / (h[j + 1] - h[j]);
+        drbdp[j] = (AA1 * log(rho[j] / rho[j + 1]) + AA * (1 / rho[j] * drdp[j] - 1 / rho[j + 1] * drdp[j + 1])) / (h[j + 1] - h[j]);
+        drbdh1[j] = (rhobar[j] - rho[j]) / (h[j + 1] - h[j]);
+        drbdh2[j] = (rho[j + 1] - rhobar[j]) / (h[j + 1] - h[j]);
+      elseif noEvent(h[j] < hl and h[j + 1] >= hl and h[j + 1] <= hv) then
+// liquid/2-phase
+        rhobar[j] = ((rho[j] + rhol) * (hl - h[j]) / 2 + AA * log(rhol / rho[j + 1])) / (h[j + 1] - h[j]);
+        drbdp[j] = ((drdp[j] + drldp) * (hl - h[j]) / 2 + (rho[j] + rhol) / 2 * dhldp + AA1 * log(rhol / rho[j + 1]) + AA * (1 / rhol * drldp - 1 / rho[j + 1] * drdp[j + 1])) / (h[j + 1] - h[j]);
+        drbdh1[j] = (rhobar[j] - (rho[j] + rhol) / 2 + drdh[j] * (hl - h[j]) / 2) / (h[j + 1] - h[j]);
+        drbdh2[j] = (rho[j + 1] - rhobar[j]) / (h[j + 1] - h[j]);
+      elseif noEvent(h[j] >= hl and h[j] <= hv and h[j + 1] > hv) then
+// 2-phase/vapour
+        rhobar[j] = (AA * log(rho[j] / rhov) + (rhov + rho[j + 1]) * (h[j + 1] - hv) / 2) / (h[j + 1] - h[j]);
+        drbdp[j] = (AA1 * log(rho[j] / rhov) + AA * (1 / rho[j] * drdp[j] - 1 / rhov * drvdp) + (drvdp + drdp[j + 1]) * (h[j + 1] - hv) / 2 - (rhov + rho[j + 1]) / 2 * dhvdp) / (h[j + 1] - h[j]);
+        drbdh1[j] = (rhobar[j] - rho[j]) / (h[j + 1] - h[j]);
+        drbdh2[j] = ((rhov + rho[j + 1]) / 2 - rhobar[j] + drdh[j + 1] * (h[j + 1] - hv) / 2) / (h[j + 1] - h[j]);
+      elseif noEvent(h[j] < hl and h[j + 1] > hv) then
+// liquid/2-phase/vapour
+        rhobar[j] = ((rho[j] + rhol) * (hl - h[j]) / 2 + AA * log(rhol / rhov) + (rhov + rho[j + 1]) * (h[j + 1] - hv) / 2) / (h[j + 1] - h[j]);
+        drbdp[j] = ((drdp[j] + drldp) * (hl - h[j]) / 2 + (rho[j] + rhol) / 2 * dhldp + AA1 * log(rhol / rhov) + AA * (1 / rhol * drldp - 1 / rhov * drvdp) + (drvdp + drdp[j + 1]) * (h[j + 1] - hv) / 2 - (rhov + rho[j + 1]) / 2 * dhvdp) / (h[j + 1] - h[j]);
+        drbdh1[j] = (rhobar[j] - (rho[j] + rhol) / 2 + drdh[j] * (hl - h[j]) / 2) / (h[j + 1] - h[j]);
+        drbdh2[j] = ((rhov + rho[j + 1]) / 2 - rhobar[j] + drdh[j + 1] * (h[j + 1] - hv) / 2) / (h[j + 1] - h[j]);
+      elseif noEvent(h[j] >= hl and h[j] <= hv and h[j + 1] < hl) then
+// 2-phase/liquid
+        rhobar[j] = (AA * log(rho[j] / rhol) + (rhol + rho[j + 1]) * (h[j + 1] - hl) / 2) / (h[j + 1] - h[j]);
+        drbdp[j] = (AA1 * log(rho[j] / rhol) + AA * (1 / rho[j] * drdp[j] - 1 / rhol * drldp) + (drldp + drdp[j + 1]) * (h[j + 1] - hl) / 2 - (rhol + rho[j + 1]) / 2 * dhldp) / (h[j + 1] - h[j]);
+        drbdh1[j] = (rhobar[j] - rho[j]) / (h[j + 1] - h[j]);
+        drbdh2[j] = ((rhol + rho[j + 1]) / 2 - rhobar[j] + drdh[j + 1] * (h[j + 1] - hl) / 2) / (h[j + 1] - h[j]);
+      elseif noEvent(h[j] > hv and h[j + 1] < hl) then
+// vapour/2-phase/liquid
+        rhobar[j] = ((rho[j] + rhov) * (hv - h[j]) / 2 + AA * log(rhov / rhol) + (rhol + rho[j + 1]) * (h[j + 1] - hl) / 2) / (h[j + 1] - h[j]);
+        drbdp[j] = ((drdp[j] + drvdp) * (hv - h[j]) / 2 + (rho[j] + rhov) / 2 * dhvdp + AA1 * log(rhov / rhol) + AA * (1 / rhov * drvdp - 1 / rhol * drldp) + (drldp + drdp[j + 1]) * (h[j + 1] - hl) / 2 - (rhol + rho[j + 1]) / 2 * dhldp) / (h[j + 1] - h[j]);
+        drbdh1[j] = (rhobar[j] - (rho[j] + rhov) / 2 + drdh[j] * (hv - h[j]) / 2) / (h[j + 1] - h[j]);
+        drbdh2[j] = ((rhol + rho[j + 1]) / 2 - rhobar[j] + drdh[j + 1] * (h[j + 1] - hl) / 2) / (h[j + 1] - h[j]);
+      else
+// vapour/2-phase
+        rhobar[j] = ((rho[j] + rhov) * (hv - h[j]) / 2 + AA * log(rhov / rho[j + 1])) / (h[j + 1] - h[j]);
+        drbdp[j] = ((drdp[j] + drvdp) * (hv - h[j]) / 2 + (rho[j] + rhov) / 2 * dhvdp + AA1 * log(rhov / rho[j + 1]) + AA * (1 / rhov * drvdp - 1 / rho[j + 1] * drdp[j + 1])) / (h[j + 1] - h[j]);
+        drbdh1[j] = (rhobar[j] - (rho[j] + rhov) / 2 + drdh[j] * (hv - h[j]) / 2) / (h[j + 1] - h[j]);
+        drbdh2[j] = (rho[j + 1] - rhobar[j]) / (h[j + 1] - h[j]);
+      end if;
+    end for;
+// Saturated fluid property calculations
+    sat = Medium.setSat_p(p);
+    Ts = sat.Tsat;
+    rhol = Medium.bubbleDensity(sat);
+    rhov = Medium.dewDensity(sat);
+    hl = Medium.bubbleEnthalpy(sat);
+    hv = Medium.dewEnthalpy(sat);
+    drldp = Medium.dBubbleDensity_dPressure(sat);
+    drvdp = Medium.dDewDensity_dPressure(sat);
+    dhldp = Medium.dBubbleEnthalpy_dPressure(sat);
+    dhvdp = Medium.dDewEnthalpy_dPressure(sat);
+    AA = (hv - hl) / (1 / rhov - 1 / rhol);
+    AA1 = ((dhvdp - dhldp) * (rhol - rhov) * rhol * rhov - (hv - hl) * (rhov ^ 2 * drldp - rhol ^ 2 * drvdp)) / (rhol - rhov) ^ 2;
+// Fluid property calculations
+    for j in 1:N loop
+      fluidState[j] = Medium.setState_phX(p, h[j]);
+      T[j] = Medium.temperature(fluidState[j]);
+      rho[j] = Medium.density(fluidState[j]);
+      drdp[j] = Medium.density_derp_h(fluidState[j]);
+      drdh[j] = Medium.density_derh_p(fluidState[j]);
+      u[j] = w / (rho[j] * A);
+      x[j] = noEvent(if h[j] <= hl then 0 else if h[j] >= hv then 1 else (h[j] - hl) / (hv - hl));
+    end for;
+// Selection of representative pressure and flow rate variables
+    if HydraulicCapacitance == HCtypes.Upstream then
+      p = infl.p;
+      w = -outfl.m_flow / Nt;
+    else
+      p = outfl.p;
+      w = infl.m_flow / Nt;
+    end if;
+// Boundary conditions
+    infl.h_outflow = htilde[1];
+    outfl.h_outflow = htilde[N - 1];
+    h[1] = inStream(infl.h_outflow);
+    h[2:N] = htilde;
+    T = wall.T;
+    phibar = (wall.phi[1:N - 1] + wall.phi[2:N]) / 2;
+    Q = Nt * l * omega * sum(phibar) "Total heat flow through lateral boundary";
+    M = sum(rhobar) * A * l "Fluid mass (single tube)";
+    Tr = noEvent(M / max(infl.m_flow / Nt, Modelica.Constants.eps)) "Residence time";
+  initial equation
+    if initOpt == Choices.Init.Options.noInit then
+// do nothing
+    elseif initOpt == Choices.Init.Options.steadyState then
+      der(htilde) = zeros(N - 1);
+      if not Medium.singleState then
+        der(p) = 0;
+      end if;
+    elseif initOpt == Choices.Init.Options.steadyStateNoP then
+      der(htilde) = zeros(N - 1);
+    elseif initOpt == Choices.Init.Options.steadyStateNoT and not Medium.singleState then
+      der(p) = 0;
+    else
+      assert(false, "Unsupported initialisation option");
+    end if;
+    annotation(
+      Diagram(graphics),
+      Icon(graphics = {Text(extent = {{-100, -54}, {100, -80}}, textString = "%name")}),
+      Documentation(info = "<HTML>
 <p>This model describes the flow of water or steam in a rigid tube. The basic modelling assumptions are:
 <ul><li>The fluid state is either one-phase, or a two-phase mixture.
 <li>In case of two-phase flow, the same velocity is assumed for both phases (homogeneous model).
@@ -7032,7 +5478,7 @@
 <p>Start values for pressure and flowrate are specified by <tt>pstart</tt>, <tt>wstart</tt>. The start values for the node enthalpies are linearly distributed from <tt>hstartin</tt> at the inlet to <tt>hstartout</tt> at the outlet.
 <p>A bank of <tt>Nt</tt> identical tubes working in parallel can be modelled by setting <tt>Nt > 1</tt>. The geometric parameters always refer to a <i>single</i> tube.
 <p>This models makes the temperature and external heat flow distributions visible through the <tt>wall</tt> connector. If other variables (e.g. the heat transfer coefficient) are needed by external components to compute the actual heat flow, the <tt>wall</tt> connector can be replaced by an extended version of the <tt>DHT</tt> connector.
-</HTML>", revisions="<html>
+</HTML>", revisions = "<html>
 <ul>
 <li><i>27 Jul 2007</i>
     by <a href=\"mailto:francesco.casella@polimi.it\">Francesco Casella</a>:<br>
@@ -7063,116 +5509,65 @@
     by <a href=\"mailto:francesco.casella@polimi.it\">Francesco Casella</a>:<br>
        First release.</li>
 </ul>
-</html>"));
-  end Flow1D2ph;
-
-  model Flow1D2phDB
-    "1-dimensional fluid flow model for 2-phase boiling flow (finite volumes, 2-phase, computation of heat transfer coeff.)"
-    extends Flow1D2ph(redeclare Thermal.DHThtc wall);
-    parameter SI.CoefficientOfHeatTransfer gamma_b=20000
-      "Coefficient of heat transfer for boiling flow";
-    parameter Real xCHF=0.9
-      "Steam quality corresponding to the Critical Heat Flux";
-    Medium.ThermodynamicState bubble "Bubble point state";
-    Medium.ThermodynamicState dew "Dew point state";
-  protected
-    SI.CoefficientOfHeatTransfer gamma[N] "Raw heat transfer coefficient";
-    SI.CoefficientOfHeatTransfer gamma_ls "H.t.c. just before bubble point";
-    SI.CoefficientOfHeatTransfer gamma_chf "H.t.c. just after CHF";
-    SI.CoefficientOfHeatTransfer gamma_corr_left[N]
-      "Correction term to get smooth h.t.c.";
-    SI.CoefficientOfHeatTransfer gamma_corr_right[N]
-      "Correction term to get smooth h.t.c.";
-    SI.SpecificEnthalpy hCHF "Enthalpy corresponding to the Critical Heat Flux";
-    SI.DynamicViscosity mu_ls "Dynamic viscosity at bubble point";
-    SI.DynamicViscosity mu_vs "Dynamic viscosity at dew point";
-    SI.ThermalConductivity k_ls "Thermal conductivity at bubble point";
-    SI.ThermalConductivity k_vs "Thermal conductivity at dew point";
-    SI.SpecificHeatCapacity cp_ls "Specific heat capacity at bubble point";
-    SI.SpecificHeatCapacity cp_vs "Specific heat capacity at dew point";
-  equation
-    hCHF = hl + xCHF*(hv - hl)
-      "Specific enthalpy corresponding to critical heat flux";
-    // Saturated fluid properties
-    bubble = Medium.setBubbleState(sat, 1);
-    dew = Medium.setDewState(sat, 1);
-    mu_ls = Medium.dynamicViscosity(bubble);
-    k_ls = Medium.thermalConductivity(bubble);
-    cp_ls = Medium.heatCapacity_cp(bubble);
-    mu_vs = Medium.dynamicViscosity(dew);
-    k_vs = Medium.thermalConductivity(dew);
-    cp_vs = Medium.heatCapacity_cp(dew);
-    // H.t.c. just outside the nucleate boiling region
-    gamma_ls = f_dittus_boelter(
-        w,
-        Dhyd,
-        A,
-        mu_ls,
-        k_ls,
-        cp_ls);
-    gamma_chf = f_dittus_boelter(
-        w*xCHF,
-        Dhyd,
-        A,
-        mu_vs,
-        k_vs,
-        cp_vs);
-
-    // Nodal h.t.c.
-    for j in 1:N loop
-      // a) Subcooled liquid
-      // b) Wet steam after dryout: Dittus-Boelter's correlation considering
-      //    only the vapour phase
-      // c) Nucleate boiling: constant h.t.c.
-      gamma[j] = noEvent(if h[j] < hl or h[j] > hv then f_dittus_boelter(
-          w,
-          Dhyd,
-          A,
-          Medium.dynamicViscosity(fluidState[j]),
-          Medium.thermalConductivity(fluidState[j]),
-          Medium.heatCapacity_cp(fluidState[j])) else if h[j] > hCHF then
-        f_dittus_boelter(
-          w*x[j],
-          Dhyd,
-          A,
-          mu_vs,
-          k_vs,
-          cp_vs) else gamma_b);
-    end for;
-
-    // Corrections due to boundaries near the nodes to the left
-    // to achieve continuous h.t.c.
-    gamma_corr_left[1] = 0;
-    for j in 2:N loop
-      gamma_corr_left[j] = noEvent(if h[j] < hl then (if (h[j - 1] + h[j])/2 >
-        hl then ((h[j - 1] - hl)/(h[j - 1] - h[j]) - 0.5)*(gamma_b - gamma_ls)*
-        (if j == N then 2 else 1) else 0) else if h[j] > hCHF then (if (h[j - 1]
-         + h[j])/2 < hCHF then ((hCHF - h[j - 1])/(h[j] - h[j - 1]) - 0.5)*(
-        gamma_b - gamma_chf)*(if j == N then 2 else 1) else 0) else if (h[j - 1]
-         + h[j])/2 < hl then ((hl - h[j - 1])/(h[j] - h[j - 1]) - 0.5)*(
-        gamma_ls - gamma_b)*(if j == N then 2 else 1) else if (h[j - 1] + h[j])
-        /2 > hCHF then ((h[j - 1] - hCHF)/(h[j - 1] - h[j]) - 0.5)*(gamma_chf
-         - gamma_b)*(if j == N then 2 else 1) else 0);
-    end for;
-
-    // Corrections due to boundaries near the nodes to the right
-    // to achieve continuous h.t.c.
-    gamma_corr_right[N] = 0;
-    for j in 1:N - 1 loop
-      gamma_corr_right[j] = noEvent(if h[j] < hl then (if (h[j + 1] + h[j])/2
-         > hl then ((h[j + 1] - hl)/(h[j + 1] - h[j]) - 0.5)*(gamma_b -
-        gamma_ls)*(if j == 1 then 2 else 1) else 0) else if h[j] > hCHF then (
-        if (h[j + 1] + h[j])/2 < hCHF then ((hCHF - h[j + 1])/(h[j] - h[j + 1])
-         - 0.5)*(gamma_b - gamma_chf)*(if j == 1 then 2 else 1) else 0) else
-        if (h[j + 1] + h[j])/2 < hl then ((hl - h[j + 1])/(h[j] - h[j + 1]) -
-        0.5)*(gamma_ls - gamma_b)*(if j == 1 then 2 else 1) else if (h[j + 1]
-         + h[j])/2 > hCHF then ((h[j + 1] - hCHF)/(h[j + 1] - h[j]) - 0.5)*(
-        gamma_chf - gamma_b)*(if j == 1 then 2 else 1) else 0);
-    end for;
-
-    wall.gamma = gamma + gamma_corr_left + gamma_corr_right
-      "H.t.c. including smoothing terms";
-    annotation (Documentation(info="<HTML>
+</html>"));
+  end Flow1D2ph;
+
+  model Flow1D2phDB "1-dimensional fluid flow model for 2-phase boiling flow (finite volumes, 2-phase, computation of heat transfer coeff.)"
+    extends Flow1D2ph(redeclare Thermal.DHThtc wall);
+    parameter SI.CoefficientOfHeatTransfer gamma_b = 20000 "Coefficient of heat transfer for boiling flow";
+    parameter Real xCHF = 0.9 "Steam quality corresponding to the Critical Heat Flux";
+    Medium.ThermodynamicState bubble "Bubble point state";
+    Medium.ThermodynamicState dew "Dew point state";
+  protected
+    SI.CoefficientOfHeatTransfer gamma[N] "Raw heat transfer coefficient";
+    SI.CoefficientOfHeatTransfer gamma_ls "H.t.c. just before bubble point";
+    SI.CoefficientOfHeatTransfer gamma_chf "H.t.c. just after CHF";
+    SI.CoefficientOfHeatTransfer gamma_corr_left[N] "Correction term to get smooth h.t.c.";
+    SI.CoefficientOfHeatTransfer gamma_corr_right[N] "Correction term to get smooth h.t.c.";
+    SI.SpecificEnthalpy hCHF "Enthalpy corresponding to the Critical Heat Flux";
+    SI.DynamicViscosity mu_ls "Dynamic viscosity at bubble point";
+    SI.DynamicViscosity mu_vs "Dynamic viscosity at dew point";
+    SI.ThermalConductivity k_ls "Thermal conductivity at bubble point";
+    SI.ThermalConductivity k_vs "Thermal conductivity at dew point";
+    SI.SpecificHeatCapacity cp_ls "Specific heat capacity at bubble point";
+    SI.SpecificHeatCapacity cp_vs "Specific heat capacity at dew point";
+  equation
+    hCHF = hl + xCHF * (hv - hl) "Specific enthalpy corresponding to critical heat flux";
+// Saturated fluid properties
+    bubble = Medium.setBubbleState(sat, 1);
+    dew = Medium.setDewState(sat, 1);
+    mu_ls = Medium.dynamicViscosity(bubble);
+    k_ls = Medium.thermalConductivity(bubble);
+    cp_ls = Medium.heatCapacity_cp(bubble);
+    mu_vs = Medium.dynamicViscosity(dew);
+    k_vs = Medium.thermalConductivity(dew);
+    cp_vs = Medium.heatCapacity_cp(dew);
+// H.t.c. just outside the nucleate boiling region
+    gamma_ls = f_dittus_boelter(w, Dhyd, A, mu_ls, k_ls, cp_ls);
+    gamma_chf = f_dittus_boelter(w * xCHF, Dhyd, A, mu_vs, k_vs, cp_vs);
+// Nodal h.t.c.
+    for j in 1:N loop
+// a) Subcooled liquid
+// b) Wet steam after dryout: Dittus-Boelter's correlation considering
+//    only the vapour phase
+// c) Nucleate boiling: constant h.t.c.
+      gamma[j] = noEvent(if h[j] < hl or h[j] > hv then f_dittus_boelter(w, Dhyd, A, Medium.dynamicViscosity(fluidState[j]), Medium.thermalConductivity(fluidState[j]), Medium.heatCapacity_cp(fluidState[j])) else if h[j] > hCHF then f_dittus_boelter(w * x[j], Dhyd, A, mu_vs, k_vs, cp_vs) else gamma_b);
+    end for;
+// Corrections due to boundaries near the nodes to the left
+// to achieve continuous h.t.c.
+    gamma_corr_left[1] = 0;
+    for j in 2:N loop
+      gamma_corr_left[j] = noEvent(if h[j] < hl then if (h[j - 1] + h[j]) / 2 > hl then ((h[j - 1] - hl) / (h[j - 1] - h[j]) - 0.5) * (gamma_b - gamma_ls) * (if j == N then 2 else 1) else 0 else if h[j] > hCHF then if (h[j - 1] + h[j]) / 2 < hCHF then ((hCHF - h[j - 1]) / (h[j] - h[j - 1]) - 0.5) * (gamma_b - gamma_chf) * (if j == N then 2 else 1) else 0 else if (h[j - 1] + h[j]) / 2 < hl then ((hl - h[j - 1]) / (h[j] - h[j - 1]) - 0.5) * (gamma_ls - gamma_b) * (if j == N then 2 else 1) else if (h[j - 1] + h[j]) / 2 > hCHF then ((h[j - 1] - hCHF) / (h[j - 1] - h[j]) - 0.5) * (gamma_chf - gamma_b) * (if j == N then 2 else 1) else 0);
+    end for;
+// Corrections due to boundaries near the nodes to the right
+// to achieve continuous h.t.c.
+    gamma_corr_right[N] = 0;
+    for j in 1:N - 1 loop
+      gamma_corr_right[j] = noEvent(if h[j] < hl then if (h[j + 1] + h[j]) / 2 > hl then ((h[j + 1] - hl) / (h[j + 1] - h[j]) - 0.5) * (gamma_b - gamma_ls) * (if j == 1 then 2 else 1) else 0 else if h[j] > hCHF then if (h[j + 1] + h[j]) / 2 < hCHF then ((hCHF - h[j + 1]) / (h[j] - h[j + 1]) - 0.5) * (gamma_b - gamma_chf) * (if j == 1 then 2 else 1) else 0 else if (h[j + 1] + h[j]) / 2 < hl then ((hl - h[j + 1]) / (h[j] - h[j + 1]) - 0.5) * (gamma_ls - gamma_b) * (if j == 1 then 2 else 1) else if (h[j + 1] + h[j]) / 2 > hCHF then ((h[j + 1] - hCHF) / (h[j + 1] - h[j]) - 0.5) * (gamma_chf - gamma_b) * (if j == 1 then 2 else 1) else 0);
+    end for;
+    wall.gamma = gamma + gamma_corr_left + gamma_corr_right "H.t.c. including smoothing terms";
+    annotation(
+      Documentation(info = "<HTML>
 <p>This model extends <tt>Flow1D2ph</tt> by computing the distribution of the heat transfer coefficient <tt>gamma</tt> and making it available through an extended version of the <tt>wall</tt> connector.
 <p>This simplified model can be used for one-phase or two-phase water/steam flow. The heat transfer coefficient is computed according to the following hypotheses:
 <ul>
@@ -7185,7 +5580,7 @@
 <ol>
 <li>J. C. Collier: <i>Convective Boiling and Condensation</i>, 2nd ed.,McGraw Hill, 1981, pp. 146.
 </ol>
-</HTML>", revisions="<html>
+</HTML>", revisions = "<html>
 <ul>
 <li><i>24 Mar 2005</i>
     by <a href=\"mailto:francesco.casella@polimi.it\">Francesco Casella</a>:<br>
@@ -7206,238 +5601,66 @@
     by <a href=\"mailto:francesco.casella@polimi.it\">Francesco Casella</a>:<br>
        First release.</li>
 </ul>
-</html>"));
-  end Flow1D2phDB;
-
-  model Flow1D2phChen
-    "1-dimensional fluid flow model for 2-phase boiling flow (finite volumes, 2-phase, Chen correlation)"
-    extends Flow1D2ph(redeclare Thermal.DHThtc wall);
-    parameter Real xCHF=0.9 "Steam quality corresponding to Critical Heat Flux";
-    Medium.ThermodynamicState bubble "Bubble point state";
-    Medium.ThermodynamicState dew "Dew point state";
-  protected
-    SI.CoefficientOfHeatTransfer gamma[N] "Raw heat transfer coefficient";
-    SI.CoefficientOfHeatTransfer gamma_ls "H.t.c. just before bubble point";
-    SI.CoefficientOfHeatTransfer gamma_chf "H.t.c. just after CHF";
-    SI.CoefficientOfHeatTransfer gamma_corr_left[N]
-      "Correction term to get smooth h.t.c.";
-    SI.CoefficientOfHeatTransfer gamma_corr_right[N]
-      "Correction term to get smooth h.t.c.";
-    Medium.SpecificEnthalpy hCHF
-      "Enthalpy corresponding to the Critical Heat Flux";
-    Medium.DynamicViscosity mu_ls "Dynamic viscosity at bubble point";
-    Medium.DynamicViscosity mu_vs "Dynamic viscosity at dew point";
-    Medium.ThermalConductivity k_ls "Thermal conductivity at bubble point";
-    Medium.ThermalConductivity k_vs "Thermal conductivity at dew point";
-    Medium.SpecificHeatCapacity cp_ls "Specific heat capacity at bubble point";
-    Medium.SpecificHeatCapacity cp_vs "Specific heat capacity at dew point";
-    Medium.SurfaceTension sigma "Surface tension";
-  equation
-    hCHF = hl + xCHF*(hv - hl)
-      "Specific enthalpy corresponding to critical heat flux";
-    // Saturated water and steam properties
-    bubble = Medium.setBubbleState(sat, 1);
-    dew = Medium.setDewState(sat, 1);
-    mu_ls = Medium.dynamicViscosity(bubble);
-    k_ls = Medium.thermalConductivity(bubble);
-    cp_ls = Medium.heatCapacity_cp(bubble);
-    mu_vs = Medium.dynamicViscosity(dew);
-    k_vs = Medium.thermalConductivity(dew);
-    cp_vs = Medium.heatCapacity_cp(dew);
-    sigma = Medium.surfaceTension(sat);
-    // H.t.c. just outside the nucleate boiling region
-    gamma_ls = f_dittus_boelter(
-        w,
-        Dhyd,
-        A,
-        mu_ls,
-        k_ls,
-        cp_ls);
-    gamma_chf = f_dittus_boelter(
-        w*xCHF,
-        Dhyd,
-        A,
-        mu_vs,
-        k_vs,
-        cp_vs);
-
-    // Nodal h.t.c. computations
-    for j in 1:N loop
-      // a) Subcooled liquid
-      // b) Wet steam after dryout: Dittus-Boelter's correlation considering
-      //    only the vapour phase
-      // c) Nucleate boiling: constant h.t.c.
-      gamma[j] = noEvent(if h[j] < hl or h[j] > hv then f_dittus_boelter(
-          w,
-          Dhyd,
-          A,
-          Medium.dynamicViscosity(fluidState[j]),
-          Medium.thermalConductivity(fluidState[j]),
-          Medium.heatCapacity_cp(fluidState[j])) else if h[j] > hCHF then
-        f_dittus_boelter(
-          w*x[j],
-          Dhyd,
-          A,
-          mu_vs,
-          k_vs,
-          cp_vs) else f_chen(
-          w,
-          Dhyd,
-          A,
-          mu_ls,
-          k_ls,
-          cp_ls,
-          rhol,
-          sigma,
-          rhov,
-          mu_vs,
-          wall.T[j] - Medium.saturationTemperature(p),
-          Medium.saturationPressure(wall.T[j]) - p,
-          hv - hl,
-          x[j]));
-    end for;
-
-    // Corrections due to boundaries near the nodes to the left
-    // to achieve continuous h.t.c.
-    gamma_corr_left[1] = 0;
-    for j in 2:N loop
-      gamma_corr_left[j] = noEvent(if h[j] < hl then (if (h[j - 1] + h[j])/2 >
-        hl then ((h[j - 1] - hl)/(h[j - 1] - h[j]) - 0.5)*(f_chen(
-          w,
-          Dhyd,
-          A,
-          mu_ls,
-          k_ls,
-          cp_ls,
-          rhol,
-          sigma,
-          rhov,
-          mu_vs,
-          wall.T[j] - Medium.saturationTemperature(p),
-          Medium.saturationPressure(wall.T[j]) - p,
-          hv - hl,
-          0) - gamma_ls)*(if j == N then 2 else 1) else 0) else if h[j] > hCHF
-         then (if (h[j - 1] + h[j])/2 < hCHF then ((hCHF - h[j - 1])/(h[j] - h[
-        j - 1]) - 0.5)*(f_chen(
-          w,
-          Dhyd,
-          A,
-          mu_ls,
-          k_ls,
-          cp_ls,
-          rhol,
-          sigma,
-          rhov,
-          mu_vs,
-          wall.T[j] - Medium.saturationTemperature(p),
-          Medium.saturationPressure(wall.T[j]) - p,
-          hv - hl,
-          xCHF) - gamma_chf)*(if j == N then 2 else 1) else 0) else if (h[j - 1]
-         + h[j])/2 < hl then ((hl - h[j - 1])/(h[j] - h[j - 1]) - 0.5)*(
-        gamma_ls - f_chen(
-          w,
-          Dhyd,
-          A,
-          mu_ls,
-          k_ls,
-          cp_ls,
-          rhol,
-          sigma,
-          rhov,
-          mu_vs,
-          wall.T[j] - Medium.saturationTemperature(p),
-          Medium.saturationPressure(wall.T[j]) - p,
-          hv - hl,
-          0))*(if j == N then 2 else 1) else if (h[j - 1] + h[j])/2 > hCHF
-         then ((h[j - 1] - hCHF)/(h[j - 1] - h[j]) - 0.5)*(gamma_chf - f_chen(
-          w,
-          Dhyd,
-          A,
-          mu_ls,
-          k_ls,
-          cp_ls,
-          rhol,
-          sigma,
-          rhov,
-          mu_vs,
-          wall.T[j] - Medium.saturationTemperature(p),
-          Medium.saturationPressure(wall.T[j]) - p,
-          hv - hl,
-          xCHF))*(if j == N then 2 else 1) else 0);
-    end for;
-
-    // Compute corrections due to boundaries near the nodes to the right
-    // to achieve continuous h.t.c.
-    gamma_corr_right[N] = 0;
-    for j in 1:N - 1 loop
-      gamma_corr_right[j] = noEvent(if h[j] < hl then (if (h[j + 1] + h[j])/2
-         > hl then ((h[j + 1] - hl)/(h[j + 1] - h[j]) - 0.5)*(f_chen(
-          w,
-          Dhyd,
-          A,
-          mu_ls,
-          k_ls,
-          cp_ls,
-          rhol,
-          sigma,
-          rhov,
-          mu_vs,
-          wall.T[j] - Medium.saturationTemperature(p),
-          Medium.saturationPressure(wall.T[j]) - p,
-          hv - hl,
-          0) - gamma_ls)*(if j == 1 then 2 else 1) else 0) else if h[j] > hCHF
-         then (if (h[j + 1] + h[j])/2 < hCHF then ((hCHF - h[j + 1])/(h[j] - h[
-        j + 1]) - 0.5)*(f_chen(
-          w,
-          Dhyd,
-          A,
-          mu_ls,
-          k_ls,
-          cp_ls,
-          rhol,
-          sigma,
-          rhov,
-          mu_vs,
-          wall.T[j] - Medium.saturationTemperature(p),
-          Medium.saturationPressure(wall.T[j]) - p,
-          hv - hl,
-          xCHF) - gamma_chf)*(if j == 1 then 2 else 1) else 0) else if (h[j + 1]
-         + h[j])/2 < hl then ((hl - h[j + 1])/(h[j] - h[j + 1]) - 0.5)*(
-        gamma_ls - f_chen(
-          w,
-          Dhyd,
-          A,
-          mu_ls,
-          k_ls,
-          cp_ls,
-          rhol,
-          sigma,
-          rhov,
-          mu_vs,
-          wall.T[j] - Medium.saturationTemperature(p),
-          Medium.saturationPressure(wall.T[j]) - p,
-          hv - hl,
-          0))*(if j == 1 then 2 else 1) else if (h[j + 1] + h[j])/2 > hCHF
-         then ((h[j + 1] - hCHF)/(h[j + 1] - h[j]) - 0.5)*(gamma_chf - f_chen(
-          w,
-          Dhyd,
-          A,
-          mu_ls,
-          k_ls,
-          cp_ls,
-          rhol,
-          sigma,
-          rhov,
-          mu_vs,
-          wall.T[j] - Medium.saturationTemperature(p),
-          Medium.saturationPressure(wall.T[j]) - p,
-          hv - hl,
-          xCHF))*(if j == 1 then 2 else 1) else 0);
-    end for;
-
-    wall.gamma = gamma + gamma_corr_left + gamma_corr_right
-      "H.t.c. including smoothing terms";
-    annotation (Documentation(info="<HTML>
+</html>"));
+  end Flow1D2phDB;
+
+  model Flow1D2phChen "1-dimensional fluid flow model for 2-phase boiling flow (finite volumes, 2-phase, Chen correlation)"
+    extends Flow1D2ph(redeclare Thermal.DHThtc wall);
+    parameter Real xCHF = 0.9 "Steam quality corresponding to Critical Heat Flux";
+    Medium.ThermodynamicState bubble "Bubble point state";
+    Medium.ThermodynamicState dew "Dew point state";
+  protected
+    SI.CoefficientOfHeatTransfer gamma[N] "Raw heat transfer coefficient";
+    SI.CoefficientOfHeatTransfer gamma_ls "H.t.c. just before bubble point";
+    SI.CoefficientOfHeatTransfer gamma_chf "H.t.c. just after CHF";
+    SI.CoefficientOfHeatTransfer gamma_corr_left[N] "Correction term to get smooth h.t.c.";
+    SI.CoefficientOfHeatTransfer gamma_corr_right[N] "Correction term to get smooth h.t.c.";
+    Medium.SpecificEnthalpy hCHF "Enthalpy corresponding to the Critical Heat Flux";
+    Medium.DynamicViscosity mu_ls "Dynamic viscosity at bubble point";
+    Medium.DynamicViscosity mu_vs "Dynamic viscosity at dew point";
+    Medium.ThermalConductivity k_ls "Thermal conductivity at bubble point";
+    Medium.ThermalConductivity k_vs "Thermal conductivity at dew point";
+    Medium.SpecificHeatCapacity cp_ls "Specific heat capacity at bubble point";
+    Medium.SpecificHeatCapacity cp_vs "Specific heat capacity at dew point";
+    Medium.SurfaceTension sigma "Surface tension";
+  equation
+    hCHF = hl + xCHF * (hv - hl) "Specific enthalpy corresponding to critical heat flux";
+// Saturated water and steam properties
+    bubble = Medium.setBubbleState(sat, 1);
+    dew = Medium.setDewState(sat, 1);
+    mu_ls = Medium.dynamicViscosity(bubble);
+    k_ls = Medium.thermalConductivity(bubble);
+    cp_ls = Medium.heatCapacity_cp(bubble);
+    mu_vs = Medium.dynamicViscosity(dew);
+    k_vs = Medium.thermalConductivity(dew);
+    cp_vs = Medium.heatCapacity_cp(dew);
+    sigma = Medium.surfaceTension(sat);
+// H.t.c. just outside the nucleate boiling region
+    gamma_ls = f_dittus_boelter(w, Dhyd, A, mu_ls, k_ls, cp_ls);
+    gamma_chf = f_dittus_boelter(w * xCHF, Dhyd, A, mu_vs, k_vs, cp_vs);
+// Nodal h.t.c. computations
+    for j in 1:N loop
+// a) Subcooled liquid
+// b) Wet steam after dryout: Dittus-Boelter's correlation considering
+//    only the vapour phase
+// c) Nucleate boiling: constant h.t.c.
+      gamma[j] = noEvent(if h[j] < hl or h[j] > hv then f_dittus_boelter(w, Dhyd, A, Medium.dynamicViscosity(fluidState[j]), Medium.thermalConductivity(fluidState[j]), Medium.heatCapacity_cp(fluidState[j])) else if h[j] > hCHF then f_dittus_boelter(w * x[j], Dhyd, A, mu_vs, k_vs, cp_vs) else f_chen(w, Dhyd, A, mu_ls, k_ls, cp_ls, rhol, sigma, rhov, mu_vs, wall.T[j] - Medium.saturationTemperature(p), Medium.saturationPressure(wall.T[j]) - p, hv - hl, x[j]));
+    end for;
+// Corrections due to boundaries near the nodes to the left
+// to achieve continuous h.t.c.
+    gamma_corr_left[1] = 0;
+    for j in 2:N loop
+      gamma_corr_left[j] = noEvent(if h[j] < hl then if (h[j - 1] + h[j]) / 2 > hl then ((h[j - 1] - hl) / (h[j - 1] - h[j]) - 0.5) * (f_chen(w, Dhyd, A, mu_ls, k_ls, cp_ls, rhol, sigma, rhov, mu_vs, wall.T[j] - Medium.saturationTemperature(p), Medium.saturationPressure(wall.T[j]) - p, hv - hl, 0) - gamma_ls) * (if j == N then 2 else 1) else 0 else if h[j] > hCHF then if (h[j - 1] + h[j]) / 2 < hCHF then ((hCHF - h[j - 1]) / (h[j] - h[j - 1]) - 0.5) * (f_chen(w, Dhyd, A, mu_ls, k_ls, cp_ls, rhol, sigma, rhov, mu_vs, wall.T[j] - Medium.saturationTemperature(p), Medium.saturationPressure(wall.T[j]) - p, hv - hl, xCHF) - gamma_chf) * (if j == N then 2 else 1) else 0 else if (h[j - 1] + h[j]) / 2 < hl then ((hl - h[j - 1]) / (h[j] - h[j - 1]) - 0.5) * (gamma_ls - f_chen(w, Dhyd, A, mu_ls, k_ls, cp_ls, rhol, sigma, rhov, mu_vs, wall.T[j] - Medium.saturationTemperature(p), Medium.saturationPressure(wall.T[j]) - p, hv - hl, 0)) * (if j == N then 2 else 1) else if (h[j - 1] + h[j]) / 2 > hCHF then ((h[j - 1] - hCHF) / (h[j - 1] - h[j]) - 0.5) * (gamma_chf - f_chen(w, Dhyd, A, mu_ls, k_ls, cp_ls, rhol, sigma, rhov, mu_vs, wall.T[j] - Medium.saturationTemperature(p), Medium.saturationPressure(wall.T[j]) - p, hv - hl, xCHF)) * (if j == N then 2 else 1) else 0);
+    end for;
+// Compute corrections due to boundaries near the nodes to the right
+// to achieve continuous h.t.c.
+    gamma_corr_right[N] = 0;
+    for j in 1:N - 1 loop
+      gamma_corr_right[j] = noEvent(if h[j] < hl then if (h[j + 1] + h[j]) / 2 > hl then ((h[j + 1] - hl) / (h[j + 1] - h[j]) - 0.5) * (f_chen(w, Dhyd, A, mu_ls, k_ls, cp_ls, rhol, sigma, rhov, mu_vs, wall.T[j] - Medium.saturationTemperature(p), Medium.saturationPressure(wall.T[j]) - p, hv - hl, 0) - gamma_ls) * (if j == 1 then 2 else 1) else 0 else if h[j] > hCHF then if (h[j + 1] + h[j]) / 2 < hCHF then ((hCHF - h[j + 1]) / (h[j] - h[j + 1]) - 0.5) * (f_chen(w, Dhyd, A, mu_ls, k_ls, cp_ls, rhol, sigma, rhov, mu_vs, wall.T[j] - Medium.saturationTemperature(p), Medium.saturationPressure(wall.T[j]) - p, hv - hl, xCHF) - gamma_chf) * (if j == 1 then 2 else 1) else 0 else if (h[j + 1] + h[j]) / 2 < hl then ((hl - h[j + 1]) / (h[j] - h[j + 1]) - 0.5) * (gamma_ls - f_chen(w, Dhyd, A, mu_ls, k_ls, cp_ls, rhol, sigma, rhov, mu_vs, wall.T[j] - Medium.saturationTemperature(p), Medium.saturationPressure(wall.T[j]) - p, hv - hl, 0)) * (if j == 1 then 2 else 1) else if (h[j + 1] + h[j]) / 2 > hCHF then ((h[j + 1] - hCHF) / (h[j + 1] - h[j]) - 0.5) * (gamma_chf - f_chen(w, Dhyd, A, mu_ls, k_ls, cp_ls, rhol, sigma, rhov, mu_vs, wall.T[j] - Medium.saturationTemperature(p), Medium.saturationPressure(wall.T[j]) - p, hv - hl, xCHF)) * (if j == 1 then 2 else 1) else 0);
+    end for;
+    wall.gamma = gamma + gamma_corr_left + gamma_corr_right "H.t.c. including smoothing terms";
+    annotation(
+      Documentation(info = "<HTML>
 <p>This model extends <tt>Flow1D2ph</tt> by computing the distribution of the heat transfer coefficient <tt>gamma</tt> and making it available through an extended version of the <tt>wall</tt> connector.
 <p>The model can be used for one-phase or two-phase water/steam flow. The heat transfer coefficient is computed according to the following hypotheses:
 <ul>
@@ -7454,7 +5677,7 @@
 <li>J. C. Collier: <i>Convective Boiling and Condensation</i>, 2nd ed.,McGraw Hill, 1981, pp. 215-220.
 </ol>
 <p><b>Revision history:</b></p>
-</HTML>", revisions="<html>
+</HTML>", revisions = "<html>
 <ul>
 <li><i>24 Mar 2005</i>
     by <a href=\"mailto:francesco.casella@polimi.it\">Francesco Casella</a>:<br>
@@ -7471,395 +5694,288 @@
 <li><i>11 Feb 2004</i>
        First release.</li>
 </ul>
-</html>"));
-  end Flow1D2phChen;
-
-  model Flow1Dfem
-    "1-dimensional fluid flow model for water/steam (finite elements)"
-    extends Modelica.Icons.ObsoleteModel;
-    extends BaseClasses.Flow1DBase;
-    replaceable ThermoPower.Thermal.DHT wall(N=N) annotation (Dialog(enable=
-            false), Placement(transformation(extent={{-40,40},{40,60}},
-            rotation=0)));
-    import Modelica.Math.*;
-    import ThermoPower.Choices.Flow1D.FFtypes;
-    import ThermoPower.Choices.Flow1D.HCtypes;
-    Medium.ThermodynamicState fluidState[N]
-      "Thermodynamic state of the fluid at the nodes";
-    parameter Real alpha(
-      min=0,
-      max=1) = 1 "Numerical stabilization coefficient";
-    parameter Real ML(
-      min=0,
-      max=1) = 0 "Mass Lumping Coefficient";
-    parameter Real wnf_bc=0.01
-      "Fraction of the nominal total mass flow rate for FEM regularization";
-    parameter Boolean regularizeBoundaryConditions = false
-      "Regularize boundary condition matrices";
-    parameter Boolean idealGasDensityDistribution = false
-      "Assume ideal-gas-type density distributions for mass balances";
-    constant Real g=Modelica.Constants.g_n;
-    final parameter Boolean evenN=(div(N, 2)*2 == N)
-      "The number of nodes is even";
-    SI.Length omega_hyd "Hydraulic perimeter (single tube)";
-    Real Kf[N] "Friction coefficients";
-    Real Cf[N] "Fanning friction factors";
-    Real dwdt "Dynamic momentum term";
-    Medium.AbsolutePressure p(start=pstart) "Fluid pressure";
-    SI.Pressure Dpfric "Pressure drop due to friction (total)";
-    SI.Pressure Dpfric1
-      "Pressure drop due to friction (from inlet to capacitance)";
-    SI.Pressure Dpfric2
-      "Pressure drop due to friction (from capacitance to outlet)";
-    SI.Pressure Dpstat "Pressure drop due to static head";
-    SI.MassFlowRate w[N](each start=wnom/Nt) "Mass flowrate (single tube)";
-    SI.Velocity u[N] "Fluid velocity";
-    SI.HeatFlux phi[N] "External heat flux";
-    Medium.Temperature T[N] "Fluid temperature";
-    Medium.SpecificEnthalpy h[N](start=hstart) "Fluid specific enthalpy";
-    Medium.Density rho[N] "Fluid density";
-    SI.SpecificVolume v[N] "Fluid specific volume";
-    SI.Mass Mtot "Total mass of fluid";
-  protected
-    SI.DerDensityByEnthalpy drdh[N] "Derivative of density by enthalpy";
-    SI.DerDensityByPressure drdp[N] "Derivative of density by pressure";
-    Real dvdt[N] "Time derivatives of specific volume";
-
-    Real Y[N, N];
-    Real M[N, N];
-    Real D[N];
-    Real D1[N];
-    Real D2[N];
-    Real G[N];
-    Real B[N, N];
-    Real C[N, N];
-    Real K[N, N];
-
-    Real alpha_sgn;
-
-    Real YY[N, N];
-
-  equation
-    //All equations are referred to a single tube
-
-    // Selection of representative pressure variable
-    if HydraulicCapacitance == HCtypes.Middle then
-      p = infl.p - Dpfric1 - Dpstat/2;
-    elseif HydraulicCapacitance == HCtypes.Upstream then
-      p = infl.p;
-    elseif HydraulicCapacitance == HCtypes.Downstream then
-      p = outfl.p;
-    else
-      assert(false, "Unsupported HydraulicCapacitance option");
-    end if;
-
-    //Friction factor selection
-    omega_hyd = 4*A/Dhyd;
-    for i in 1:N loop
-      if FFtype == FFtypes.Kfnom then
-        Kf[i] = Kfnom*Kfc;
-      elseif FFtype == FFtypes.OpPoint then
-        Kf[i] = dpnom*rhonom/(wnom/Nt)^2*Kfc;
-      elseif FFtype == FFtypes.Cfnom then
-        Cf[i] = Cfnom*Kfc;
-      elseif FFtype == FFtypes.Colebrook then
-        Cf[i] = f_colebrook(
-            w[i],
-            Dhyd/A,
-            e,
-            Medium.dynamicViscosity(fluidState[i]))*Kfc;
-      elseif FFtype == FFtypes.NoFriction then
-        Cf[i] = 0;
-      end if;
-      assert(Kf[i] >= 0, "Negative friction coefficient");
-      Kf[i] = Cf[i]*omega_hyd*L/(2*A^3)
-        "Relationship between friction coefficient and Fanning friction factor";
-    end for;
-
-    //Dynamic Momentum [not] accounted for
-    if DynamicMomentum then
-      if HydraulicCapacitance == HCtypes.Upstream then
-        dwdt = der(w[N]);
-      elseif HydraulicCapacitance == HCtypes.Downstream then
-        dwdt = der(w[1]);
-      else
-        assert(false,
-          "DynamicMomentum == true requires either Upstream or Downstream capacitance");
-      end if;
-    else
-      dwdt = 0;
-    end if;
-
-    L/A*dwdt + (outfl.p - infl.p) + Dpstat + Dpfric = 0
-      "Momentum balance equation";
-
-    w[1] = infl.m_flow/Nt "Inlet flow rate - single tube";
-    w[N] = -outfl.m_flow/Nt "Outlet flow rate - single tube";
-
-    Dpfric = Dpfric1 + Dpfric2 "Total pressure drop due to friction";
-
-    if FFtype == FFtypes.NoFriction then
-      Dpfric1 = 0;
-      Dpfric2 = 0;
-    else
-      Dpfric1 = homotopy(sum(Kf[i]/L*squareReg(w[i], wnom/Nt*wnf)*D1[i]/rho[i]
-        for i in 1:N), dpnom/2/(wnom/Nt)*w[1])
-        "Pressure drop from inlet to capacitance";
-      Dpfric2 = homotopy(sum(Kf[i]/L*squareReg(w[i], wnom/Nt*wnf)*D2[i]/rho[i]
-        for i in 1:N), dpnom/2/(wnom/Nt)*w[N])
-        "Pressure drop from capacitance to outlet";
-    end if "Pressure drop due to friction";
-
-    Dpstat = if abs(dzdx) < 1e-6 then 0 else g*dzdx*rho*D
-      "Pressure drop due to static head";
-    ((1 - ML)*Y + ML*YY)*der(h) + B/A*h + C*h/A = der(p)*G + M*(omega/A)*phi +
-      K*w/A "Energy balance equation";
-
-    // Fluid property calculations
-    for j in 1:N loop
-      fluidState[j] = Medium.setState_phX(p, h[j]);
-      T[j] = Medium.temperature(fluidState[j]);
-      rho[j] = Medium.density(fluidState[j]);
-      drdp[j] = if Medium.singleState then 0 else Medium.density_derp_h(
-        fluidState[j]);
-      drdh[j] = Medium.density_derh_p(fluidState[j]);
-      dvdt[j] = -1/rho[j]^2*(drdp[j]*der(p) + drdh[j]*der(h[j]));
-      v[j] = 1/rho[j];
-      u[j] = w[j]/(rho[j]*A);
-    end for;
-
-    //Wall energy flux and  temperature
-    T = wall.T;
-    phi = wall.phi;
-
-    //Boundary Values of outflowing fluid enthalpies
-    h[1] = infl.h_outflow;
-    h[N] = outfl.h_outflow;
-
-    alpha_sgn = alpha*sign(infl.m_flow - outfl.m_flow);
-
-    for i in 1:N - 1 loop
-      if idealGasDensityDistribution then
-        (w[i + 1] - w[i]) = noEvent(
-          if abs((v[i+1]-v[i])/v[i]) < 1e-7 then
-             2*A*l/(v[i]+v[i+1])^2*(dvdt[i]+dvdt[i+1])
-          else
-             -A*l/(v[i+1]-v[i])*(
-              (dvdt[i+1]*v[i]-dvdt[i]*v[i+1])/(v[i+1]*v[i]) -
-              (dvdt[i+1]-dvdt[i])/(v[i+1]-v[i])*log(v[i+1]/v[i])));
-      else
-      (w[i + 1] - w[i]) = -A*l*(
-        der(p)*1/2*(drdp[i + 1] + drdp[i]) +
-        1/6*(der(h[i])*(2*drdh[i] + drdh[i + 1]) +
-             der(h[i + 1])*(drdh[i] + 2*drdh[i + 1]))) "Mass balance equations";
-      end if;
-    end for;
-
-    // Energy equation FEM matrices
-    Y[1, 1] = rho[1]*((-l/12)*(2*alpha_sgn - 3)) + rho[2]*((-l/12)*(alpha_sgn
-       - 1));
-    Y[1, 2] = rho[1]*((-l/12)*(alpha_sgn - 1)) + rho[2]*((-l/12)*(2*alpha_sgn
-       - 1));
-    Y[N, N] = rho[N - 1]*((l/12)*(alpha_sgn + 1)) + rho[N]*((l/12)*(2*alpha_sgn
-       + 3));
-    Y[N, N - 1] = rho[N - 1]*((l/12)*(2*alpha_sgn + 1)) + rho[N]*((l/12)*(
-      alpha_sgn + 1));
-    if N > 2 then
-      for i in 2:N - 1 loop
-        Y[i, i - 1] = rho[i - 1]*((l/12)*(2*alpha_sgn + 1)) + rho[i]*((l/12)*(
-          alpha_sgn + 1));
-        Y[i, i] = rho[i - 1]*((l/12)*(alpha_sgn + 1)) + rho[i]*(l/2) + rho[i +
-          1]*(-(l/12)*(alpha_sgn - 1));
-        Y[i, i + 1] = rho[i]*((-l/12)*(alpha_sgn - 1)) + rho[i + 1]*((-l/12)*(2
-          *alpha_sgn - 1));
-        Y[1, i + 1] = 0;
-        Y[N, i - 1] = 0;
-        for j in 1:(i - 2) loop
-          Y[i, j] = 0;
-        end for;
-        for j in (i + 2):N loop
-          Y[i, j] = 0;
-        end for;
-      end for;
-    end if;
-
-    for i in 1:N loop
-      for j in 1:N loop
-        YY[i, j] = if (i <> j) then 0 else sum(Y[:, j]);
-      end for;
-    end for;
-
-    M[1, 1] = l/3 - l*alpha_sgn/4;
-    M[N, N] = l/3 + l*alpha_sgn/4;
-    M[1, 2] = l/6 - l*alpha_sgn/4;
-    M[N, (N - 1)] = l/6 + l*alpha_sgn/4;
-    if N > 2 then
-      for i in 2:N - 1 loop
-        M[i, i - 1] = l/6 + l*alpha_sgn/4;
-        M[i, i] = 2*l/3;
-        M[i, i + 1] = l/6 - l*alpha_sgn/4;
-        M[1, i + 1] = 0;
-        M[N, i - 1] = 0;
-        for j in 1:(i - 2) loop
-          M[i, j] = 0;
-        end for;
-        for j in (i + 2):N loop
-          M[i, j] = 0;
-        end for;
-      end for;
-    end if;
-
-    B[1, 1] = (-1/3 + alpha_sgn/4)*w[1] + (-1/6 + alpha_sgn/4)*w[2];
-    B[1, 2] = (1/3 - alpha_sgn/4)*w[1] + (1/6 - alpha_sgn/4)*w[2];
-    B[N, N] = (1/6 + alpha_sgn/4)*w[N - 1] + (1/3 + alpha_sgn/4)*w[N];
-    B[N, N - 1] = (-1/(6) - alpha_sgn/4)*w[N - 1] + (-1/3 - alpha_sgn/4)*w[N];
-    if N > 2 then
-      for i in 2:N - 1 loop
-        B[i, i - 1] = (-1/6 - alpha_sgn/4)*w[i - 1] + (-1/3 - alpha_sgn/4)*w[i];
-        B[i, i] = (1/6 + alpha_sgn/4)*w[i - 1] + (alpha_sgn/2)*w[i] + (-1/6 +
-          alpha_sgn/4)*w[i + 1];
-        B[i, i + 1] = (1/3 - alpha_sgn/4)*w[i] + (1/6 - alpha_sgn/4)*w[i + 1];
-        B[1, i + 1] = 0;
-        B[N, i - 1] = 0;
-        for j in 1:(i - 2) loop
-          B[i, j] = 0;
-        end for;
-        for j in (i + 2):N loop
-          B[i, j] = 0;
-        end for;
-      end for;
-    end if;
-
-    if Medium.singleState then
-      G = zeros(N) "No influence of pressure";
-    else
-      G[1] = l/2*(1 - alpha_sgn);
-      G[N] = l/2*(1 + alpha_sgn);
-      if N > 2 then
-        for i in 2:N - 1 loop
-          G[i] = l;
-        end for;
-      end if;
-    end if;
-
-    // boundary condition matrices
-    if regularizeBoundaryConditions then
-      C[1, 1] = Functions.stepReg(
-        infl.m_flow - wnom*wnf_bc,
-        (1 - alpha_sgn/2)*w[1],
-        0,
-        wnom*wnf_bc);
-      C[N, N] = Functions.stepReg(
-        outfl.m_flow - wnom*wnf_bc,
-        -(1 + alpha_sgn/2)*w[N],
-        0,
-        wnom*wnf_bc);
-    else
-      C[1, 1] = noEvent(if infl.m_flow >= 0 then (1 - alpha_sgn/2)*w[1] else 0);
-      C[N, N] = noEvent(if outfl.m_flow >= 0 then -(1 + alpha_sgn/2)*w[N] else 0);
-    end if;
-    C[N, 1] = 0;
-    C[1, N] = 0;
-    if (N > 2) then
-      for i in 2:(N - 1) loop
-        C[1, i] = 0;
-        C[N, i] = 0;
-        for j in 1:N loop
-          C[i, j] = 0;
-        end for;
-      end for;
-    end if;
-
-    if regularizeBoundaryConditions then
-      K[1, 1] = Functions.stepReg(
-        infl.m_flow - wnom*wnf_bc,
-        (1 - alpha_sgn/2)*inStream(infl.h_outflow),
-        0,
-        wnom*wnf_bc);
-      K[N, N] = Functions.stepReg(
-        outfl.m_flow - wnom*wnf_bc,
-        -(1 + alpha_sgn/2)*inStream(outfl.h_outflow),
-        0,
-        wnom*wnf_bc);
-    else
-      K[1, 1] = noEvent(if infl.m_flow >= 0 then (1 - alpha_sgn/2)*inStream(infl.h_outflow) else 0);
-      K[N, N] = noEvent(if outfl.m_flow >= 0 then -(1 + alpha_sgn/2)*inStream(outfl.h_outflow) else 0);
-    end if;
-
-    K[N, 1] = 0;
-    K[1, N] = 0;
-    if (N > 2) then
-      for i in 2:(N - 1) loop
-        K[1, i] = 0;
-        K[N, i] = 0;
-        for j in 1:N loop
-          K[i, j] = 0;
-        end for;
-      end for;
-    end if;
-
-    // Momentum and Mass balance equation matrices
-    D[1] = l/2;
-    D[N] = l/2;
-    for i in 2:N - 1 loop
-      D[i] = l;
-    end for;
-    if HydraulicCapacitance == HCtypes.Middle then
-      D1 = l*(if N == 2 then {3/8,1/8} else if evenN then cat(
-          1,
-          {1/2},
-          ones(max(0, div(N, 2) - 2)),
-          {7/8,1/8},
-          zeros(div(N, 2) - 1)) else cat(
-          1,
-          {1/2},
-          ones(div(N, 2) - 1),
-          {1/2},
-          zeros(div(N, 2))));
-      D2 = l*(if N == 2 then {1/8,3/8} else if evenN then cat(
-          1,
-          zeros(div(N, 2) - 1),
-          {1/8,7/8},
-          ones(max(div(N, 2) - 2, 0)),
-          {1/2}) else cat(
-          1,
-          zeros(div(N, 2)),
-          {1/2},
-          ones(div(N, 2) - 1),
-          {1/2}));
-    elseif HydraulicCapacitance == HCtypes.Upstream then
-      D1 = zeros(N);
-      D2 = D;
-    elseif HydraulicCapacitance == HCtypes.Downstream then
-      D1 = D;
-      D2 = zeros(N);
-    else
-      assert(false, "Unsupported HydraulicCapacitance option");
-    end if;
-
-    Q = Nt*omega*D*phi "Total heat flow through lateral boundary";
-    Mtot = Nt*D*rho*A "Total mass of fluid";
-    Tr = noEvent(Mtot/max(abs(infl.m_flow), Modelica.Constants.eps))
-      "Residence time";
-  initial equation
-    if initOpt == Choices.Init.Options.noInit then
-      // do nothing
-    elseif initOpt == Choices.Init.Options.steadyState then
-      der(h) = zeros(N);
-      if (not Medium.singleState) then
-        der(p) = 0;
-      end if;
-    elseif initOpt == Choices.Init.Options.steadyStateNoP then
-      der(h) = zeros(N);
-    elseif initOpt == Choices.Init.Options.steadyStateNoT and not Medium.singleState then
-      der(p) = 0;
-    else
-      assert(false, "Unsupported initialisation option");
-    end if;
-    annotation (
-      Diagram(graphics),
-      Icon(graphics={Text(extent={{-100,-52},{100,-82}}, textString="%name")}),
-      Documentation(info="<HTML>
+</html>"));
+  end Flow1D2phChen;
+
+  model Flow1Dfem "1-dimensional fluid flow model for water/steam (finite elements)"
+    extends Modelica.Icons.ObsoleteModel;
+    extends BaseClasses.Flow1DBase;
+    replaceable ThermoPower.Thermal.DHT wall(N = N) annotation(
+      Dialog(enable = false),
+      Placement(transformation(extent = {{-40, 40}, {40, 60}}, rotation = 0)));
+    import Modelica.Math.*;
+    import ThermoPower.Choices.Flow1D.FFtypes;
+    import ThermoPower.Choices.Flow1D.HCtypes;
+    Medium.ThermodynamicState fluidState[N] "Thermodynamic state of the fluid at the nodes";
+    parameter Real alpha(min = 0, max = 1) = 1 "Numerical stabilization coefficient";
+    parameter Real ML(min = 0, max = 1) = 0 "Mass Lumping Coefficient";
+    parameter Real wnf_bc = 0.01 "Fraction of the nominal total mass flow rate for FEM regularization";
+    parameter Boolean regularizeBoundaryConditions = false "Regularize boundary condition matrices";
+    parameter Boolean idealGasDensityDistribution = false "Assume ideal-gas-type density distributions for mass balances";
+    constant Real g = Modelica.Constants.g_n;
+    final parameter Boolean evenN = div(N, 2) * 2 == N "The number of nodes is even";
+    SI.Length omega_hyd "Hydraulic perimeter (single tube)";
+    Real Kf[N] "Friction coefficients";
+    Real Cf[N] "Fanning friction factors";
+    Real dwdt "Dynamic momentum term";
+    Medium.AbsolutePressure p(start = pstart) "Fluid pressure";
+    SI.Pressure Dpfric "Pressure drop due to friction (total)";
+    SI.Pressure Dpfric1 "Pressure drop due to friction (from inlet to capacitance)";
+    SI.Pressure Dpfric2 "Pressure drop due to friction (from capacitance to outlet)";
+    SI.Pressure Dpstat "Pressure drop due to static head";
+    SI.MassFlowRate w[N](each start = wnom / Nt) "Mass flowrate (single tube)";
+    SI.Velocity u[N] "Fluid velocity";
+    SI.HeatFlux phi[N] "External heat flux";
+    Medium.Temperature T[N] "Fluid temperature";
+    Medium.SpecificEnthalpy h[N](start = hstart) "Fluid specific enthalpy";
+    Medium.Density rho[N] "Fluid density";
+    SI.SpecificVolume v[N] "Fluid specific volume";
+    SI.Mass Mtot "Total mass of fluid";
+  protected
+    SI.DerDensityByEnthalpy drdh[N] "Derivative of density by enthalpy";
+    SI.DerDensityByPressure drdp[N] "Derivative of density by pressure";
+    Real dvdt[N] "Time derivatives of specific volume";
+    Real Y[N, N];
+    Real M[N, N];
+    Real D[N];
+    Real D1[N];
+    Real D2[N];
+    Real G[N];
+    Real B[N, N];
+    Real C[N, N];
+    Real K[N, N];
+    Real alpha_sgn;
+    Real YY[N, N];
+  equation
+//All equations are referred to a single tube
+// Selection of representative pressure variable
+    if HydraulicCapacitance == HCtypes.Middle then
+      p = infl.p - Dpfric1 - Dpstat / 2;
+    elseif HydraulicCapacitance == HCtypes.Upstream then
+      p = infl.p;
+    elseif HydraulicCapacitance == HCtypes.Downstream then
+      p = outfl.p;
+    else
+      assert(false, "Unsupported HydraulicCapacitance option");
+    end if;
+//Friction factor selection
+    omega_hyd = 4 * A / Dhyd;
+    for i in 1:N loop
+      if FFtype == FFtypes.Kfnom then
+        Kf[i] = Kfnom * Kfc;
+      elseif FFtype == FFtypes.OpPoint then
+        Kf[i] = dpnom * rhonom / (wnom / Nt) ^ 2 * Kfc;
+      elseif FFtype == FFtypes.Cfnom then
+        Cf[i] = Cfnom * Kfc;
+      elseif FFtype == FFtypes.Colebrook then
+        Cf[i] = f_colebrook(w[i], Dhyd / A, e, Medium.dynamicViscosity(fluidState[i])) * Kfc;
+      elseif FFtype == FFtypes.NoFriction then
+        Cf[i] = 0;
+      end if;
+      assert(Kf[i] >= 0, "Negative friction coefficient");
+      Kf[i] = Cf[i] * omega_hyd * L / (2 * A ^ 3) "Relationship between friction coefficient and Fanning friction factor";
+    end for;
+//Dynamic Momentum [not] accounted for
+    if DynamicMomentum then
+      if HydraulicCapacitance == HCtypes.Upstream then
+        dwdt = der(w[N]);
+      elseif HydraulicCapacitance == HCtypes.Downstream then
+        dwdt = der(w[1]);
+      else
+        assert(false, "DynamicMomentum == true requires either Upstream or Downstream capacitance");
+      end if;
+    else
+      dwdt = 0;
+    end if;
+    L / A * dwdt + outfl.p - infl.p + Dpstat + Dpfric = 0 "Momentum balance equation";
+    w[1] = infl.m_flow / Nt "Inlet flow rate - single tube";
+    w[N] = -outfl.m_flow / Nt "Outlet flow rate - single tube";
+    Dpfric = Dpfric1 + Dpfric2 "Total pressure drop due to friction";
+    if FFtype == FFtypes.NoFriction then
+      Dpfric1 = 0;
+      Dpfric2 = 0;
+    else
+      Dpfric1 = homotopy(sum(Kf[i] / L * squareReg(w[i], wnom / Nt * wnf) * D1[i] / rho[i] for i in 1:N), dpnom / 2 / (wnom / Nt) * w[1]) "Pressure drop from inlet to capacitance";
+      Dpfric2 = homotopy(sum(Kf[i] / L * squareReg(w[i], wnom / Nt * wnf) * D2[i] / rho[i] for i in 1:N), dpnom / 2 / (wnom / Nt) * w[N]) "Pressure drop from capacitance to outlet";
+    end if "Pressure drop due to friction";
+    Dpstat = if abs(dzdx) < 1e-6 then 0 else g * dzdx * rho * D "Pressure drop due to static head";
+    ((1 - ML) * Y + ML * YY) * der(h) + B / A * h + C * h / A = der(p) * G + M * (omega / A) * phi + K * w / A "Energy balance equation";
+// Fluid property calculations
+    for j in 1:N loop
+      fluidState[j] = Medium.setState_phX(p, h[j]);
+      T[j] = Medium.temperature(fluidState[j]);
+      rho[j] = Medium.density(fluidState[j]);
+      drdp[j] = if Medium.singleState then 0 else Medium.density_derp_h(fluidState[j]);
+      drdh[j] = Medium.density_derh_p(fluidState[j]);
+      dvdt[j] = -1 / rho[j] ^ 2 * (drdp[j] * der(p) + drdh[j] * der(h[j]));
+      v[j] = 1 / rho[j];
+      u[j] = w[j] / (rho[j] * A);
+    end for;
+//Wall energy flux and  temperature
+    T = wall.T;
+    phi = wall.phi;
+//Boundary Values of outflowing fluid enthalpies
+    h[1] = infl.h_outflow;
+    h[N] = outfl.h_outflow;
+    alpha_sgn = alpha * sign(infl.m_flow - outfl.m_flow);
+    for i in 1:N - 1 loop
+      if idealGasDensityDistribution then
+        w[i + 1] - w[i] = noEvent(if abs((v[i + 1] - v[i]) / v[i]) < 1e-7 then 2 * A * l / (v[i] + v[i + 1]) ^ 2 * (dvdt[i] + dvdt[i + 1]) else -A * l / (v[i + 1] - v[i]) * ((dvdt[i + 1] * v[i] - dvdt[i] * v[i + 1]) / (v[i + 1] * v[i]) - (dvdt[i + 1] - dvdt[i]) / (v[i + 1] - v[i]) * log(v[i + 1] / v[i])));
+      else
+        w[i + 1] - w[i] = -A * l * (der(p) * 1 / 2 * (drdp[i + 1] + drdp[i]) + 1 / 6 * (der(h[i]) * (2 * drdh[i] + drdh[i + 1]) + der(h[i + 1]) * (drdh[i] + 2 * drdh[i + 1]))) "Mass balance equations";
+      end if;
+    end for;
+// Energy equation FEM matrices
+    Y[1, 1] = rho[1] * ((-l / 12) * (2 * alpha_sgn - 3)) + rho[2] * ((-l / 12) * (alpha_sgn - 1));
+    Y[1, 2] = rho[1] * ((-l / 12) * (alpha_sgn - 1)) + rho[2] * ((-l / 12) * (2 * alpha_sgn - 1));
+    Y[N, N] = rho[N - 1] * (l / 12 * (alpha_sgn + 1)) + rho[N] * (l / 12 * (2 * alpha_sgn + 3));
+    Y[N, N - 1] = rho[N - 1] * (l / 12 * (2 * alpha_sgn + 1)) + rho[N] * (l / 12 * (alpha_sgn + 1));
+    if N > 2 then
+      for i in 2:N - 1 loop
+        Y[i, i - 1] = rho[i - 1] * (l / 12 * (2 * alpha_sgn + 1)) + rho[i] * (l / 12 * (alpha_sgn + 1));
+        Y[i, i] = rho[i - 1] * (l / 12 * (alpha_sgn + 1)) + rho[i] * (l / 2) + rho[i + 1] * (-l / 12 * (alpha_sgn - 1));
+        Y[i, i + 1] = rho[i] * ((-l / 12) * (alpha_sgn - 1)) + rho[i + 1] * ((-l / 12) * (2 * alpha_sgn - 1));
+        Y[1, i + 1] = 0;
+        Y[N, i - 1] = 0;
+        for j in 1:i - 2 loop
+          Y[i, j] = 0;
+        end for;
+        for j in i + 2:N loop
+          Y[i, j] = 0;
+        end for;
+      end for;
+    end if;
+    for i in 1:N loop
+      for j in 1:N loop
+        YY[i, j] = if i <> j then 0 else sum(Y[:, j]);
+      end for;
+    end for;
+    M[1, 1] = l / 3 - l * alpha_sgn / 4;
+    M[N, N] = l / 3 + l * alpha_sgn / 4;
+    M[1, 2] = l / 6 - l * alpha_sgn / 4;
+    M[N, N - 1] = l / 6 + l * alpha_sgn / 4;
+    if N > 2 then
+      for i in 2:N - 1 loop
+        M[i, i - 1] = l / 6 + l * alpha_sgn / 4;
+        M[i, i] = 2 * l / 3;
+        M[i, i + 1] = l / 6 - l * alpha_sgn / 4;
+        M[1, i + 1] = 0;
+        M[N, i - 1] = 0;
+        for j in 1:i - 2 loop
+          M[i, j] = 0;
+        end for;
+        for j in i + 2:N loop
+          M[i, j] = 0;
+        end for;
+      end for;
+    end if;
+    B[1, 1] = ((-1 / 3) + alpha_sgn / 4) * w[1] + ((-1 / 6) + alpha_sgn / 4) * w[2];
+    B[1, 2] = (1 / 3 - alpha_sgn / 4) * w[1] + (1 / 6 - alpha_sgn / 4) * w[2];
+    B[N, N] = (1 / 6 + alpha_sgn / 4) * w[N - 1] + (1 / 3 + alpha_sgn / 4) * w[N];
+    B[N, N - 1] = ((-1 / 6) - alpha_sgn / 4) * w[N - 1] + ((-1 / 3) - alpha_sgn / 4) * w[N];
+    if N > 2 then
+      for i in 2:N - 1 loop
+        B[i, i - 1] = ((-1 / 6) - alpha_sgn / 4) * w[i - 1] + ((-1 / 3) - alpha_sgn / 4) * w[i];
+        B[i, i] = (1 / 6 + alpha_sgn / 4) * w[i - 1] + alpha_sgn / 2 * w[i] + ((-1 / 6) + alpha_sgn / 4) * w[i + 1];
+        B[i, i + 1] = (1 / 3 - alpha_sgn / 4) * w[i] + (1 / 6 - alpha_sgn / 4) * w[i + 1];
+        B[1, i + 1] = 0;
+        B[N, i - 1] = 0;
+        for j in 1:i - 2 loop
+          B[i, j] = 0;
+        end for;
+        for j in i + 2:N loop
+          B[i, j] = 0;
+        end for;
+      end for;
+    end if;
+    if Medium.singleState then
+      G = zeros(N) "No influence of pressure";
+    else
+      G[1] = l / 2 * (1 - alpha_sgn);
+      G[N] = l / 2 * (1 + alpha_sgn);
+      if N > 2 then
+        for i in 2:N - 1 loop
+          G[i] = l;
+        end for;
+      end if;
+    end if;
+// boundary condition matrices
+    if regularizeBoundaryConditions then
+      C[1, 1] = Functions.stepReg(infl.m_flow - wnom * wnf_bc, (1 - alpha_sgn / 2) * w[1], 0, wnom * wnf_bc);
+      C[N, N] = Functions.stepReg(outfl.m_flow - wnom * wnf_bc, -(1 + alpha_sgn / 2) * w[N], 0, wnom * wnf_bc);
+    else
+      C[1, 1] = noEvent(if infl.m_flow >= 0 then (1 - alpha_sgn / 2) * w[1] else 0);
+      C[N, N] = noEvent(if outfl.m_flow >= 0 then -(1 + alpha_sgn / 2) * w[N] else 0);
+    end if;
+    C[N, 1] = 0;
+    C[1, N] = 0;
+    if N > 2 then
+      for i in 2:N - 1 loop
+        C[1, i] = 0;
+        C[N, i] = 0;
+        for j in 1:N loop
+          C[i, j] = 0;
+        end for;
+      end for;
+    end if;
+    if regularizeBoundaryConditions then
+      K[1, 1] = Functions.stepReg(infl.m_flow - wnom * wnf_bc, (1 - alpha_sgn / 2) * inStream(infl.h_outflow), 0, wnom * wnf_bc);
+      K[N, N] = Functions.stepReg(outfl.m_flow - wnom * wnf_bc, -(1 + alpha_sgn / 2) * inStream(outfl.h_outflow), 0, wnom * wnf_bc);
+    else
+      K[1, 1] = noEvent(if infl.m_flow >= 0 then (1 - alpha_sgn / 2) * inStream(infl.h_outflow) else 0);
+      K[N, N] = noEvent(if outfl.m_flow >= 0 then -(1 + alpha_sgn / 2) * inStream(outfl.h_outflow) else 0);
+    end if;
+    K[N, 1] = 0;
+    K[1, N] = 0;
+    if N > 2 then
+      for i in 2:N - 1 loop
+        K[1, i] = 0;
+        K[N, i] = 0;
+        for j in 1:N loop
+          K[i, j] = 0;
+        end for;
+      end for;
+    end if;
+// Momentum and Mass balance equation matrices
+    D[1] = l / 2;
+    D[N] = l / 2;
+    for i in 2:N - 1 loop
+      D[i] = l;
+    end for;
+    if HydraulicCapacitance == HCtypes.Middle then
+      D1 = l * (if N == 2 then {3 / 8, 1 / 8} else if evenN then cat(1, {1 / 2}, ones(max(0, div(N, 2) - 2)), {7 / 8, 1 / 8}, zeros(div(N, 2) - 1)) else cat(1, {1 / 2}, ones(div(N, 2) - 1), {1 / 2}, zeros(div(N, 2))));
+      D2 = l * (if N == 2 then {1 / 8, 3 / 8} else if evenN then cat(1, zeros(div(N, 2) - 1), {1 / 8, 7 / 8}, ones(max(div(N, 2) - 2, 0)), {1 / 2}) else cat(1, zeros(div(N, 2)), {1 / 2}, ones(div(N, 2) - 1), {1 / 2}));
+    elseif HydraulicCapacitance == HCtypes.Upstream then
+      D1 = zeros(N);
+      D2 = D;
+    elseif HydraulicCapacitance == HCtypes.Downstream then
+      D1 = D;
+      D2 = zeros(N);
+    else
+      assert(false, "Unsupported HydraulicCapacitance option");
+    end if;
+    Q = Nt * omega * D * phi "Total heat flow through lateral boundary";
+    Mtot = Nt * D * rho * A "Total mass of fluid";
+    Tr = noEvent(Mtot / max(abs(infl.m_flow), Modelica.Constants.eps)) "Residence time";
+  initial equation
+    if initOpt == Choices.Init.Options.noInit then
+// do nothing
+    elseif initOpt == Choices.Init.Options.steadyState then
+      der(h) = zeros(N);
+      if not Medium.singleState then
+        der(p) = 0;
+      end if;
+    elseif initOpt == Choices.Init.Options.steadyStateNoP then
+      der(h) = zeros(N);
+    elseif initOpt == Choices.Init.Options.steadyStateNoT and not Medium.singleState then
+      der(p) = 0;
+    else
+      assert(false, "Unsupported initialisation option");
+    end if;
+    annotation(
+      Diagram(graphics),
+      Icon(graphics = {Text(extent = {{-100, -52}, {100, -82}}, textString = "%name")}),
+      Documentation(info = "<HTML>
 <p>This model describes the flow of water or steam in a rigid tube. The basic modelling assumptions are:
 <ul><li>The fluid state is always one-phase (i.e. subcooled liquid or superheated steam).
 <li>Uniform velocity is assumed on the cross section, leading to a 1-D distributed parameter model.
@@ -7887,7 +6003,7 @@
 <p>Start values for pressure and flowrate are specified by <tt>pstart</tt>, <tt>wstart</tt>. The start values for the node enthalpies are linearly distributed from <tt>hstartin</tt> at the inlet to <tt>hstartout</tt> at the outlet.
 <p>A bank of <tt>Nt</tt> identical tubes working in parallel can be modelled by setting <tt>Nt > 1</tt>. The geometric parameters always refer to a <i>single</i> tube.
 <p>This models makes the temperature and external heat flow distributions visible through the <tt>wall</tt> connector. If other variables (e.g. the heat transfer coefficient) are needed by external components to compute the actual heat flow, the <tt>wall</tt> connector can be replaced by an extended version of the <tt>DHT</tt> connector.
-</HTML>", revisions="<html>
+</HTML>", revisions = "<html>
 <ul>
 <li><i>24 Mar 2005</i>
     by <a href=\"mailto:francesco.casella@polimi.it\">Francesco Casella</a>:<br>
@@ -7917,708 +6033,519 @@
     by <a href=\"mailto:francesco.schiavo@polimi.it\">Francesco Schiavo</a>:<br>
        First release.</li>
 </ul>
-</html>"));
-  end Flow1Dfem;
-
-  model Flow1Dfem2ph
-    "1-dimensional fluid flow model for water/steam (finite elements)"
-    extends Modelica.Icons.ObsoleteModel;
-    import Modelica.Math.*;
-    import ThermoPower.Choices.Flow1D.FFtypes;
-    import ThermoPower.Choices.Flow1D.HCtypes;
-    extends BaseClasses.Flow1DBase(redeclare replaceable package Medium =
-          StandardWater                constrainedby
-        Modelica.Media.Interfaces.PartialTwoPhaseMedium
-                        "Medium model");
-    replaceable ThermoPower.Thermal.DHT wall(N=N) annotation (Dialog(enable=
-            false), Placement(transformation(extent={{-40,40},{40,60}},
-            rotation=0)));
-    parameter Real alpha(
-      min=0,
-      max=2) = 1 "Numerical stabilization coefficient";
-    parameter Real ML(
-      min=0,
-      max=1) = 0.2 "Mass Lumping Coefficient";
-    constant Real g=Modelica.Constants.g_n;
-    final parameter Boolean evenN=(div(N, 2)*2 == N)
-      "The number of nodes is even";
-    constant SI.Pressure pzero=10 "Small deltap for calculations";
-    constant SI.Pressure pc=Medium.fluidConstants[1].criticalPressure;
-    constant SI.SpecificEnthalpy hzero=1e-3;
-
-    Medium.ThermodynamicState fluidState[N]
-      "Thermodynamic state of the fluid at the nodes";
-    Medium.SaturationProperties sat "Properties of saturated fluid";
-    Medium.ThermodynamicState dew "Thermodynamic state at dewpoint";
-    Medium.ThermodynamicState bubble "Thermodynamic state at bubblepoint";
-    SI.Length omega_hyd "Hydraulic perimeter (single tube)";
-    Real dwdt "Dynamic momentum term";
-    Medium.AbsolutePressure p "Fluid pressure";
-    SI.Pressure Dpfric "Pressure drop due to friction";
-    SI.Pressure Dpfric1
-      "Pressure drop due to friction (from inlet to capacitance)";
-    SI.Pressure Dpfric2
-      "Pressure drop due to friction (from capacitance to outlet)";
-    SI.Pressure Dpstat "Pressure drop due to static head";
-    SI.MassFlowRate w[N](start=wnom*ones(N)) "Mass flowrate (single tube)";
-    SI.Velocity u[N] "Fluid velocity";
-    SI.HeatFlux phi[N] "External heat flux";
-    Medium.Temperature T[N] "Fluid temperature";
-    Medium.SpecificEnthalpy h[N](start=hstart) "Fluid specific enthalpy";
-    Medium.Density rho[N] "Fluid density";
-    SI.SpecificVolume v[N] "Fluid specific volume";
-
-    Medium.Temperature Ts "Saturation temperature";
-    Medium.SpecificEnthalpy hl(start=Medium.bubbleEnthalpy(Medium.setSat_p(
-          pstart))) "Saturated liquid specific enthalpy";
-    Medium.SpecificEnthalpy hv(start=Medium.dewEnthalpy(Medium.setSat_p(pstart)))
-      "Saturated vapour specific enthalpy";
-    Real x[N] "Steam quality";
-    Units.LiquidDensity rhol "Saturated liquid density";
-    Units.GasDensity rhov "Saturated vapour density";
-
-    Real Kf[N] "Friction coefficient";
-    Real Cf[N] "Fanning friction factor";
-    Real Phi[N] "Two-phase friction multiplier";
-  protected
-    SI.DerDensityByEnthalpy drdh[N] "Derivative of density by enthalpy";
-    SI.DerDensityByPressure drdp[N] "Derivative of density by pressure";
-
-    SI.DerDensityByPressure drl_dp
-      "Derivative of liquid density by pressure just before saturation";
-    SI.DerDensityByPressure drv_dp
-      "Derivative of vapour density by pressure just before saturation";
-    SI.DerDensityByEnthalpy drl_dh
-      "Derivative of liquid density by enthalpy just before saturation";
-    SI.DerDensityByEnthalpy drv_dh
-      "Derivative of vapour density by enthalpy just before saturation";
-
-    Real dhl "Derivative of saturated liquid enthalpy by pressure";
-    Real dhv "Derivative of saturated vapour enthalpy by pressure";
-
-    Real drl "Derivative of saturatd liquid density by pressure";
-    Real drv "Derivative of saturated vapour density by pressure";
-
-    SI.Density rhos[N - 1];
-    SI.MassFlowRate ws[N - 1];
-    Real rs[N - 1];
-
-    Real Y[N, N];
-    Real YY[N, N];
-
-    Real Y2ph[N, N];
-    Real M[N, N];
-    Real D[N];
-    Real D1[N];
-    Real D2[N];
-    Real G[N];
-    Real B[N, N];
-    Real B2ph[N, N];
-    Real C[N, N];
-    Real K[N, N];
-
-    Real by[8, N];
-    Real beta[8, N];
-    //coefficients matrix for 2-phases augmented FEM matrices
-    Real alpha_sgn;
-
-    Real gamma_rho[N - 1];
-    Real gamma_w[N - 1];
-    //coefficients for gamma functions
-
-    Real a;
-    Real b;
-    Real betap;
-    Real c;
-    Real d;
-    Real ee[N - 1];
-    Real f[N - 1];
-
-    Real dMbif[N - 1];
-    Real dMmono[N - 1];
-
-  equation
-    //All equations are referred to a single tube
-
-    // Selection of representative pressure variable
-    if HydraulicCapacitance == HCtypes.Middle then
-      p = infl.p - Dpfric1 - Dpstat/2;
-    elseif HydraulicCapacitance == HCtypes.Upstream then
-      p = infl.p;
-    elseif HydraulicCapacitance == HCtypes.Downstream then
-      p = outfl.p;
-    else
-      assert(false, "Unsupported HydraulicCapacitance option");
-    end if;
-
-    //Friction factor calculation
-    omega_hyd = 4*A/Dhyd;
-    for i in 1:N loop
-      if FFtype == FFtypes.NoFriction then
-        Cf[i] = 0;
-      elseif FFtype == FFtypes.Cfnom then
-        Cf[i] = Cfnom*Kfc;
-      else
-        assert(true, "Unsupported friction factor selection");
-      end if;
-      Kf[i] = Cf[i]*omega_hyd*L/(2*A^3)
-        "Relationship between friction coefficient and Fanning friction factor";
-    end for;
-
-    //Dynamic Momentum [not] accounted for
-    if DynamicMomentum then
-      if HydraulicCapacitance == HCtypes.Upstream then
-        dwdt = -der(outfl.m_flow)/Nt;
-      else
-        dwdt = der(infl.m_flow)/Nt;
-      end if;
-
-    else
-      dwdt = 0;
-    end if;
-
-    //Momentum balance equation
-    L/A*dwdt + (outfl.p - infl.p) + Dpstat + Dpfric = 0;
-
-    w[1] = infl.m_flow/Nt;
-    w[N] = -outfl.m_flow/Nt;
-
-    Dpfric = Dpfric1 + Dpfric2 "Total pressure drop due to friction";
-
-    if FFtype == FFtypes.NoFriction then
-      Dpfric1 = 0;
-      Dpfric2 = 0;
-    else
-      Dpfric1 = homotopy(sum(Kf[i]/L*squareReg(w[i], wnom/Nt*wnf)*D1[i]/rho[i]*
-        Phi[i] for i in 1:N), dpnom/2/(wnom/Nt)*w[1])
-        "Pressure drop from inlet to capacitance";
-      Dpfric2 = homotopy(sum(Kf[i]/L*squareReg(w[i], wnom/Nt*wnf)*D2[i]/rho[i]*
-        Phi[i] for i in 1:N), dpnom/2/(wnom/Nt)*w[N])
-        "Pressure drop from capacitance to outlet";
-    end if "Pressure drop due to friction";
-
-    for i in 1:N loop
-      if FFtype == FFtypes.NoFriction or noEvent(h[i] <= hl or h[i] >= hv) then
-        Phi[i] = 1;
-      else
-        // Chisholm-Laird formulation of Martinelli-Lockhart correlation for turbulent-turbulent flow
-        // Phi_l^2 = 1 + 20/Xtt + 1/Xtt^2
-        // same fixed Fanning friction factor Cfnom is assumed for liquid and vapour, so Xtt = (rhov/rhol)^0.5 * (1-x)/x
-        Phi[i] = rho[i]/rhol*((1 - x[i])^2 + 20*sqrt(rhol/rhov)*x[i]*(1 - x[i])
-           + rhol/rhov*x[i]^2);
-      end if;
-    end for;
-
-    Dpstat = if abs(dzdx) < 1e-6 then 0 else g*dzdx*rho*D
-      "Pressure drop due to static head";
-
-    //Energy balance equations
-    l/12*((1 - ML)*Y + ML*YY + 0*Y2ph)*der(h) + (1/A)*(B + 0*B2ph)*h + C*h/A =
-      der(p)*G + M*(omega/A)*phi + K*w/A;
-
-    //  (Ts,rhol,rhov,hl,hv,drl_dp,drv_dp,drl_dh,drv_dh,dhl,dhv,drl,drv) =
-    //  propsat_p_2der(noEvent(min(p, pc - pzero)));
-
-    sat.psat = p;
-    sat.Tsat = Medium.saturationTemperature(p);
-    Ts = sat.Tsat;
-    bubble = Medium.setBubbleState(sat);
-    dew = Medium.setDewState(sat);
-    rhol = Medium.bubbleDensity(sat);
-    rhov = Medium.dewDensity(sat);
-    hl = Medium.bubbleEnthalpy(sat);
-    hv = Medium.dewEnthalpy(sat);
-    drl = Medium.dBubbleDensity_dPressure(sat);
-    drv = Medium.dDewDensity_dPressure(sat);
-    dhl = Medium.dBubbleEnthalpy_dPressure(sat);
-    dhv = Medium.dDewEnthalpy_dPressure(sat);
-    drl_dp = Medium.density_derp_h(bubble);
-    drv_dp = Medium.density_derp_h(dew);
-    drl_dh = Medium.density_derh_p(bubble);
-    drv_dh = Medium.density_derh_p(dew);
-
-    a = ((hv - hl)*(rhol^2*drv + rhov^2*drl) + rhov*rhol*(rhol - rhov)*(dhv -
-      dhl))/(rhol - rhov)^2;
-    betap = ((rhol - rhov)*(rhov*dhv - rhol*dhl) + (hv - hl)*(rhol*drv - rhov*
-      drl))/(rhol - rhov)^2;
-    b = a*c + d*betap;
-    c = (rhov*hv - rhol*hl)/(rhol - rhov);
-    d = -rhol*rhov*(hv - hl)/(rhol - rhov);
-
-    //Computation of fluid properties
-    for j in 1:N loop
-      fluidState[j] = Medium.setState_phX(p, h[j]);
-      T[j] = Medium.temperature(fluidState[j]);
-      rho[j] = Medium.density(fluidState[j]);
-      drdp[j] = if Medium.singleState then 0 else Medium.density_derp_h(
-        fluidState[j]);
-      drdh[j] = Medium.density_derh_p(fluidState[j]);
-      v[j] = 1/rho[j];
-      u[j] = w[j]/(rho[j]*A);
-      x[j] = noEvent(min(max((h[j] - hl)/(hv - hl), 0), 1));
-    end for;
-
-    //Wall energy flux and  temperature
-    T = wall.T;
-    phi = wall.phi;
-
-    //Boundary Values
-
-    h[1] = infl.h_outflow;
-    h[N] = outfl.h_outflow;
-
-    alpha_sgn = alpha*sign(infl.m_flow - outfl.m_flow);
-
-    //phase change determination
-    for i in 1:N - 1 loop
-      (w[i] - w[i + 1]) = dMmono[i] + dMbif[i];
-      if noEvent(abs(h[i + 1] - h[i]) < hzero) then
-
-        rs[i] = 0;
-        rhos[i] = 0;
-        gamma_rho[i] = 0;
-
-        gamma_w[i] = 0;
-        ws[i] = 0;
-
-        dMmono[i] = A*l*(der(p)*1/2*(drdp[i + 1] + drdp[i]) + 1/6*(der(h[i])*(2
-          *drdh[i] + drdh[i + 1]) + der(h[i + 1])*(drdh[i] + 2*drdh[i + 1])));
-
-        dMbif[i] = 0;
-
-        ee[i] = 0;
-        f[i] = 0;
-
-      elseif noEvent((h[i] < hl) and (h[i + 1] >= hl) and (h[i + 1] <= hv)) then
-        //liquid - two phase
-
-        rs[i] = (hl - h[i])/(h[i + 1] - h[i]);
-        rhos[i] = rhol;
-        gamma_rho[i] = (rhos[i] - rho[i]*(1 - rs[i]) - rho[i + 1]*rs[i]);
-
-        gamma_w[i] = (ws[i] - w[i]*(1 - rs[i]) - w[i + 1]*rs[i]);
-
-        (w[i] - ws[i]) = dMmono[i];
-
-        dMmono[i] = A*rs[i]*l*(der(p)*1/2*(drl_dp + drdp[i]) + 1/6*(der(h[i])*(
-          2*drdh[i] + drl_dh) + (der(h[i])*(1 - rs[i]) + der(h[i + 1])*rs[i])*(
-          drdh[i] + 2*drl_dh)));
-
-        dMbif[i] = A*(1 - rs[i])*l/(h[i + 1] - hl)*(der(p)*((b - a*c)*(h[i + 1]
-           - hl)/((c + h[i + 1])*(c + hl)) + a*log((c + h[i + 1])/(c + hl))) +
-          ((d*f[i] - d*c*ee[i])*(h[i + 1] - hl)/((c + h[i + 1])*(c + hl)) + d*
-          ee[i]*log((c + h[i + 1])/(c + hl))));
-
-        ee[i] = (der(h[i + 1]) - (der(h[i + 1])*rs[i] + der(h[i])*(1 - rs[i])))
-          /(h[i + 1] - hl);
-        f[i] = ((der(h[i + 1])*rs[i] + der(h[i])*(1 - rs[i]))*h[i + 1] - der(h[
-          i + 1])*hl)/(h[i + 1] - hl);
-
-      elseif noEvent((h[i] >= hl) and (h[i] <= hv) and (h[i + 1] < hl)) then
-        //two phase-liquid
-
-        rs[i] = (hl - h[i])/(h[i + 1] - h[i]);
-        rhos[i] = rhol;
-        gamma_rho[i] = (rhos[i] - rho[i]*(1 - rs[i]) - rho[i + 1]*rs[i]);
-
-        gamma_w[i] = (ws[i] - w[i]*(1 - rs[i]) - w[i + 1]*rs[i]);
-
-        (w[i] - ws[i]) = dMbif[i];
-
-        dMmono[i] = A*(1 - rs[i])*l*(der(p)*1/2*(drdp[i + 1] + drl_dp) + 1/6*(
-          der(h[i])*(2*drl_dh + drdh[i + 1]) + (der(h[i + 1])*rs[i] + der(h[i])
-          *(1 - rs[i]))*(drl_dh + 2*drdh[i + 1])));
-
-        dMbif[i] = A*rs[i]*l/(hl - h[i])*(der(p)*((b - a*c)*(hl - h[i])/((c +
-          hl)*(c + h[i])) + a*log((c + hl)/(c + h[i]))) + ((d*f[i] - d*c*ee[i])
-          *(hl - h[i])/((c + hl)*(c + h[i])) + d*ee[i]*log((c + hl)/(c + h[i]))));
-
-        ee[i] = ((der(h[i + 1])*rs[i] + der(h[i])*(1 - rs[i])) - der(h[i]))/(hl
-           - h[i]);
-        f[i] = (der(h[i])*hl - (der(h[i + 1])*rs[i] + der(h[i])*(1 - rs[i]))*h[
-          i])/(hl - h[i]);
-
-      elseif noEvent((h[i] >= hl) and (h[i] <= hv) and (h[i + 1] > hv)) then
-        //two phase - vapour
-
-        rs[i] = (hv - h[i])/(h[i + 1] - h[i]);
-        rhos[i] = rhov;
-        gamma_rho[i] = (rhos[i] - rho[i]*(1 - rs[i]) - rho[i + 1]*rs[i]);
-
-        gamma_w[i] = (ws[i] - w[i]*(1 - rs[i]) - w[i + 1]*rs[i]);
-        (w[i] - ws[i]) = dMbif[i];
-
-        dMmono[i] = A*(1 - rs[i])*l*(der(p)*1/2*(drdp[i + 1] + drv_dp) + 1/6*(
-          der(h[i])*(2*drv_dh + drdh[i + 1]) + (der(h[i + 1])*rs[i] + der(h[i])
-          *(1 - rs[i]))*(drv_dh + 2*drdh[i + 1])));
-
-        dMbif[i] = A*rs[i]*l/(hv - h[i])*(der(p)*((b - a*c)*(hv - h[i])/((c +
-          hv)*(c + h[i])) + a*log((c + hv)/(c + h[i]))) + ((d*f[i] - d*c*ee[i])
-          *(hv - h[i])/((c + hv)*(c + h[i])) + d*ee[i]*log((c + hv)/(c + h[i]))));
-
-        ee[i] = ((der(h[i + 1])*rs[i] + der(h[i])*(1 - rs[i])) - der(h[i]))/(hv
-           - h[i]);
-        f[i] = (der(h[i])*hv - (der(h[i + 1])*rs[i] + der(h[i])*(1 - rs[i]))*h[
-          i])/(hv - h[i]);
-
-      elseif noEvent((h[i] > hv) and (h[i + 1] >= hl) and (h[i + 1] <= hv)) then
-        // vapour - two phase
-
-        rs[i] = (hv - h[i])/(h[i + 1] - h[i]);
-        rhos[i] = rhov;
-        gamma_rho[i] = (rhos[i] - rho[i]*(1 - rs[i]) - rho[i + 1]*rs[i]);
-
-        gamma_w[i] = (ws[i] - w[i]*(1 - rs[i]) - w[i + 1]*rs[i]);
-        (w[i] - ws[i]) = dMmono[i];
-
-        dMmono[i] = A*rs[i]*l*(der(p)*1/2*(drv_dp + drdp[i]) + 1/6*(der(h[i])*(
-          2*drdh[i] + drv_dh) + (der(h[i])*(1 - rs[i]) + der(h[i + 1])*rs[i])*(
-          drdh[i] + 2*drv_dh)));
-
-        dMbif[i] = A*(1 - rs[i])*(der(p)*((b - a*c)*(h[i + 1] - hv)/((c + h[i
-           + 1])*(c + hv)) + a*log((c + h[i + 1])/(c + hv))) + ((d*f[i] - d*c*
-          ee[i])*(h[i + 1] - hv)/((c + h[i + 1])*(c + hv)) + d*ee[i]*log((c + h[
-          i + 1])/(c + hv))));
-
-        ee[i] = (der(h[i + 1]) - (der(h[i + 1])*rs[i] + der(h[i])*(1 - rs[i])))
-          /(h[i + 1] - hv);
-        f[i] = ((der(h[i + 1])*rs[i] + der(h[i])*(1 - rs[i]))*h[i + 1] - der(h[
-          i + 1])*hv)/(h[i + 1] - hv);
-
-      elseif noEvent((h[i] >= hl) and (h[i] <= hv) and (h[i + 1] >= hl) and (h[
-          i + 1] <= hv)) then
-        //two phase
-
-        rs[i] = 0;
-        rhos[i] = 0;
-        gamma_rho[i] = 0;
-
-        gamma_w[i] = 0;
-
-        ws[i] = 0;
-
-        dMmono[i] = 0;
-
-        dMbif[i] = A*l/(h[i + 1] - h[i])*(der(p)*((b - a*c)*(h[i + 1] - h[i])/(
-          (c + h[i + 1])*(c + h[i])) + a*log((c + h[i + 1])/(c + h[i]))) + ((d*
-          f[i] - d*c*ee[i])*(h[i + 1] - h[i])/((c + h[i + 1])*(c + h[i])) + d*
-          ee[i]*log((c + h[i + 1])/(c + h[i]))));
-
-        ee[i] = (der(h[i + 1]) - der(h[i]))/(h[i + 1] - h[i]);
-        f[i] = (der(h[i])*h[i + 1] - der(h[i + 1])*h[i])/(h[i + 1] - h[i]);
-
-      elseif noEvent(((h[i] < hl) and (h[i + 1] < hl)) or ((h[i] > hv) and (h[i
-           + 1] > hv))) then
-        //single-phase
-
-        rs[i] = 0;
-        rhos[i] = 0;
-        gamma_rho[i] = 0;
-
-        gamma_w[i] = 0;
-        ws[i] = 0;
-
-        dMmono[i] = A*l*(der(p)*1/2*(drdp[i + 1] + drdp[i]) + 1/6*(der(h[i])*(2
-          *drdh[i] + drdh[i + 1]) + der(h[i + 1])*(drdh[i] + 2*drdh[i + 1])));
-        dMbif[i] = 0;
-
-        ee[i] = 0;
-        f[i] = 0;
-      else
-        //double transition (not supported!)
-        assert(0 > 1,
-          "Error: two phase transitions between two adiacent nodes. Try increasing the number of nodes");
-        rs[i] = 0;
-        rhos[i] = 0;
-        gamma_rho[i] = 0;
-
-        gamma_w[i] = 0;
-        ws[i] = 0;
-
-        dMmono[i] = 0;
-        dMbif[i] = 0;
-
-        ee[i] = 0;
-        f[i] = 0;
-      end if;
-    end for;
-
-    // Energy equation FEM matrices
-
-    Y[1, 1] = rho[1]*(3 - 2*alpha_sgn) + rho[2]*(1 - alpha_sgn);
-    Y[1, 2] = rho[1]*(1 - alpha_sgn) + rho[2]*(1 - 2*alpha_sgn);
-    Y[N, N] = rho[N - 1]*(alpha_sgn + 1) + rho[N]*(3 + 2*alpha_sgn);
-    Y[N, N - 1] = rho[N - 1]*(1 + 2*alpha_sgn) + rho[N]*(1 + alpha_sgn);
-    if N > 2 then
-      for i in 2:N - 1 loop
-        Y[i, i - 1] = rho[i - 1]*(1 + 2*alpha_sgn) + rho[i]*(1 + alpha_sgn);
-        Y[i, i] = rho[i - 1]*(1 + alpha_sgn) + rho[i]*6 + rho[i + 1]*(1 -
-          alpha_sgn);
-        Y[i, i + 1] = rho[i]*(1 - alpha_sgn) + rho[i + 1]*(1 - 2*alpha_sgn);
-        Y[1, i + 1] = 0;
-        Y[N, i - 1] = 0;
-        for j in 1:(i - 2) loop
-          Y[i, j] = 0;
-        end for;
-        for j in (i + 2):N loop
-          Y[i, j] = 0;
-        end for;
-      end for;
-    end if;
-
-    for i in 1:N loop
-      for j in 1:N loop
-        YY[i, j] = if (i <> j) then 0 else sum(Y[:, j]);
-      end for;
-    end for;
-
-    M[1, 1] = l/3 - l*alpha_sgn/4;
-    M[N, N] = l/3 + l*alpha_sgn/4;
-    M[1, 2] = l/6 - l*alpha_sgn/4;
-    M[N, (N - 1)] = l/6 + l*alpha_sgn/4;
-    if N > 2 then
-      for i in 2:N - 1 loop
-        M[i, i - 1] = l/6 + l*alpha_sgn/4;
-        M[i, i] = 2*l/3;
-        M[i, i + 1] = l/6 - l*alpha_sgn/4;
-        M[1, i + 1] = 0;
-        M[N, i - 1] = 0;
-        for j in 1:(i - 2) loop
-          M[i, j] = 0;
-        end for;
-        for j in (i + 2):N loop
-          M[i, j] = 0;
-        end for;
-      end for;
-    end if;
-
-    B[1, 1] = (-1/3 + alpha_sgn/4)*w[1] + (-1/6 + alpha_sgn/4)*w[2];
-    B[1, 2] = (1/3 - alpha_sgn/4)*w[1] + (1/6 - alpha_sgn/4)*w[2];
-    B[N, N] = (1/6 + alpha_sgn/4)*w[N - 1] + (1/3 + alpha_sgn/4)*w[N];
-    B[N, N - 1] = (-1/6 - alpha_sgn/4)*w[N - 1] + (-1/3 - alpha_sgn/4)*w[N];
-    if N > 2 then
-      for i in 2:N - 1 loop
-        B[i, i - 1] = (-1/6 - alpha_sgn/4)*w[i - 1] + (-1/3 - alpha_sgn/4)*w[i];
-        B[i, i] = (1/6 + alpha_sgn/4)*w[i - 1] + (alpha_sgn/2)*w[i] + (-1/6 +
-          alpha_sgn/4)*w[i + 1];
-        B[i, i + 1] = (1/3 - alpha_sgn/4)*w[i] + (1/6 - alpha_sgn/4)*w[i + 1];
-        B[1, i + 1] = 0;
-        B[N, i - 1] = 0;
-        for j in 1:(i - 2) loop
-          B[i, j] = 0;
-        end for;
-        for j in (i + 2):N loop
-          B[i, j] = 0;
-        end for;
-      end for;
-    end if;
-
-    G[1] = l/2*(1 - alpha_sgn);
-    G[N] = l/2*(1 + alpha_sgn);
-    if N > 2 then
-      for i in 2:N - 1 loop
-        G[i] = l;
-      end for;
-    end if;
-
-    //boundary conditions
-
-    C[1, 1] = if noEvent(infl.m_flow >= 0) then (1 - alpha_sgn/2)*w[1] else 0;
-    C[N, N] = if noEvent(outfl.m_flow >= 0) then -(1 + alpha_sgn/2)*w[N] else 0;
-    C[N, 1] = 0;
-    C[1, N] = 0;
-    if (N > 2) then
-      for i in 2:(N - 1) loop
-        C[1, i] = 0;
-        C[N, i] = 0;
-        for j in 1:N loop
-          C[i, j] = 0;
-        end for;
-      end for;
-    end if;
-
-    K[1, 1] = if noEvent(infl.m_flow >= 0) then (1 - alpha_sgn/2)*inStream(infl.h_outflow)
-       else 0;
-    K[N, N] = if noEvent(outfl.m_flow >= 0) then -(1 + alpha_sgn/2)*inStream(
-      outfl.h_outflow) else 0;
-    K[N, 1] = 0;
-    K[1, N] = 0;
-    if (N > 2) then
-      for i in 2:(N - 1) loop
-        K[1, i] = 0;
-        K[N, i] = 0;
-        for j in 1:N loop
-          K[i, j] = 0;
-        end for;
-      end for;
-    end if;
-
-    // Momentum and Mass balance equation matrices
-    D[1] = l/2;
-    D[N] = l/2;
-    for i in 2:N - 1 loop
-      D[i] = l;
-    end for;
-    if HydraulicCapacitance == HCtypes.Middle then
-      D1 = l*(if N == 2 then {3/8,1/8} else if evenN then cat(
-          1,
-          {1/2},
-          ones(max(0, div(N, 2) - 2)),
-          {7/8,1/8},
-          zeros(div(N, 2) - 1)) else cat(
-          1,
-          {1/2},
-          ones(div(N, 2) - 1),
-          {1/2},
-          zeros(div(N, 2))));
-      D2 = l*(if N == 2 then {1/8,3/8} else if evenN then cat(
-          1,
-          zeros(div(N, 2) - 1),
-          {1/8,7/8},
-          ones(max(div(N, 2) - 2, 0)),
-          {1/2}) else cat(
-          1,
-          zeros(div(N, 2)),
-          {1/2},
-          ones(div(N, 2) - 1),
-          {1/2}));
-    elseif HydraulicCapacitance == HCtypes.Upstream then
-      D1 = zeros(N);
-      D2 = D;
-    elseif HydraulicCapacitance == HCtypes.Downstream then
-      D1 = D;
-      D2 = zeros(N);
-    else
-      assert(false, "Unsupported HydraulicCapacitance option");
-    end if;
-
-    by[1, 1] = 0;
-    by[2, 1] = 0;
-    by[3, 1] = l/12*rs[1]*(6 - 8*rs[1] + 3*rs[1]^2 + alpha_sgn*(2*rs[1] - 3));
-    by[4, 1] = -l/12*(1 - rs[1])^2*(2*alpha_sgn + 3*rs[1] - 3);
-    by[5, 1] = -l/12*rs[1]^2*(2*alpha_sgn + 3*rs[1] - 4);
-    by[6, 1] = -l/12*(1 - rs[1])*(3*rs[1]^2 - 2*rs[1] + 2*alpha_sgn*rs[1] +
-      alpha_sgn - 1);
-    by[7, 1] = 0;
-    by[8, 1] = 0;
-    by[1, N] = l/12*rs[N - 1]^2*(2*alpha_sgn + 3*rs[N - 1]);
-    by[2, N] = l/12*(1 - rs[N - 1])*(1 + alpha_sgn + 2*rs[N - 1] + 2*alpha_sgn*
-      rs[N - 1] + 3*rs[N - 1]^2);
-    by[3, N] = 0;
-    by[4, N] = 0;
-    by[5, N] = 0;
-    by[6, N] = 0;
-    by[7, N] = l/12*rs[N - 1]*(alpha_sgn*(3 - 2*rs[N - 1]) + rs[N - 1]*(4 - 3*
-      rs[N - 1]));
-    by[8, N] = l/12*(1 - rs[N - 1])^2*(2*alpha_sgn + 3*rs[N - 1] + 1);
-    if N > 2 then
-      for i in 2:N - 1 loop
-        by[1, i] = l/12*rs[i - 1]^2*(2*alpha_sgn + 3*rs[i - 1]);
-        by[2, i] = l/12*(1 - rs[i - 1])*(1 + alpha_sgn + 2*rs[i - 1] + 2*
-          alpha_sgn*rs[i - 1] + 3*rs[i - 1]^2);
-        by[3, i] = l/12*rs[i]*(6 - 8*rs[i] + 3*rs[i]^2 + alpha_sgn*(2*rs[i] - 3));
-        by[4, i] = -l/12*(1 - rs[i])^2*(2*alpha_sgn + 3*rs[i] - 3);
-        by[5, i] = -l/12*rs[i]^2*(2*alpha_sgn + 3*rs[i] - 4);
-        by[6, i] = -l/12*(1 - rs[i])*(3*rs[i]^2 - 2*rs[i] + 2*alpha_sgn*rs[i]
-           + alpha_sgn - 1);
-        by[7, i] = l/12*rs[i - 1]*(alpha_sgn*(3 - 2*rs[i - 1]) + rs[i - 1]*(4
-           - 3*rs[i - 1]));
-        by[8, i] = l/12*(1 - rs[i - 1])^2*(2*alpha_sgn + 3*rs[i - 1] + 1);
-      end for;
-    end if;
-
-    //additional 2 phases Y-matrix
-    Y2ph[1, 1] = (gamma_rho[1]*by[3, 1] + gamma_rho[1]*by[4, 1]);
-    Y2ph[1, 2] = (gamma_rho[1]*by[5, 1] + gamma_rho[1]*by[6, 1]);
-    Y2ph[N, N] = (gamma_rho[N - 1]*by[1, N] + gamma_rho[N - 1]*by[2, N]);
-    Y2ph[N, N - 1] = (gamma_rho[N - 1]*by[7, N] + gamma_rho[N - 1]*by[8, N]);
-    if N > 2 then
-      for i in 2:N - 1 loop
-        Y2ph[i, i - 1] = (gamma_rho[i - 1]*by[7, i] + gamma_rho[i - 1]*by[8, i]);
-        Y2ph[i, i] = (gamma_rho[i - 1]*by[1, i] + gamma_rho[i - 1]*by[2, i]) +
-          (gamma_rho[i]*by[3, i] + gamma_rho[i]*by[4, i]);
-        Y2ph[i, i + 1] = (gamma_rho[i]*by[5, i] + gamma_rho[i]*by[6, i]);
-        Y2ph[1, i + 1] = 0;
-        Y2ph[N, i - 1] = 0;
-        for j in 1:(i - 2) loop
-          Y2ph[i, j] = 0;
-        end for;
-        for j in (i + 2):N loop
-          Y2ph[i, j] = 0;
-        end for;
-      end for;
-    end if;
-
-    //computation of beta functions for additional matrices
-    beta[1, 1] = 0;
-    beta[2, 1] = 0;
-    beta[3, 1] = 1/12*rs[1]*(3*alpha_sgn + 4*rs[1] - 6);
-    beta[4, 1] = 1/12*(1 - rs[1])*(3*alpha_sgn + 4*rs[1] - 4);
-    beta[5, 1] = -beta[3, 1];
-    beta[6, 1] = -beta[4, 1];
-    beta[7, 1] = 0;
-    beta[8, 1] = 0;
-    beta[1, N] = 1/12*rs[N - 1]*(3*alpha_sgn + 4*rs[N - 1]);
-    beta[2, N] = 1/12*(1 - rs[N - 1])*(3*alpha_sgn + 4*rs[N - 1] + 2);
-    beta[3, N] = 0;
-    beta[4, N] = 0;
-    beta[5, N] = 0;
-    beta[6, N] = 0;
-    beta[7, N] = -beta[1, N];
-    beta[8, N] = -beta[2, N];
-    if N > 2 then
-      for i in 2:N - 1 loop
-        beta[1, i] = 1/12*rs[i - 1]*(3*alpha_sgn + 4*rs[i - 1]);
-        beta[2, i] = 1/12*(1 - rs[i - 1])*(3*alpha_sgn + 4*rs[i - 1] + 2);
-        beta[3, i] = 1/12*rs[i]*(3*alpha_sgn + 4*rs[i] - 6);
-        beta[4, i] = 1/12*(1 - rs[i])*(3*alpha_sgn + 4*rs[i] - 4);
-        beta[5, i] = -beta[3, i];
-        beta[6, i] = -beta[4, i];
-        beta[7, i] = -beta[1, i];
-        beta[8, i] = -beta[2, i];
-      end for;
-    end if;
-
-    //additional 2 phases B-matrix
-    B2ph[1, 1] = (gamma_w[1]*beta[3, 1] + gamma_w[1]*beta[4, 1]);
-    B2ph[1, 2] = (gamma_w[1]*beta[5, 1] + gamma_w[1]*beta[6, 1]);
-    B2ph[N, N] = (gamma_w[N - 1]*beta[1, N] + gamma_w[N - 1]*beta[2, N]);
-    B2ph[N, N - 1] = (gamma_w[N - 1]*beta[7, N] + gamma_w[N - 1]*beta[8, N]);
-    if N > 2 then
-      for i in 2:N - 1 loop
-        B2ph[i, i - 1] = (gamma_w[i - 1]*beta[7, i] + gamma_w[i - 1]*beta[8, i]);
-        B2ph[i, i] = (gamma_w[i - 1]*beta[1, i] + gamma_w[i - 1]*beta[2, i]) +
-          (gamma_w[i]*beta[3, i] + gamma_w[i]*beta[4, i]);
-        B2ph[i, i + 1] = (gamma_w[i]*beta[5, i] + gamma_w[i]*beta[6, i]);
-        B2ph[1, i + 1] = 0;
-        B2ph[N, i - 1] = 0;
-        for j in 1:(i - 2) loop
-          B2ph[i, j] = 0;
-        end for;
-        for j in (i + 2):N loop
-          B2ph[i, j] = 0;
-        end for;
-      end for;
-    end if;
-    Q = Nt*omega*D*phi "Total heat flow through lateral boundary";
-    Tr = noEvent(sum(rho)*A*l/max(infl.m_flow/Nt, Modelica.Constants.eps));
-  initial equation
-    if initOpt == Choices.Init.Options.noInit then
-      // do nothing
-    elseif initOpt == Choices.Init.Options.steadyState then
-      der(h) = zeros(N);
-      if (not Medium.singleState) then
-        der(p) = 0;
-      end if;
-    elseif initOpt == Choices.Init.Options.steadyStateNoP then
-      der(h) = zeros(N);
-    else
-      assert(false, "Unsupported initialisation option");
-    end if;
-    annotation (
-      Diagram(graphics),
-      Icon(graphics={Text(extent={{-100,-52},{100,-82}}, textString="%name")}),
-      Documentation(info="<HTML>
+</html>"));
+  end Flow1Dfem;
+
+  model Flow1Dfem2ph "1-dimensional fluid flow model for water/steam (finite elements)"
+    extends Modelica.Icons.ObsoleteModel;
+    import Modelica.Math.*;
+    import ThermoPower.Choices.Flow1D.FFtypes;
+    import ThermoPower.Choices.Flow1D.HCtypes;
+    extends BaseClasses.Flow1DBase(redeclare replaceable package Medium = StandardWater constrainedby Modelica.Media.Interfaces.PartialTwoPhaseMedium "Medium model");
+    replaceable ThermoPower.Thermal.DHT wall(N = N) annotation(
+      Dialog(enable = false),
+      Placement(transformation(extent = {{-40, 40}, {40, 60}}, rotation = 0)));
+    parameter Real alpha(min = 0, max = 2) = 1 "Numerical stabilization coefficient";
+    parameter Real ML(min = 0, max = 1) = 0.2 "Mass Lumping Coefficient";
+    constant Real g = Modelica.Constants.g_n;
+    final parameter Boolean evenN = div(N, 2) * 2 == N "The number of nodes is even";
+    constant SI.Pressure pzero = 10 "Small deltap for calculations";
+    constant SI.Pressure pc = Medium.fluidConstants[1].criticalPressure;
+    constant SI.SpecificEnthalpy hzero = 1e-3;
+    Medium.ThermodynamicState fluidState[N] "Thermodynamic state of the fluid at the nodes";
+    Medium.SaturationProperties sat "Properties of saturated fluid";
+    Medium.ThermodynamicState dew "Thermodynamic state at dewpoint";
+    Medium.ThermodynamicState bubble "Thermodynamic state at bubblepoint";
+    SI.Length omega_hyd "Hydraulic perimeter (single tube)";
+    Real dwdt "Dynamic momentum term";
+    Medium.AbsolutePressure p "Fluid pressure";
+    SI.Pressure Dpfric "Pressure drop due to friction";
+    SI.Pressure Dpfric1 "Pressure drop due to friction (from inlet to capacitance)";
+    SI.Pressure Dpfric2 "Pressure drop due to friction (from capacitance to outlet)";
+    SI.Pressure Dpstat "Pressure drop due to static head";
+    SI.MassFlowRate w[N](start = wnom * ones(N)) "Mass flowrate (single tube)";
+    SI.Velocity u[N] "Fluid velocity";
+    SI.HeatFlux phi[N] "External heat flux";
+    Medium.Temperature T[N] "Fluid temperature";
+    Medium.SpecificEnthalpy h[N](start = hstart) "Fluid specific enthalpy";
+    Medium.Density rho[N] "Fluid density";
+    SI.SpecificVolume v[N] "Fluid specific volume";
+    Medium.Temperature Ts "Saturation temperature";
+    Medium.SpecificEnthalpy hl(start = Medium.bubbleEnthalpy(Medium.setSat_p(pstart))) "Saturated liquid specific enthalpy";
+    Medium.SpecificEnthalpy hv(start = Medium.dewEnthalpy(Medium.setSat_p(pstart))) "Saturated vapour specific enthalpy";
+    Real x[N] "Steam quality";
+    Units.LiquidDensity rhol "Saturated liquid density";
+    Units.GasDensity rhov "Saturated vapour density";
+    Real Kf[N] "Friction coefficient";
+    Real Cf[N] "Fanning friction factor";
+    Real Phi[N] "Two-phase friction multiplier";
+  protected
+    SI.DerDensityByEnthalpy drdh[N] "Derivative of density by enthalpy";
+    SI.DerDensityByPressure drdp[N] "Derivative of density by pressure";
+    SI.DerDensityByPressure drl_dp "Derivative of liquid density by pressure just before saturation";
+    SI.DerDensityByPressure drv_dp "Derivative of vapour density by pressure just before saturation";
+    SI.DerDensityByEnthalpy drl_dh "Derivative of liquid density by enthalpy just before saturation";
+    SI.DerDensityByEnthalpy drv_dh "Derivative of vapour density by enthalpy just before saturation";
+    Real dhl "Derivative of saturated liquid enthalpy by pressure";
+    Real dhv "Derivative of saturated vapour enthalpy by pressure";
+    Real drl "Derivative of saturatd liquid density by pressure";
+    Real drv "Derivative of saturated vapour density by pressure";
+    SI.Density rhos[N - 1];
+    SI.MassFlowRate ws[N - 1];
+    Real rs[N - 1];
+    Real Y[N, N];
+    Real YY[N, N];
+    Real Y2ph[N, N];
+    Real M[N, N];
+    Real D[N];
+    Real D1[N];
+    Real D2[N];
+    Real G[N];
+    Real B[N, N];
+    Real B2ph[N, N];
+    Real C[N, N];
+    Real K[N, N];
+    Real by[8, N];
+    Real beta[8, N];
+    //coefficients matrix for 2-phases augmented FEM matrices
+    Real alpha_sgn;
+    Real gamma_rho[N - 1];
+    Real gamma_w[N - 1];
+    //coefficients for gamma functions
+    Real a;
+    Real b;
+    Real betap;
+    Real c;
+    Real d;
+    Real ee[N - 1];
+    Real f[N - 1];
+    Real dMbif[N - 1];
+    Real dMmono[N - 1];
+  equation
+//All equations are referred to a single tube
+// Selection of representative pressure variable
+    if HydraulicCapacitance == HCtypes.Middle then
+      p = infl.p - Dpfric1 - Dpstat / 2;
+    elseif HydraulicCapacitance == HCtypes.Upstream then
+      p = infl.p;
+    elseif HydraulicCapacitance == HCtypes.Downstream then
+      p = outfl.p;
+    else
+      assert(false, "Unsupported HydraulicCapacitance option");
+    end if;
+//Friction factor calculation
+    omega_hyd = 4 * A / Dhyd;
+    for i in 1:N loop
+      if FFtype == FFtypes.NoFriction then
+        Cf[i] = 0;
+      elseif FFtype == FFtypes.Cfnom then
+        Cf[i] = Cfnom * Kfc;
+      else
+        assert(true, "Unsupported friction factor selection");
+      end if;
+      Kf[i] = Cf[i] * omega_hyd * L / (2 * A ^ 3) "Relationship between friction coefficient and Fanning friction factor";
+    end for;
+//Dynamic Momentum [not] accounted for
+    if DynamicMomentum then
+      if HydraulicCapacitance == HCtypes.Upstream then
+        dwdt = -der(outfl.m_flow) / Nt;
+      else
+        dwdt = der(infl.m_flow) / Nt;
+      end if;
+    else
+      dwdt = 0;
+    end if;
+//Momentum balance equation
+    L / A * dwdt + outfl.p - infl.p + Dpstat + Dpfric = 0;
+    w[1] = infl.m_flow / Nt;
+    w[N] = -outfl.m_flow / Nt;
+    Dpfric = Dpfric1 + Dpfric2 "Total pressure drop due to friction";
+    if FFtype == FFtypes.NoFriction then
+      Dpfric1 = 0;
+      Dpfric2 = 0;
+    else
+      Dpfric1 = homotopy(sum(Kf[i] / L * squareReg(w[i], wnom / Nt * wnf) * D1[i] / rho[i] * Phi[i] for i in 1:N), dpnom / 2 / (wnom / Nt) * w[1]) "Pressure drop from inlet to capacitance";
+      Dpfric2 = homotopy(sum(Kf[i] / L * squareReg(w[i], wnom / Nt * wnf) * D2[i] / rho[i] * Phi[i] for i in 1:N), dpnom / 2 / (wnom / Nt) * w[N]) "Pressure drop from capacitance to outlet";
+    end if "Pressure drop due to friction";
+    for i in 1:N loop
+      if FFtype == FFtypes.NoFriction or noEvent(h[i] <= hl or h[i] >= hv) then
+        Phi[i] = 1;
+      else
+// Chisholm-Laird formulation of Martinelli-Lockhart correlation for turbulent-turbulent flow
+// Phi_l^2 = 1 + 20/Xtt + 1/Xtt^2
+// same fixed Fanning friction factor Cfnom is assumed for liquid and vapour, so Xtt = (rhov/rhol)^0.5 * (1-x)/x
+        Phi[i] = rho[i] / rhol * ((1 - x[i]) ^ 2 + 20 * sqrt(rhol / rhov) * x[i] * (1 - x[i]) + rhol / rhov * x[i] ^ 2);
+      end if;
+    end for;
+    Dpstat = if abs(dzdx) < 1e-6 then 0 else g * dzdx * rho * D "Pressure drop due to static head";
+//Energy balance equations
+    l / 12 * ((1 - ML) * Y + ML * YY + 0 * Y2ph) * der(h) + 1 / A * (B + 0 * B2ph) * h + C * h / A = der(p) * G + M * (omega / A) * phi + K * w / A;
+//  (Ts,rhol,rhov,hl,hv,drl_dp,drv_dp,drl_dh,drv_dh,dhl,dhv,drl,drv) =
+//  propsat_p_2der(noEvent(min(p, pc - pzero)));
+    sat.psat = p;
+    sat.Tsat = Medium.saturationTemperature(p);
+    Ts = sat.Tsat;
+    bubble = Medium.setBubbleState(sat);
+    dew = Medium.setDewState(sat);
+    rhol = Medium.bubbleDensity(sat);
+    rhov = Medium.dewDensity(sat);
+    hl = Medium.bubbleEnthalpy(sat);
+    hv = Medium.dewEnthalpy(sat);
+    drl = Medium.dBubbleDensity_dPressure(sat);
+    drv = Medium.dDewDensity_dPressure(sat);
+    dhl = Medium.dBubbleEnthalpy_dPressure(sat);
+    dhv = Medium.dDewEnthalpy_dPressure(sat);
+    drl_dp = Medium.density_derp_h(bubble);
+    drv_dp = Medium.density_derp_h(dew);
+    drl_dh = Medium.density_derh_p(bubble);
+    drv_dh = Medium.density_derh_p(dew);
+    a = ((hv - hl) * (rhol ^ 2 * drv + rhov ^ 2 * drl) + rhov * rhol * (rhol - rhov) * (dhv - dhl)) / (rhol - rhov) ^ 2;
+    betap = ((rhol - rhov) * (rhov * dhv - rhol * dhl) + (hv - hl) * (rhol * drv - rhov * drl)) / (rhol - rhov) ^ 2;
+    b = a * c + d * betap;
+    c = (rhov * hv - rhol * hl) / (rhol - rhov);
+    d = -rhol * rhov * (hv - hl) / (rhol - rhov);
+//Computation of fluid properties
+    for j in 1:N loop
+      fluidState[j] = Medium.setState_phX(p, h[j]);
+      T[j] = Medium.temperature(fluidState[j]);
+      rho[j] = Medium.density(fluidState[j]);
+      drdp[j] = if Medium.singleState then 0 else Medium.density_derp_h(fluidState[j]);
+      drdh[j] = Medium.density_derh_p(fluidState[j]);
+      v[j] = 1 / rho[j];
+      u[j] = w[j] / (rho[j] * A);
+      x[j] = noEvent(min(max((h[j] - hl) / (hv - hl), 0), 1));
+    end for;
+//Wall energy flux and  temperature
+    T = wall.T;
+    phi = wall.phi;
+//Boundary Values
+    h[1] = infl.h_outflow;
+    h[N] = outfl.h_outflow;
+    alpha_sgn = alpha * sign(infl.m_flow - outfl.m_flow);
+//phase change determination
+    for i in 1:N - 1 loop
+      w[i] - w[i + 1] = dMmono[i] + dMbif[i];
+      if noEvent(abs(h[i + 1] - h[i]) < hzero) then
+        rs[i] = 0;
+        rhos[i] = 0;
+        gamma_rho[i] = 0;
+        gamma_w[i] = 0;
+        ws[i] = 0;
+        dMmono[i] = A * l * (der(p) * 1 / 2 * (drdp[i + 1] + drdp[i]) + 1 / 6 * (der(h[i]) * (2 * drdh[i] + drdh[i + 1]) + der(h[i + 1]) * (drdh[i] + 2 * drdh[i + 1])));
+        dMbif[i] = 0;
+        ee[i] = 0;
+        f[i] = 0;
+      elseif noEvent(h[i] < hl and h[i + 1] >= hl and h[i + 1] <= hv) then
+//liquid - two phase
+        rs[i] = (hl - h[i]) / (h[i + 1] - h[i]);
+        rhos[i] = rhol;
+        gamma_rho[i] = rhos[i] - rho[i] * (1 - rs[i]) - rho[i + 1] * rs[i];
+        gamma_w[i] = ws[i] - w[i] * (1 - rs[i]) - w[i + 1] * rs[i];
+        w[i] - ws[i] = dMmono[i];
+        dMmono[i] = A * rs[i] * l * (der(p) * 1 / 2 * (drl_dp + drdp[i]) + 1 / 6 * (der(h[i]) * (2 * drdh[i] + drl_dh) + (der(h[i]) * (1 - rs[i]) + der(h[i + 1]) * rs[i]) * (drdh[i] + 2 * drl_dh)));
+        dMbif[i] = A * (1 - rs[i]) * l / (h[i + 1] - hl) * (der(p) * ((b - a * c) * (h[i + 1] - hl) / ((c + h[i + 1]) * (c + hl)) + a * log((c + h[i + 1]) / (c + hl))) + (d * f[i] - d * c * ee[i]) * (h[i + 1] - hl) / ((c + h[i + 1]) * (c + hl)) + d * ee[i] * log((c + h[i + 1]) / (c + hl)));
+        ee[i] = (der(h[i + 1]) - (der(h[i + 1]) * rs[i] + der(h[i]) * (1 - rs[i]))) / (h[i + 1] - hl);
+        f[i] = ((der(h[i + 1]) * rs[i] + der(h[i]) * (1 - rs[i])) * h[i + 1] - der(h[i + 1]) * hl) / (h[i + 1] - hl);
+      elseif noEvent(h[i] >= hl and h[i] <= hv and h[i + 1] < hl) then
+//two phase-liquid
+        rs[i] = (hl - h[i]) / (h[i + 1] - h[i]);
+        rhos[i] = rhol;
+        gamma_rho[i] = rhos[i] - rho[i] * (1 - rs[i]) - rho[i + 1] * rs[i];
+        gamma_w[i] = ws[i] - w[i] * (1 - rs[i]) - w[i + 1] * rs[i];
+        w[i] - ws[i] = dMbif[i];
+        dMmono[i] = A * (1 - rs[i]) * l * (der(p) * 1 / 2 * (drdp[i + 1] + drl_dp) + 1 / 6 * (der(h[i]) * (2 * drl_dh + drdh[i + 1]) + (der(h[i + 1]) * rs[i] + der(h[i]) * (1 - rs[i])) * (drl_dh + 2 * drdh[i + 1])));
+        dMbif[i] = A * rs[i] * l / (hl - h[i]) * (der(p) * ((b - a * c) * (hl - h[i]) / ((c + hl) * (c + h[i])) + a * log((c + hl) / (c + h[i]))) + (d * f[i] - d * c * ee[i]) * (hl - h[i]) / ((c + hl) * (c + h[i])) + d * ee[i] * log((c + hl) / (c + h[i])));
+        ee[i] = (der(h[i + 1]) * rs[i] + der(h[i]) * (1 - rs[i]) - der(h[i])) / (hl - h[i]);
+        f[i] = (der(h[i]) * hl - (der(h[i + 1]) * rs[i] + der(h[i]) * (1 - rs[i])) * h[i]) / (hl - h[i]);
+      elseif noEvent(h[i] >= hl and h[i] <= hv and h[i + 1] > hv) then
+//two phase - vapour
+        rs[i] = (hv - h[i]) / (h[i + 1] - h[i]);
+        rhos[i] = rhov;
+        gamma_rho[i] = rhos[i] - rho[i] * (1 - rs[i]) - rho[i + 1] * rs[i];
+        gamma_w[i] = ws[i] - w[i] * (1 - rs[i]) - w[i + 1] * rs[i];
+        w[i] - ws[i] = dMbif[i];
+        dMmono[i] = A * (1 - rs[i]) * l * (der(p) * 1 / 2 * (drdp[i + 1] + drv_dp) + 1 / 6 * (der(h[i]) * (2 * drv_dh + drdh[i + 1]) + (der(h[i + 1]) * rs[i] + der(h[i]) * (1 - rs[i])) * (drv_dh + 2 * drdh[i + 1])));
+        dMbif[i] = A * rs[i] * l / (hv - h[i]) * (der(p) * ((b - a * c) * (hv - h[i]) / ((c + hv) * (c + h[i])) + a * log((c + hv) / (c + h[i]))) + (d * f[i] - d * c * ee[i]) * (hv - h[i]) / ((c + hv) * (c + h[i])) + d * ee[i] * log((c + hv) / (c + h[i])));
+        ee[i] = (der(h[i + 1]) * rs[i] + der(h[i]) * (1 - rs[i]) - der(h[i])) / (hv - h[i]);
+        f[i] = (der(h[i]) * hv - (der(h[i + 1]) * rs[i] + der(h[i]) * (1 - rs[i])) * h[i]) / (hv - h[i]);
+      elseif noEvent(h[i] > hv and h[i + 1] >= hl and h[i + 1] <= hv) then
+// vapour - two phase
+        rs[i] = (hv - h[i]) / (h[i + 1] - h[i]);
+        rhos[i] = rhov;
+        gamma_rho[i] = rhos[i] - rho[i] * (1 - rs[i]) - rho[i + 1] * rs[i];
+        gamma_w[i] = ws[i] - w[i] * (1 - rs[i]) - w[i + 1] * rs[i];
+        w[i] - ws[i] = dMmono[i];
+        dMmono[i] = A * rs[i] * l * (der(p) * 1 / 2 * (drv_dp + drdp[i]) + 1 / 6 * (der(h[i]) * (2 * drdh[i] + drv_dh) + (der(h[i]) * (1 - rs[i]) + der(h[i + 1]) * rs[i]) * (drdh[i] + 2 * drv_dh)));
+        dMbif[i] = A * (1 - rs[i]) * (der(p) * ((b - a * c) * (h[i + 1] - hv) / ((c + h[i + 1]) * (c + hv)) + a * log((c + h[i + 1]) / (c + hv))) + (d * f[i] - d * c * ee[i]) * (h[i + 1] - hv) / ((c + h[i + 1]) * (c + hv)) + d * ee[i] * log((c + h[i + 1]) / (c + hv)));
+        ee[i] = (der(h[i + 1]) - (der(h[i + 1]) * rs[i] + der(h[i]) * (1 - rs[i]))) / (h[i + 1] - hv);
+        f[i] = ((der(h[i + 1]) * rs[i] + der(h[i]) * (1 - rs[i])) * h[i + 1] - der(h[i + 1]) * hv) / (h[i + 1] - hv);
+      elseif noEvent(h[i] >= hl and h[i] <= hv and h[i + 1] >= hl and h[i + 1] <= hv) then
+//two phase
+        rs[i] = 0;
+        rhos[i] = 0;
+        gamma_rho[i] = 0;
+        gamma_w[i] = 0;
+        ws[i] = 0;
+        dMmono[i] = 0;
+        dMbif[i] = A * l / (h[i + 1] - h[i]) * (der(p) * ((b - a * c) * (h[i + 1] - h[i]) / ((c + h[i + 1]) * (c + h[i])) + a * log((c + h[i + 1]) / (c + h[i]))) + (d * f[i] - d * c * ee[i]) * (h[i + 1] - h[i]) / ((c + h[i + 1]) * (c + h[i])) + d * ee[i] * log((c + h[i + 1]) / (c + h[i])));
+        ee[i] = (der(h[i + 1]) - der(h[i])) / (h[i + 1] - h[i]);
+        f[i] = (der(h[i]) * h[i + 1] - der(h[i + 1]) * h[i]) / (h[i + 1] - h[i]);
+      elseif noEvent(h[i] < hl and h[i + 1] < hl or h[i] > hv and h[i + 1] > hv) then
+//single-phase
+        rs[i] = 0;
+        rhos[i] = 0;
+        gamma_rho[i] = 0;
+        gamma_w[i] = 0;
+        ws[i] = 0;
+        dMmono[i] = A * l * (der(p) * 1 / 2 * (drdp[i + 1] + drdp[i]) + 1 / 6 * (der(h[i]) * (2 * drdh[i] + drdh[i + 1]) + der(h[i + 1]) * (drdh[i] + 2 * drdh[i + 1])));
+        dMbif[i] = 0;
+        ee[i] = 0;
+        f[i] = 0;
+      else
+//double transition (not supported!)
+        assert(0 > 1, "Error: two phase transitions between two adiacent nodes. Try increasing the number of nodes");
+        rs[i] = 0;
+        rhos[i] = 0;
+        gamma_rho[i] = 0;
+        gamma_w[i] = 0;
+        ws[i] = 0;
+        dMmono[i] = 0;
+        dMbif[i] = 0;
+        ee[i] = 0;
+        f[i] = 0;
+      end if;
+    end for;
+// Energy equation FEM matrices
+    Y[1, 1] = rho[1] * (3 - 2 * alpha_sgn) + rho[2] * (1 - alpha_sgn);
+    Y[1, 2] = rho[1] * (1 - alpha_sgn) + rho[2] * (1 - 2 * alpha_sgn);
+    Y[N, N] = rho[N - 1] * (alpha_sgn + 1) + rho[N] * (3 + 2 * alpha_sgn);
+    Y[N, N - 1] = rho[N - 1] * (1 + 2 * alpha_sgn) + rho[N] * (1 + alpha_sgn);
+    if N > 2 then
+      for i in 2:N - 1 loop
+        Y[i, i - 1] = rho[i - 1] * (1 + 2 * alpha_sgn) + rho[i] * (1 + alpha_sgn);
+        Y[i, i] = rho[i - 1] * (1 + alpha_sgn) + rho[i] * 6 + rho[i + 1] * (1 - alpha_sgn);
+        Y[i, i + 1] = rho[i] * (1 - alpha_sgn) + rho[i + 1] * (1 - 2 * alpha_sgn);
+        Y[1, i + 1] = 0;
+        Y[N, i - 1] = 0;
+        for j in 1:i - 2 loop
+          Y[i, j] = 0;
+        end for;
+        for j in i + 2:N loop
+          Y[i, j] = 0;
+        end for;
+      end for;
+    end if;
+    for i in 1:N loop
+      for j in 1:N loop
+        YY[i, j] = if i <> j then 0 else sum(Y[:, j]);
+      end for;
+    end for;
+    M[1, 1] = l / 3 - l * alpha_sgn / 4;
+    M[N, N] = l / 3 + l * alpha_sgn / 4;
+    M[1, 2] = l / 6 - l * alpha_sgn / 4;
+    M[N, N - 1] = l / 6 + l * alpha_sgn / 4;
+    if N > 2 then
+      for i in 2:N - 1 loop
+        M[i, i - 1] = l / 6 + l * alpha_sgn / 4;
+        M[i, i] = 2 * l / 3;
+        M[i, i + 1] = l / 6 - l * alpha_sgn / 4;
+        M[1, i + 1] = 0;
+        M[N, i - 1] = 0;
+        for j in 1:i - 2 loop
+          M[i, j] = 0;
+        end for;
+        for j in i + 2:N loop
+          M[i, j] = 0;
+        end for;
+      end for;
+    end if;
+    B[1, 1] = ((-1 / 3) + alpha_sgn / 4) * w[1] + ((-1 / 6) + alpha_sgn / 4) * w[2];
+    B[1, 2] = (1 / 3 - alpha_sgn / 4) * w[1] + (1 / 6 - alpha_sgn / 4) * w[2];
+    B[N, N] = (1 / 6 + alpha_sgn / 4) * w[N - 1] + (1 / 3 + alpha_sgn / 4) * w[N];
+    B[N, N - 1] = ((-1 / 6) - alpha_sgn / 4) * w[N - 1] + ((-1 / 3) - alpha_sgn / 4) * w[N];
+    if N > 2 then
+      for i in 2:N - 1 loop
+        B[i, i - 1] = ((-1 / 6) - alpha_sgn / 4) * w[i - 1] + ((-1 / 3) - alpha_sgn / 4) * w[i];
+        B[i, i] = (1 / 6 + alpha_sgn / 4) * w[i - 1] + alpha_sgn / 2 * w[i] + ((-1 / 6) + alpha_sgn / 4) * w[i + 1];
+        B[i, i + 1] = (1 / 3 - alpha_sgn / 4) * w[i] + (1 / 6 - alpha_sgn / 4) * w[i + 1];
+        B[1, i + 1] = 0;
+        B[N, i - 1] = 0;
+        for j in 1:i - 2 loop
+          B[i, j] = 0;
+        end for;
+        for j in i + 2:N loop
+          B[i, j] = 0;
+        end for;
+      end for;
+    end if;
+    G[1] = l / 2 * (1 - alpha_sgn);
+    G[N] = l / 2 * (1 + alpha_sgn);
+    if N > 2 then
+      for i in 2:N - 1 loop
+        G[i] = l;
+      end for;
+    end if;
+//boundary conditions
+    C[1, 1] = if noEvent(infl.m_flow >= 0) then (1 - alpha_sgn / 2) * w[1] else 0;
+    C[N, N] = if noEvent(outfl.m_flow >= 0) then -(1 + alpha_sgn / 2) * w[N] else 0;
+    C[N, 1] = 0;
+    C[1, N] = 0;
+    if N > 2 then
+      for i in 2:N - 1 loop
+        C[1, i] = 0;
+        C[N, i] = 0;
+        for j in 1:N loop
+          C[i, j] = 0;
+        end for;
+      end for;
+    end if;
+    K[1, 1] = if noEvent(infl.m_flow >= 0) then (1 - alpha_sgn / 2) * inStream(infl.h_outflow) else 0;
+    K[N, N] = if noEvent(outfl.m_flow >= 0) then -(1 + alpha_sgn / 2) * inStream(outfl.h_outflow) else 0;
+    K[N, 1] = 0;
+    K[1, N] = 0;
+    if N > 2 then
+      for i in 2:N - 1 loop
+        K[1, i] = 0;
+        K[N, i] = 0;
+        for j in 1:N loop
+          K[i, j] = 0;
+        end for;
+      end for;
+    end if;
+// Momentum and Mass balance equation matrices
+    D[1] = l / 2;
+    D[N] = l / 2;
+    for i in 2:N - 1 loop
+      D[i] = l;
+    end for;
+    if HydraulicCapacitance == HCtypes.Middle then
+      D1 = l * (if N == 2 then {3 / 8, 1 / 8} else if evenN then cat(1, {1 / 2}, ones(max(0, div(N, 2) - 2)), {7 / 8, 1 / 8}, zeros(div(N, 2) - 1)) else cat(1, {1 / 2}, ones(div(N, 2) - 1), {1 / 2}, zeros(div(N, 2))));
+      D2 = l * (if N == 2 then {1 / 8, 3 / 8} else if evenN then cat(1, zeros(div(N, 2) - 1), {1 / 8, 7 / 8}, ones(max(div(N, 2) - 2, 0)), {1 / 2}) else cat(1, zeros(div(N, 2)), {1 / 2}, ones(div(N, 2) - 1), {1 / 2}));
+    elseif HydraulicCapacitance == HCtypes.Upstream then
+      D1 = zeros(N);
+      D2 = D;
+    elseif HydraulicCapacitance == HCtypes.Downstream then
+      D1 = D;
+      D2 = zeros(N);
+    else
+      assert(false, "Unsupported HydraulicCapacitance option");
+    end if;
+    by[1, 1] = 0;
+    by[2, 1] = 0;
+    by[3, 1] = l / 12 * rs[1] * (6 - 8 * rs[1] + 3 * rs[1] ^ 2 + alpha_sgn * (2 * rs[1] - 3));
+    by[4, 1] = -l / 12 * (1 - rs[1]) ^ 2 * (2 * alpha_sgn + 3 * rs[1] - 3);
+    by[5, 1] = -l / 12 * rs[1] ^ 2 * (2 * alpha_sgn + 3 * rs[1] - 4);
+    by[6, 1] = -l / 12 * (1 - rs[1]) * (3 * rs[1] ^ 2 - 2 * rs[1] + 2 * alpha_sgn * rs[1] + alpha_sgn - 1);
+    by[7, 1] = 0;
+    by[8, 1] = 0;
+    by[1, N] = l / 12 * rs[N - 1] ^ 2 * (2 * alpha_sgn + 3 * rs[N - 1]);
+    by[2, N] = l / 12 * (1 - rs[N - 1]) * (1 + alpha_sgn + 2 * rs[N - 1] + 2 * alpha_sgn * rs[N - 1] + 3 * rs[N - 1] ^ 2);
+    by[3, N] = 0;
+    by[4, N] = 0;
+    by[5, N] = 0;
+    by[6, N] = 0;
+    by[7, N] = l / 12 * rs[N - 1] * (alpha_sgn * (3 - 2 * rs[N - 1]) + rs[N - 1] * (4 - 3 * rs[N - 1]));
+    by[8, N] = l / 12 * (1 - rs[N - 1]) ^ 2 * (2 * alpha_sgn + 3 * rs[N - 1] + 1);
+    if N > 2 then
+      for i in 2:N - 1 loop
+        by[1, i] = l / 12 * rs[i - 1] ^ 2 * (2 * alpha_sgn + 3 * rs[i - 1]);
+        by[2, i] = l / 12 * (1 - rs[i - 1]) * (1 + alpha_sgn + 2 * rs[i - 1] + 2 * alpha_sgn * rs[i - 1] + 3 * rs[i - 1] ^ 2);
+        by[3, i] = l / 12 * rs[i] * (6 - 8 * rs[i] + 3 * rs[i] ^ 2 + alpha_sgn * (2 * rs[i] - 3));
+        by[4, i] = -l / 12 * (1 - rs[i]) ^ 2 * (2 * alpha_sgn + 3 * rs[i] - 3);
+        by[5, i] = -l / 12 * rs[i] ^ 2 * (2 * alpha_sgn + 3 * rs[i] - 4);
+        by[6, i] = -l / 12 * (1 - rs[i]) * (3 * rs[i] ^ 2 - 2 * rs[i] + 2 * alpha_sgn * rs[i] + alpha_sgn - 1);
+        by[7, i] = l / 12 * rs[i - 1] * (alpha_sgn * (3 - 2 * rs[i - 1]) + rs[i - 1] * (4 - 3 * rs[i - 1]));
+        by[8, i] = l / 12 * (1 - rs[i - 1]) ^ 2 * (2 * alpha_sgn + 3 * rs[i - 1] + 1);
+      end for;
+    end if;
+//additional 2 phases Y-matrix
+    Y2ph[1, 1] = gamma_rho[1] * by[3, 1] + gamma_rho[1] * by[4, 1];
+    Y2ph[1, 2] = gamma_rho[1] * by[5, 1] + gamma_rho[1] * by[6, 1];
+    Y2ph[N, N] = gamma_rho[N - 1] * by[1, N] + gamma_rho[N - 1] * by[2, N];
+    Y2ph[N, N - 1] = gamma_rho[N - 1] * by[7, N] + gamma_rho[N - 1] * by[8, N];
+    if N > 2 then
+      for i in 2:N - 1 loop
+        Y2ph[i, i - 1] = gamma_rho[i - 1] * by[7, i] + gamma_rho[i - 1] * by[8, i];
+        Y2ph[i, i] = gamma_rho[i - 1] * by[1, i] + gamma_rho[i - 1] * by[2, i] + gamma_rho[i] * by[3, i] + gamma_rho[i] * by[4, i];
+        Y2ph[i, i + 1] = gamma_rho[i] * by[5, i] + gamma_rho[i] * by[6, i];
+        Y2ph[1, i + 1] = 0;
+        Y2ph[N, i - 1] = 0;
+        for j in 1:i - 2 loop
+          Y2ph[i, j] = 0;
+        end for;
+        for j in i + 2:N loop
+          Y2ph[i, j] = 0;
+        end for;
+      end for;
+    end if;
+//computation of beta functions for additional matrices
+    beta[1, 1] = 0;
+    beta[2, 1] = 0;
+    beta[3, 1] = 1 / 12 * rs[1] * (3 * alpha_sgn + 4 * rs[1] - 6);
+    beta[4, 1] = 1 / 12 * (1 - rs[1]) * (3 * alpha_sgn + 4 * rs[1] - 4);
+    beta[5, 1] = -beta[3, 1];
+    beta[6, 1] = -beta[4, 1];
+    beta[7, 1] = 0;
+    beta[8, 1] = 0;
+    beta[1, N] = 1 / 12 * rs[N - 1] * (3 * alpha_sgn + 4 * rs[N - 1]);
+    beta[2, N] = 1 / 12 * (1 - rs[N - 1]) * (3 * alpha_sgn + 4 * rs[N - 1] + 2);
+    beta[3, N] = 0;
+    beta[4, N] = 0;
+    beta[5, N] = 0;
+    beta[6, N] = 0;
+    beta[7, N] = -beta[1, N];
+    beta[8, N] = -beta[2, N];
+    if N > 2 then
+      for i in 2:N - 1 loop
+        beta[1, i] = 1 / 12 * rs[i - 1] * (3 * alpha_sgn + 4 * rs[i - 1]);
+        beta[2, i] = 1 / 12 * (1 - rs[i - 1]) * (3 * alpha_sgn + 4 * rs[i - 1] + 2);
+        beta[3, i] = 1 / 12 * rs[i] * (3 * alpha_sgn + 4 * rs[i] - 6);
+        beta[4, i] = 1 / 12 * (1 - rs[i]) * (3 * alpha_sgn + 4 * rs[i] - 4);
+        beta[5, i] = -beta[3, i];
+        beta[6, i] = -beta[4, i];
+        beta[7, i] = -beta[1, i];
+        beta[8, i] = -beta[2, i];
+      end for;
+    end if;
+//additional 2 phases B-matrix
+    B2ph[1, 1] = gamma_w[1] * beta[3, 1] + gamma_w[1] * beta[4, 1];
+    B2ph[1, 2] = gamma_w[1] * beta[5, 1] + gamma_w[1] * beta[6, 1];
+    B2ph[N, N] = gamma_w[N - 1] * beta[1, N] + gamma_w[N - 1] * beta[2, N];
+    B2ph[N, N - 1] = gamma_w[N - 1] * beta[7, N] + gamma_w[N - 1] * beta[8, N];
+    if N > 2 then
+      for i in 2:N - 1 loop
+        B2ph[i, i - 1] = gamma_w[i - 1] * beta[7, i] + gamma_w[i - 1] * beta[8, i];
+        B2ph[i, i] = gamma_w[i - 1] * beta[1, i] + gamma_w[i - 1] * beta[2, i] + gamma_w[i] * beta[3, i] + gamma_w[i] * beta[4, i];
+        B2ph[i, i + 1] = gamma_w[i] * beta[5, i] + gamma_w[i] * beta[6, i];
+        B2ph[1, i + 1] = 0;
+        B2ph[N, i - 1] = 0;
+        for j in 1:i - 2 loop
+          B2ph[i, j] = 0;
+        end for;
+        for j in i + 2:N loop
+          B2ph[i, j] = 0;
+        end for;
+      end for;
+    end if;
+    Q = Nt * omega * D * phi "Total heat flow through lateral boundary";
+    Tr = noEvent(sum(rho) * A * l / max(infl.m_flow / Nt, Modelica.Constants.eps));
+  initial equation
+    if initOpt == Choices.Init.Options.noInit then
+// do nothing
+    elseif initOpt == Choices.Init.Options.steadyState then
+      der(h) = zeros(N);
+      if not Medium.singleState then
+        der(p) = 0;
+      end if;
+    elseif initOpt == Choices.Init.Options.steadyStateNoP then
+      der(h) = zeros(N);
+    else
+      assert(false, "Unsupported initialisation option");
+    end if;
+    annotation(
+      Diagram(graphics),
+      Icon(graphics = {Text(extent = {{-100, -52}, {100, -82}}, textString = "%name")}),
+      Documentation(info = "<HTML>
 <p>This model describes the flow of water or steam in a rigid tube. The basic modelling assumptions are:
 <ul><li>The fluid state is either one-phase, or a two-phase mixture.
 <li>In case of two-phase flow, the same velocity is assumed for both phases (homogeneous model).
@@ -8646,7 +6573,7 @@
 <p>Start values for pressure and flowrate are specified by <tt>pstart</tt>, <tt>wstart</tt>. The start values for the node enthalpies are linearly distributed from <tt>hstartin</tt> at the inlet to <tt>hstartout</tt> at the outlet.
 <p>A bank of <tt>Nt</tt> identical tubes working in parallel can be modelled by setting <tt>Nt > 1</tt>. The geometric parameters always refer to a <i>single</i> tube.
 <p>This models makes the temperature and external heat flow distributions visible through the <tt>wall</tt> connector. If other variables (e.g. the heat transfer coefficient) are needed by external components to compute the actual heat flow, the <tt>wall</tt> connector can be replaced by an extended version of the <tt>DHT</tt> connector.
-</HTML>", revisions="<html>
+</HTML>", revisions = "<html>
 <ul>
 <li><i>30 May 2005</i>
     by <a href=\"mailto:francesco.casella@polimi.it\">Francesco Casella</a>:<br>
@@ -8672,61 +6599,49 @@
        First release.</li>
 </ul>
 </html>
-"));
-  end Flow1Dfem2ph;
-
-  model SourceP "Pressure source for water/steam flows"
-    extends Icons.Water.SourceP;
-    extends Modelica.Icons.ObsoleteModel;
-    replaceable package Medium = StandardWater constrainedby
-      Modelica.Media.Interfaces.PartialMedium "Medium model";
-    parameter SI.Pressure p0=1.01325e5 "Nominal pressure";
-    parameter Units.HydraulicResistance R=0 "Hydraulic resistance";
-    parameter Medium.SpecificEnthalpy h=1e5 "Nominal specific enthalpy";
-    parameter Boolean allowFlowReversal=system.allowFlowReversal
-      "= true to allow flow reversal, false restricts to design direction"
-      annotation(Evaluate=true);
-    outer ThermoPower.System system "System wide properties";
-    Medium.AbsolutePressure p "Actual pressure";
-    FlangeB flange(redeclare package Medium = Medium, m_flow(max=if
-            allowFlowReversal then +Modelica.Constants.inf else 0)) annotation (
-       Placement(transformation(extent={{80,-20},{120,20}}, rotation=0)));
-    Modelica.Blocks.Interfaces.RealInput in_p0 annotation (Placement(
-          transformation(
-          origin={-40,92},
-          extent={{-20,-20},{20,20}},
-          rotation=270)));
-    Modelica.Blocks.Interfaces.RealInput in_h annotation (Placement(
-          transformation(
-          origin={40,90},
-          extent={{-20,-20},{20,20}},
-          rotation=270)));
-  equation
-    if R == 0 then
-      flange.p = p;
-    else
-      flange.p = p + flange.m_flow*R;
-    end if;
-
-    p = in_p0;
-    if cardinality(in_p0) == 0 then
-      in_p0 = p0 "Pressure set by parameter";
-    end if;
-
-    flange.h_outflow = in_h;
-    if cardinality(in_h) == 0 then
-      in_h = h "Enthalpy set by parameter";
-    end if;
-    annotation (
-      Diagram(graphics),
-      Icon(graphics={Text(extent={{-106,90},{-52,50}}, textString="p0"), Text(
-              extent={{66,90},{98,52}}, textString="h")}),
-      Documentation(info="<HTML>
+      "));
+  end Flow1Dfem2ph;
+
+  model SourceP "Pressure source for water/steam flows"
+    extends Icons.Water.SourceP;
+    extends Modelica.Icons.ObsoleteModel;
+    replaceable package Medium = StandardWater constrainedby Modelica.Media.Interfaces.PartialMedium "Medium model";
+    parameter SI.Pressure p0 = 1.01325e5 "Nominal pressure";
+    parameter Units.HydraulicResistance R = 0 "Hydraulic resistance";
+    parameter Medium.SpecificEnthalpy h = 1e5 "Nominal specific enthalpy";
+    parameter Boolean allowFlowReversal = system.allowFlowReversal "= true to allow flow reversal, false restricts to design direction" annotation(
+      Evaluate = true);
+    outer ThermoPower.System system "System wide properties";
+    Medium.AbsolutePressure p "Actual pressure";
+    FlangeB flange(redeclare package Medium = Medium, m_flow(max = if allowFlowReversal then +Modelica.Constants.inf else 0)) annotation(
+      Placement(transformation(extent = {{80, -20}, {120, 20}}, rotation = 0)));
+    Modelica.Blocks.Interfaces.RealInput in_p0 annotation(
+      Placement(transformation(origin = {-40, 92}, extent = {{-20, -20}, {20, 20}}, rotation = 270)));
+    Modelica.Blocks.Interfaces.RealInput in_h annotation(
+      Placement(transformation(origin = {40, 90}, extent = {{-20, -20}, {20, 20}}, rotation = 270)));
+  equation
+    if R == 0 then
+      flange.p = p;
+    else
+      flange.p = p + flange.m_flow * R;
+    end if;
+    p = in_p0;
+    if cardinality(in_p0) == 0 then
+      in_p0 = p0 "Pressure set by parameter";
+    end if;
+    flange.h_outflow = in_h;
+    if cardinality(in_h) == 0 then
+      in_h = h "Enthalpy set by parameter";
+    end if;
+    annotation(
+      Diagram(graphics),
+      Icon(graphics = {Text(extent = {{-106, 90}, {-52, 50}}, textString = "p0"), Text(extent = {{66, 90}, {98, 52}}, textString = "h")}),
+      Documentation(info = "<HTML>
 <p><b>Modelling options</b></p>
 <p>If <tt>R</tt> is set to zero, the pressure source is ideal; otherwise, the outlet pressure decreases proportionally to the outgoing flowrate.</p>
 <p>If the <tt>in_p0</tt> connector is wired, then the source pressure is given by the corresponding signal, otherwise it is fixed to <tt>p0</tt>.</p>
 <p>If the <tt>in_h</tt> connector is wired, then the source pressure is given by the corresponding signal, otherwise it is fixed to <tt>h</tt>.</p>
-</HTML>", revisions="<html>
+</HTML>", revisions = "<html>
 <ul>
 <li><i>16 Dec 2004</i>
     by <a href=\"mailto:francesco.casella@polimi.it\">Francesco Casella</a>:<br>
@@ -8738,62 +6653,50 @@
     by <a href=\"mailto:francesco.casella@polimi.it\">Francesco Casella</a>:<br>
        First release.</li>
 </ul>
-</html>"));
-  end SourceP;
-
-  model SinkP "Pressure sink for water/steam flows"
-    extends Icons.Water.SourceP;
-    extends Modelica.Icons.ObsoleteModel;
-    replaceable package Medium = StandardWater constrainedby
-      Modelica.Media.Interfaces.PartialMedium "Medium model";
-    parameter Medium.AbsolutePressure p0=1.01325e5 "Nominal pressure";
-    parameter Units.HydraulicResistance R=0 "Hydraulic resistance"
-      annotation (Evaluate=true);
-    parameter Medium.SpecificEnthalpy h=1e5 "Nominal specific enthalpy";
-    parameter Boolean allowFlowReversal=system.allowFlowReversal
-      "= true to allow flow reversal, false restricts to design direction"
-      annotation(Evaluate=true);
-    outer ThermoPower.System system "System wide properties";
-    Medium.AbsolutePressure p;
-    FlangeA flange(redeclare package Medium = Medium, m_flow(min=if
-            allowFlowReversal then -Modelica.Constants.inf else 0)) annotation (
-       Placement(transformation(extent={{-120,-20},{-80,20}}, rotation=0)));
-    Modelica.Blocks.Interfaces.RealInput in_p0 annotation (Placement(
-          transformation(
-          origin={-40,88},
-          extent={{-20,-20},{20,20}},
-          rotation=270)));
-    Modelica.Blocks.Interfaces.RealInput in_h annotation (Placement(
-          transformation(
-          origin={40,88},
-          extent={{-20,-20},{20,20}},
-          rotation=270)));
-  equation
-    if R == 0 then
-      flange.p = p;
-    else
-      flange.p = p + flange.m_flow*R;
-    end if;
-
-    p = in_p0;
-    if cardinality(in_p0) == 0 then
-      in_p0 = p0 "Pressure set by parameter";
-    end if;
-
-    flange.h_outflow = in_h;
-    if cardinality(in_h) == 0 then
-      in_h = h "Enthalpy set by parameter";
-    end if;
-    annotation (
-      Icon(graphics={Text(extent={{-106,92},{-56,50}}, textString="p0"), Text(
-              extent={{54,94},{112,52}}, textString="h")}),
-      Diagram(graphics),
-      Documentation(info="<HTML>
+</html>"));
+  end SourceP;
+
+  model SinkP "Pressure sink for water/steam flows"
+    extends Icons.Water.SourceP;
+    extends Modelica.Icons.ObsoleteModel;
+    replaceable package Medium = StandardWater constrainedby Modelica.Media.Interfaces.PartialMedium "Medium model";
+    parameter Medium.AbsolutePressure p0 = 1.01325e5 "Nominal pressure";
+    parameter Units.HydraulicResistance R = 0 "Hydraulic resistance" annotation(
+      Evaluate = true);
+    parameter Medium.SpecificEnthalpy h = 1e5 "Nominal specific enthalpy";
+    parameter Boolean allowFlowReversal = system.allowFlowReversal "= true to allow flow reversal, false restricts to design direction" annotation(
+      Evaluate = true);
+    outer ThermoPower.System system "System wide properties";
+    Medium.AbsolutePressure p;
+    FlangeA flange(redeclare package Medium = Medium, m_flow(min = if allowFlowReversal then -Modelica.Constants.inf else 0)) annotation(
+      Placement(transformation(extent = {{-120, -20}, {-80, 20}}, rotation = 0)));
+    Modelica.Blocks.Interfaces.RealInput in_p0 annotation(
+      Placement(transformation(origin = {-40, 88}, extent = {{-20, -20}, {20, 20}}, rotation = 270)));
+    Modelica.Blocks.Interfaces.RealInput in_h annotation(
+      Placement(transformation(origin = {40, 88}, extent = {{-20, -20}, {20, 20}}, rotation = 270)));
+  equation
+    if R == 0 then
+      flange.p = p;
+    else
+      flange.p = p + flange.m_flow * R;
+    end if;
+    p = in_p0;
+    if cardinality(in_p0) == 0 then
+      in_p0 = p0 "Pressure set by parameter";
+    end if;
+    flange.h_outflow = in_h;
+    if cardinality(in_h) == 0 then
+      in_h = h "Enthalpy set by parameter";
+    end if;
+    annotation(
+      Icon(graphics = {Text(extent = {{-106, 92}, {-56, 50}}, textString = "p0"), Text(extent = {{54, 94}, {112, 52}}, textString = "h")}),
+      Diagram(graphics),
+      Documentation(info = "<HTML>
 <p><b>Modelling options</b></p>
 <p>If <tt>R</tt> is set to zero, the pressure sink is ideal; otherwise, the inlet pressure increases proportionally to the incoming flowrate.</p>
 <p>If the <tt>in_p0</tt> connector is wired, then the source pressure is given by the corresponding signal, otherwise it is fixed to <tt>p0</tt>.</p>
 <p>If the <tt>in_h</tt> connector is wired, then the source pressure is given by the corresponding signal, otherwise it is fixed to <tt>h</tt>.</p>
-</HTML>", revisions="<html>
+</HTML>", revisions = "<html>
 <ul>
 <li><i>16 Dec 2004</i>
     by <a href=\"mailto:francesco.casella@polimi.it\">Francesco Casella</a>:<br>
@@ -8805,62 +6708,50 @@
     by <a href=\"mailto:francesco.casella@polimi.it\">Francesco Casella</a>:<br>
        First release.</li>
 </ul>
-</html>"));
-  end SinkP;
-
-  model SourceW "Flowrate source for water/steam flows"
-    extends Icons.Water.SourceW;
-    extends Modelica.Icons.ObsoleteModel;
-    replaceable package Medium = StandardWater constrainedby
-      Modelica.Media.Interfaces.PartialMedium "Medium model";
-    parameter SI.MassFlowRate w0=0 "Nominal mass flowrate";
-    parameter Medium.AbsolutePressure p0=1e5 "Nominal pressure";
-    parameter Units.HydraulicConductance G=0 "Hydraulic conductance";
-    parameter Medium.SpecificEnthalpy h=1e5 "Nominal specific enthalpy";
-    parameter Boolean allowFlowReversal=system.allowFlowReversal
-      "= true to allow flow reversal, false restricts to design direction"
-      annotation(Evaluate=true);
-    outer ThermoPower.System system "System wide properties";
-    Medium.MassFlowRate w "Mass flowrate";
-    FlangeB flange(redeclare package Medium = Medium, m_flow(max=if
-            allowFlowReversal then +Modelica.Constants.inf else 0)) annotation (
-       Placement(transformation(extent={{80,-20},{120,20}}, rotation=0)));
-    Modelica.Blocks.Interfaces.RealInput in_w0 annotation (Placement(
-          transformation(
-          origin={-40,60},
-          extent={{-20,-20},{20,20}},
-          rotation=270)));
-    Modelica.Blocks.Interfaces.RealInput in_h annotation (Placement(
-          transformation(
-          origin={40,60},
-          extent={{-20,-20},{20,20}},
-          rotation=270)));
-  equation
-    if G == 0 then
-      flange.m_flow = -w;
-    else
-      flange.m_flow = -w + (flange.p - p0)*G;
-    end if;
-
-    w = in_w0;
-    if cardinality(in_w0) == 0 then
-      in_w0 = w0 "Flow rate set by parameter";
-    end if;
-
-    flange.h_outflow = in_h "Enthalpy set by connector";
-    if cardinality(in_h) == 0 then
-      in_h = h "Enthalpy set by parameter";
-    end if;
-    annotation (
-      Icon(graphics={Text(extent={{-98,74},{-48,42}}, textString="w0"), Text(
-              extent={{48,74},{98,42}}, textString="h")}),
-      Diagram(graphics),
-      Documentation(info="<HTML>
+</html>"));
+  end SinkP;
+
+  model SourceW "Flowrate source for water/steam flows"
+    extends Icons.Water.SourceW;
+    extends Modelica.Icons.ObsoleteModel;
+    replaceable package Medium = StandardWater constrainedby Modelica.Media.Interfaces.PartialMedium "Medium model";
+    parameter SI.MassFlowRate w0 = 0 "Nominal mass flowrate";
+    parameter Medium.AbsolutePressure p0 = 1e5 "Nominal pressure";
+    parameter Units.HydraulicConductance G = 0 "Hydraulic conductance";
+    parameter Medium.SpecificEnthalpy h = 1e5 "Nominal specific enthalpy";
+    parameter Boolean allowFlowReversal = system.allowFlowReversal "= true to allow flow reversal, false restricts to design direction" annotation(
+      Evaluate = true);
+    outer ThermoPower.System system "System wide properties";
+    Medium.MassFlowRate w "Mass flowrate";
+    FlangeB flange(redeclare package Medium = Medium, m_flow(max = if allowFlowReversal then +Modelica.Constants.inf else 0)) annotation(
+      Placement(transformation(extent = {{80, -20}, {120, 20}}, rotation = 0)));
+    Modelica.Blocks.Interfaces.RealInput in_w0 annotation(
+      Placement(transformation(origin = {-40, 60}, extent = {{-20, -20}, {20, 20}}, rotation = 270)));
+    Modelica.Blocks.Interfaces.RealInput in_h annotation(
+      Placement(transformation(origin = {40, 60}, extent = {{-20, -20}, {20, 20}}, rotation = 270)));
+  equation
+    if G == 0 then
+      flange.m_flow = -w;
+    else
+      flange.m_flow = (-w) + (flange.p - p0) * G;
+    end if;
+    w = in_w0;
+    if cardinality(in_w0) == 0 then
+      in_w0 = w0 "Flow rate set by parameter";
+    end if;
+    flange.h_outflow = in_h "Enthalpy set by connector";
+    if cardinality(in_h) == 0 then
+      in_h = h "Enthalpy set by parameter";
+    end if;
+    annotation(
+      Icon(graphics = {Text(extent = {{-98, 74}, {-48, 42}}, textString = "w0"), Text(extent = {{48, 74}, {98, 42}}, textString = "h")}),
+      Diagram(graphics),
+      Documentation(info = "<HTML>
 <p><b>Modelling options</b></p>
 <p>If <tt>G</tt> is set to zero, the flowrate source is ideal; otherwise, the outgoing flowrate decreases proportionally to the outlet pressure.</p>
 <p>If the <tt>in_w0</tt> connector is wired, then the source pressure is given by the corresponding signal, otherwise it is fixed to <tt>p0</tt>.</p>
 <p>If the <tt>in_h</tt> connector is wired, then the source pressure is given by the corresponding signal, otherwise it is fixed to <tt>h</tt>.</p>
-</HTML>", revisions="<html>
+</HTML>", revisions = "<html>
 <ul>
 <li><i>16 Dec 2004</i>
     by <a href=\"mailto:francesco.casella@polimi.it\">Francesco Casella</a>:<br>
@@ -8872,61 +6763,49 @@
     by <a href=\"mailto:francesco.casella@polimi.it\">Francesco Casella</a>:<br>
        First release.</li>
 </ul>
-</html>"));
-  end SourceW;
-
-  model SinkW "Flowrate sink for water/steam flows"
-    extends Icons.Water.SourceW;
-    extends Modelica.Icons.ObsoleteModel;
-    replaceable package Medium = StandardWater constrainedby
-      Modelica.Media.Interfaces.PartialMedium "Medium model";
-    parameter Medium.MassFlowRate w0=0 "Nominal mass flowrate";
-    parameter Medium.AbsolutePressure p0=1e5 "Nominal pressure";
-    parameter Units.HydraulicConductance G=0 "Hydraulic conductance";
-    parameter Medium.SpecificEnthalpy h=1e5 "Nominal specific enthalpy";
-    parameter Boolean allowFlowReversal=system.allowFlowReversal
-      "= true to allow flow reversal, false restricts to design direction"
-      annotation(Evaluate=true);
-    outer ThermoPower.System system "System wide properties";
-    Medium.MassFlowRate w "Mass flowrate";
-    FlangeA flange(redeclare package Medium = Medium, m_flow(min=if
-            allowFlowReversal then -Modelica.Constants.inf else 0)) annotation (
-       Placement(transformation(extent={{-120,-20},{-80,20}}, rotation=0)));
-    Modelica.Blocks.Interfaces.RealInput in_w0 annotation (Placement(
-          transformation(
-          origin={-40,60},
-          extent={{-20,-20},{20,20}},
-          rotation=270)));
-    Modelica.Blocks.Interfaces.RealInput in_h annotation (Placement(
-          transformation(
-          origin={40,60},
-          extent={{-20,-20},{20,20}},
-          rotation=270)));
-  equation
-    if G == 0 then
-      flange.m_flow = w;
-    else
-      flange.m_flow = w + (flange.p - p0)*G;
-    end if;
-
-    w = in_w0 "Flow rate set by connector";
-    if cardinality(in_w0) == 0 then
-      in_w0 = w0 "Flow rate set by parameter";
-    end if;
-
-    flange.h_outflow = in_h "Enthalpy set by connector";
-    if cardinality(in_h) == 0 then
-      in_h = h "Enthalpy set by parameter";
-    end if;
-    annotation (
-      Icon(graphics={Text(extent={{-98,72},{-48,40}}, textString="w0"), Text(
-              extent={{48,72},{98,40}}, textString="h")}),
-      Documentation(info="<HTML>
+</html>"));
+  end SourceW;
+
+  model SinkW "Flowrate sink for water/steam flows"
+    extends Icons.Water.SourceW;
+    extends Modelica.Icons.ObsoleteModel;
+    replaceable package Medium = StandardWater constrainedby Modelica.Media.Interfaces.PartialMedium "Medium model";
+    parameter Medium.MassFlowRate w0 = 0 "Nominal mass flowrate";
+    parameter Medium.AbsolutePressure p0 = 1e5 "Nominal pressure";
+    parameter Units.HydraulicConductance G = 0 "Hydraulic conductance";
+    parameter Medium.SpecificEnthalpy h = 1e5 "Nominal specific enthalpy";
+    parameter Boolean allowFlowReversal = system.allowFlowReversal "= true to allow flow reversal, false restricts to design direction" annotation(
+      Evaluate = true);
+    outer ThermoPower.System system "System wide properties";
+    Medium.MassFlowRate w "Mass flowrate";
+    FlangeA flange(redeclare package Medium = Medium, m_flow(min = if allowFlowReversal then -Modelica.Constants.inf else 0)) annotation(
+      Placement(transformation(extent = {{-120, -20}, {-80, 20}}, rotation = 0)));
+    Modelica.Blocks.Interfaces.RealInput in_w0 annotation(
+      Placement(transformation(origin = {-40, 60}, extent = {{-20, -20}, {20, 20}}, rotation = 270)));
+    Modelica.Blocks.Interfaces.RealInput in_h annotation(
+      Placement(transformation(origin = {40, 60}, extent = {{-20, -20}, {20, 20}}, rotation = 270)));
+  equation
+    if G == 0 then
+      flange.m_flow = w;
+    else
+      flange.m_flow = w + (flange.p - p0) * G;
+    end if;
+    w = in_w0 "Flow rate set by connector";
+    if cardinality(in_w0) == 0 then
+      in_w0 = w0 "Flow rate set by parameter";
+    end if;
+    flange.h_outflow = in_h "Enthalpy set by connector";
+    if cardinality(in_h) == 0 then
+      in_h = h "Enthalpy set by parameter";
+    end if;
+    annotation(
+      Icon(graphics = {Text(extent = {{-98, 72}, {-48, 40}}, textString = "w0"), Text(extent = {{48, 72}, {98, 40}}, textString = "h")}),
+      Documentation(info = "<HTML>
 <p><b>Modelling options</b></p>
 <p>If <tt>G</tt> is set to zero, the flowrate source is ideal; otherwise, the incoming flowrate increases proportionally to the inlet pressure.</p>
 <p>If <tt>w0Fix</tt> is set to true, the incoming flowrate is given by the parameter <tt>w0</tt>; otherwise, the <tt>in_w0</tt> connector must be wired, providing the (possibly varying) source flowrate.</p>
 <p>If <tt>hFix</tt> is set to true, the source enthalpy is given by the parameter <tt>h</tt>; otherwise, the <tt>in_h</tt> connector must be wired, providing the (possibly varying) source enthalpy.</p>
-</HTML>", revisions="<html>
+</HTML>", revisions = "<html>
 <ul>
 <li><i>16 Dec 2004</i>
     by <a href=\"mailto:francesco.casella@polimi.it\">Francesco Casella</a>:<br>
@@ -8938,63 +6817,54 @@
     by <a href=\"mailto:francesco.casella@polimi.it\">Francesco Casella</a>:<br>
        First release.</li>
 </ul>
-</html>"),
-      Diagram(graphics));
-  end SinkW;
-
-  model ThroughW "Prescribes the flow rate across the component"
-    extends Icons.Water.SourceW;
-    extends Modelica.Icons.ObsoleteModel;
-    replaceable package Medium = StandardWater constrainedby
-      Modelica.Media.Interfaces.PartialMedium "Medium model";
-    parameter Medium.MassFlowRate w0=0 "Nominal mass flowrate";
-    parameter Boolean allowFlowReversal=system.allowFlowReversal
-      "= true to allow flow reversal, false restricts to design direction"
-      annotation(Evaluate=true);
-    outer ThermoPower.System system "System wide properties";
-    Medium.MassFlowRate w "Mass flowrate";
-    FlangeA inlet(redeclare package Medium = Medium, m_flow(min=if
-            allowFlowReversal then -Modelica.Constants.inf else 0)) annotation (
-       Placement(transformation(extent={{-120,-20},{-80,20}}, rotation=0)));
-    FlangeB outlet(redeclare package Medium = Medium, m_flow(max=if
-            allowFlowReversal then +Modelica.Constants.inf else 0)) annotation (
-       Placement(transformation(extent={{80,-20},{120,20}}, rotation=0)));
-    Modelica.Blocks.Interfaces.RealInput in_w0 annotation (Placement(
-          transformation(
-          origin={-40,60},
-          extent={{-20,-20},{20,20}},
-          rotation=270)));
-  equation
-    inlet.m_flow + outlet.m_flow = 0 "Mass balance";
-    inlet.m_flow = w "Flow characteristics";
-
-    w = in_w0;
-    if cardinality(in_w0) == 0 then
-      in_w0 = w0 "Flow rate set by parameter";
-    end if;
-
-    // Energy balance
-    inlet.h_outflow = inStream(outlet.h_outflow);
-    inStream(inlet.h_outflow) = outlet.h_outflow;
-    annotation (
-      Icon(graphics={Text(extent={{-98,72},{-48,40}}, textString="w0")}),
-      Documentation(info="<HTML>
+</html>"),
+      Diagram(graphics));
+  end SinkW;
+
+  model ThroughW "Prescribes the flow rate across the component"
+    extends Icons.Water.SourceW;
+    extends Modelica.Icons.ObsoleteModel;
+    replaceable package Medium = StandardWater constrainedby Modelica.Media.Interfaces.PartialMedium "Medium model";
+    parameter Medium.MassFlowRate w0 = 0 "Nominal mass flowrate";
+    parameter Boolean allowFlowReversal = system.allowFlowReversal "= true to allow flow reversal, false restricts to design direction" annotation(
+      Evaluate = true);
+    outer ThermoPower.System system "System wide properties";
+    Medium.MassFlowRate w "Mass flowrate";
+    FlangeA inlet(redeclare package Medium = Medium, m_flow(min = if allowFlowReversal then -Modelica.Constants.inf else 0)) annotation(
+      Placement(transformation(extent = {{-120, -20}, {-80, 20}}, rotation = 0)));
+    FlangeB outlet(redeclare package Medium = Medium, m_flow(max = if allowFlowReversal then +Modelica.Constants.inf else 0)) annotation(
+      Placement(transformation(extent = {{80, -20}, {120, 20}}, rotation = 0)));
+    Modelica.Blocks.Interfaces.RealInput in_w0 annotation(
+      Placement(transformation(origin = {-40, 60}, extent = {{-20, -20}, {20, 20}}, rotation = 270)));
+  equation
+    inlet.m_flow + outlet.m_flow = 0 "Mass balance";
+    inlet.m_flow = w "Flow characteristics";
+    w = in_w0;
+    if cardinality(in_w0) == 0 then
+      in_w0 = w0 "Flow rate set by parameter";
+    end if;
+// Energy balance
+    inlet.h_outflow = inStream(outlet.h_outflow);
+    inStream(inlet.h_outflow) = outlet.h_outflow;
+    annotation(
+      Icon(graphics = {Text(extent = {{-98, 72}, {-48, 40}}, textString = "w0")}),
+      Documentation(info = "<HTML>
 This component prescribes the flow rate passing through it. The change of
 specific enthalpy due to the pressure difference between the inlet and the
 outlet is ignored; use <t>Pump</t> models if this has to be taken into account correctly.
 <p><b>Modelling options</b></p>
 <p>If <tt>w0Fix</tt> is set to true, the flowrate is given by the parameter <tt>w0</tt>; otherwise, the <tt>in_w0</tt> connector must be wired, providing the (possibly varying) flowrate value.</p>
-</HTML>", revisions="<html>
+</HTML>", revisions = "<html>
 <ul>
 <li><i>18 Mar 2005</i>
     by <a href=\"mailto:francesco.casella@polimi.it\">Francesco Casella</a>:<br>
        First release.</li>
 </ul>
-</html>"),
-      Diagram(graphics));
-  end ThroughW;
-
-  annotation (Documentation(info="<HTML>
+</html>"),
+      Diagram(graphics));
+  end ThroughW;
+  annotation(
+    Documentation(info = "<HTML>
 This package contains models of physical processes and components using water or steam as working fluid.
 <p>All models use the <tt>StandardWater</tt> medium model by default, which is in turn set to <tt>Modelica.Media.Water.StandardWater</tt> at the library level. It is of course possible to redeclare the medium model to any model extending <tt>Modelica.Media.Interfaces.PartialMedium</tt> (or <tt>PartialTwoPhaseMedium</tt> for 2-phase models). This can be done by directly setting Medium in the parameter dialog, or through a local package definition, as shown e.g. in <tt>Test.TestMixerSlowFast</tt>. The latter solution allows to easily replace the medium model for an entire set of components.
 <p>All models with dynamic equations provide initialisation support. Set the <tt>initOpt</tt> parameter to the appropriate value:
@@ -9005,5 +6875,5 @@
 <li><tt>Choices.Init.Options.steadyStateNoT</tt>: steady-state initialisation (except temperature)
 </ul>
 The latter options can be useful when two or more components are connected directly so that they will have the same pressure or temperature, to avoid over-specified systems of initial equations.
-</HTML>"));
-end Water;
+</HTML>"));
+end Water;
\ No newline at end of file
Only in converted-libraries/.openmodelica/libraries/ThermoPower 3.1.0-master: Water.mo.after
Only in converted-libraries/.openmodelica/libraries/ThermoPower 3.1.0-master: Water.mo.before
diff -ur "/home/hudson/saved_omc/libraries/.openmodelica/libraries/ThermoPower 3.1.0-master/openmodelica.metadata.json" "converted-libraries/.openmodelica/libraries/ThermoPower 3.1.0-master/openmodelica.metadata.json"
--- "/home/hudson/saved_omc/libraries/.openmodelica/libraries/ThermoPower 3.1.0-master/openmodelica.metadata.json"	2022-03-10 09:57:37.956144120 +0000
+++ "converted-libraries/.openmodelica/libraries/ThermoPower 3.1.0-master/openmodelica.metadata.json"	2022-03-10 09:59:05.912155261 +0000
@@ -1 +1 @@
-{"path":"ThermoPower", "sha":"650be2c8cbd5abc3535e92b865e509073afc8aeb", "support":"noSupport", "uses":{"Modelica":"3.2.3"}, "version":"3.1.0-master", "zipfile":"https://github.com/casella/ThermoPower/archive/650be2c8cbd5abc3535e92b865e509073afc8aeb.zip"}
+{"path": "ThermoPower", "sha": "650be2c8cbd5abc3535e92b865e509073afc8aeb", "support": "noSupport", "uses": {"Modelica": "4.0.0"}, "version": "3.1.0-master", "zipfile": "https://github.com/casella/ThermoPower/archive/650be2c8cbd5abc3535e92b865e509073afc8aeb.zip", "extraInfo": "Conversion script /home/hudson/saved_omc/libraries/.openmodelica/libraries/Modelica 4.0.0+maint.om//Resources/Scripts/Conversion/ConvertModelica_from_3.2.3_to_4.0.0.mos was applied"}
\ No newline at end of file
diff -ur "/home/hudson/saved_omc/libraries/.openmodelica/libraries/ThermoPower 3.1.0-master/package.mo" "converted-libraries/.openmodelica/libraries/ThermoPower 3.1.0-master/package.mo"
--- "/home/hudson/saved_omc/libraries/.openmodelica/libraries/ThermoPower 3.1.0-master/package.mo"	2022-03-10 09:57:37.956144120 +0000
+++ "converted-libraries/.openmodelica/libraries/ThermoPower 3.1.0-master/package.mo"	2022-03-10 09:58:49.896153233 +0000
@@ -1,8 +1,8 @@
 within ;
 package ThermoPower "Open library for thermal power plant simulation"
   extends Modelica.Icons.Package;
-  import SI = Modelica.SIunits;
-  import NonSI = Modelica.SIunits.Conversions.NonSIunits;
+  import Modelica.Units.SI;
+  import Modelica.Units.NonSI;
 
 
 model System "System wide properties and defaults"
@@ -1391,7 +1391,7 @@
   end linspaceExt;
 
   block OffsetController "Offset computation for steady-state conditions"
-    extends Modelica.Blocks.Interfaces.BlockIcon;
+    extends Modelica.Blocks.Icons.Block;
     parameter Real steadyStateGain=0.0
       "0.0: Adds offset to input - 1.0: Closed loop action to find steady state";
     parameter Real SP0 "Initial setpoint for the controlled variable";
@@ -1754,7 +1754,7 @@
   end ValveCharacteristics;
 
   package FanCharacteristics "Functions for fan characteristics"
-    import NonSI = Modelica.SIunits.Conversions.NonSIunits;
+    import Modelica.Units.NonSI;
 
     partial function baseFlow "Base class for fan flow characteristics"
       extends Modelica.Icons.Function;
@@ -1766,14 +1766,14 @@
     partial function basePower
       "Base class for fan power consumption characteristics"
       extends Modelica.Icons.Function;
-      input Modelica.SIunits.VolumeFlowRate q_flow "Volumetric flow rate";
+      input Modelica.Units.SI.VolumeFlowRate q_flow "Volumetric flow rate";
       input Real bladePos=1 "Blade position";
-      output Modelica.SIunits.Power consumption "Power consumption";
+      output Modelica.Units.SI.Power consumption "Power consumption";
     end basePower;
 
     partial function baseEfficiency "Base class for efficiency characteristics"
       extends Modelica.Icons.Function;
-      input Modelica.SIunits.VolumeFlowRate q_flow "Volumetric flow rate";
+      input Modelica.Units.SI.VolumeFlowRate q_flow "Volumetric flow rate";
       input Real bladePos=1 "Blade position";
       output Real eta "Efficiency";
     end baseEfficiency;
@@ -1786,9 +1786,9 @@
 
     function linearFlow "Linear flow characteristic, fixed blades"
       extends baseFlow;
-      input Modelica.SIunits.VolumeFlowRate q_nom[2]
+      input Modelica.Units.SI.VolumeFlowRate q_nom[2]
         "Volume flow rate for two operating points (single fan)" annotation(Dialog);
-      input Modelica.SIunits.Height H_nom[2]
+      input Modelica.Units.SI.Height H_nom[2]
         "Specific energy for two operating points" annotation(Dialog);
       /* Linear system to determine the coefficients:
   H_nom[1] = c[1] + q_nom[1]*c[2];
@@ -1804,9 +1804,9 @@
 
     function quadraticFlow "Quadratic flow characteristic, fixed blades"
       extends baseFlow;
-      input Modelica.SIunits.VolumeFlowRate q_nom[3]
+      input Modelica.Units.SI.VolumeFlowRate q_nom[3]
         "Volume flow rate for three operating points (single fan)" annotation(Dialog);
-      input Modelica.SIunits.Height H_nom[3]
+      input Modelica.Units.SI.Height H_nom[3]
         "Specific work for three operating points" annotation(Dialog);
     protected
       parameter Real q_nom2[3]={q_nom[1]^2,q_nom[2]^2,q_nom[3]^2}
@@ -1849,9 +1849,9 @@
 
     function polynomialFlow "Polynomial flow characteristic, fixed blades"
       extends baseFlow;
-      input Modelica.SIunits.VolumeFlowRate q_nom[:]
+      input Modelica.Units.SI.VolumeFlowRate q_nom[:]
         "Volume flow rate for N operating points (single fan)" annotation(Dialog);
-      input Modelica.SIunits.Height H_nom[:]
+      input Modelica.Units.SI.Height H_nom[:]
         "Specific work for N operating points"                                      annotation(Dialog);
     protected
       parameter Integer N=size(q_nom, 1) "Number of nominal operating points";
@@ -1880,7 +1880,7 @@
 
     function constantPower "Constant power consumption characteristic"
       extends FanCharacteristics.basePower;
-      input Modelica.SIunits.Power power=0 "Constant power consumption" annotation(Dialog);
+      input Modelica.Units.SI.Power power=0 "Constant power consumption" annotation(Dialog);
     algorithm
       consumption := power;
     end constantPower;
@@ -1888,9 +1888,9 @@
     function quadraticPower
       "Quadratic power consumption characteristic, fixed blades"
       extends basePower;
-      input Modelica.SIunits.VolumeFlowRate q_nom[3]
+      input Modelica.Units.SI.VolumeFlowRate q_nom[3]
         "Volume flow rate for three operating points (single fan)" annotation(Dialog);
-      input Modelica.SIunits.Power W_nom[3]
+      input Modelica.Units.SI.Power W_nom[3]
         "Power consumption for three operating points" annotation(Dialog);
     protected
       Real q_nom2[3]={q_nom[1]^2,q_nom[2]^2,q_nom[3]^2}
@@ -1910,7 +1910,7 @@
       function quadraticFlowBlades
         "Quadratic flow characteristic, movable blades"
         extends Modelica.Icons.Function;
-        input Modelica.SIunits.VolumeFlowRate q_flow;
+        input Modelica.Units.SI.VolumeFlowRate q_flow;
         input Real bladePos;
         input Real bladePos_nom[:];
         input Real c[:, :]
@@ -1945,9 +1945,9 @@
       function quadraticFlowBladesCoeff
         extends Modelica.Icons.Function;
         input Real bladePos_nom[:];
-        input Modelica.SIunits.VolumeFlowRate q_nom[3, :]
+        input Modelica.Units.SI.VolumeFlowRate q_nom[3, :]
           "Volume flow rate for three operating points at N_pos blade positionings";
-        input Modelica.SIunits.Height H_nom[3, :]
+        input Modelica.Units.SI.Height H_nom[3, :]
           "Specific work for three operating points at N_pos blade positionings";
         output Real c[3, size(bladePos_nom, 1)]
           "Coefficients of quadratic specific work characteristic";
@@ -1997,10 +1997,15 @@
   annotation (Documentation(info="<HTML>
 This package contains general-purpose functions and models
 </HTML>"));
+
 end Functions;
 
 
-annotation (
+
+
+
+
+  annotation (
   Documentation(info="<html>
 <h2>General Information</h2>
 <p>The ThermoPower library is an open-source <a href=\"http://www.modelica.org/libraries\">Modelica library</a> for the dynamic modelling of thermal power plants and energy conversion systems. It provides basic components for system-level modelling, in particular for the study of control systems in traditional and innovative power plants and energy conversion systems.</p>
@@ -2105,6 +2110,6 @@
 <p>The ThermoPower package is licensed by Politecnico di Milano under the <b><a href=\"http://www.modelica.org/licenses/ModelicaLicense2\">Modelica License 2</a></b>. </p>
 <p><h4>Copyright &copy; 2002-2014, Politecnico di Milano.</h4></p>
 </html>"),
-  uses(Modelica(version="3.2.3")),
+  uses(Modelica(version= "4.0.0")),
   version="3.1");
 end ThermoPower;
