• No results found

4. Physical Models for Thermo-Hydraulics

4.6 Choice of Dynamic State Variables

Chapter 4. Physical Models for Thermo-Hydraulics Single Component Fluids

In order to be as general as possible, the derivations will be done for a control volume of variable size, first for single component fluids and, equivalent in the single phase case, fluid mixtures with fixed mass com-position. The change of volume dV is usually caused by moving systems parts like an engine piston.

d dt

 M U V

 =



Pn

i m˙ Pn

i q˙conv,i+Pl

jq˙trans f er,j− pdVdt dV

 =



dM dt dU dt dV dt

 (4.32)

In a first step, this equation is written in the intensive variables density ρ and specific inner energy u and the volume.

d dt

 ρ u V

 =



1

V 0 −Vρ

Mu M1 Vu

0 0 1

d dt

 M U V



If pressure and enthalpy are chosen as states, the first law and the mass balance can be rewritten into these states as follows:

d dt

 ρ u V

 =





Vρ V p

h Vρ Vh

p 0

VuV p

h VuVh

p 0

0 0 1





| {z }

Jacobian MatrixJ

d dt

 p h V

 (4.33)

To obtain differential equations for pressure and enthalpy(4.33) must be solved for the derivative of(p,h)

d dt

 p h V

 =J−1d dt

 ρ u V



existing EOS-implementations in such a way that an automatic choice of states can be done by Dymola is a lot more work than the manual coordinate transformation presented in this section. Another possibility would be to extend Modelica’s annotations for functions with more details about derivatives into specific directions.

4.6 Choice of Dynamic State Variables The inverse of the Jacobian is computed as

J−1= 1 detJ





VuVh

pVh

p 0

VuV p

h V p

h 0

0 0 V p

h VuVh

pVh

p VuV p

h





with the determinant

detJ= Vρ V p

h

Vu Vh

p

− Vρ Vh

p

Vu V p

h

It is possible to reduce the partial derivatives of u to the ones of ρ by using u = h − p/ρ, but this rewrite does not improve the clarity of the model. It may be useful for implementation though, if only the ρ -derivatives are available5.

Equivalent derivations can be done for pressure and temperature as states and for density and temperature. The advantage of the latter two forms is that there are many medium property models which are explicit in these variables. This avoids a non-linear system of equation in a cen-tral part of the model and is therefore very efficient. In order to simplify notation, the volume is assumed constant in these derivations.

d dt

ρ u

!

=

 1 0

Vu

T VTVu

ρ

| {z }

Jacobian Matrix

d dt

ρ T

!

For ideal gases this simplifies further because, Vu/VρhT = 0 and further it is common to writeVu/VThρ= cv, the heat capacity at constant volume.

Solving for density and temperature yields:

d dt

ρ T

!

=J−1d dt

ρ u

! ,

with the inverse of the Jacobian:

J−1= 1 cv

cv 0

Vu

T 1

5Note: this way of writing the transformations to select suitable state variables assumes that some other part of the model is able to calculate the partial derivatives in the matrix efficiently. InThermoFluid, the medium models compute the needed derivatives.

Chapter 4. Physical Models for Thermo-Hydraulics

Because of the dependence between pressure and temperature in the two phase region, these two variables can, under the assumption of ther-modynamic equilibrium, not be used as dynamic states. But outside the two phase region they have the advantage that these two variables are often readily available from measurements.

d dt

ρ u

!

=



V p

T VT

p VuV p

T VTVu

p



| {z }

Jacobian Matrix

d dt

p T

!

For ideal gases the above simplifies again as VuV p

T = 0 and VTVu

p = cv. Solving for pressure and temperature yields:

d dt

p T

!

=J−1d dt

ρ u

!

. (4.34)

Writing the same physical model of a fluid in a control volume in three different ways may seem nothing more than an academic exercise, but if we look at the numerical implications of the combination of a thermody-namic EOS and one of the above dythermody-namic equations into a DAE, there are two reasons for using different models in different situations. The goal of the reformulation is to arrive at a model in which the dynamic states are

• explicit inputs to the EOS (in the cases of {ρ,T,V} and {p,T,V} as states) or

• make use of the shape of the EOS to choose numerically favorable state coordinates in the case of{p,h,V}.

The shape of the EOS can be such that a small error in one of the states (e. g., with an implicit equation for the EOS which is solved numerically only to a certain accuracy) results in a large error of other variables calculated via the EOS. If liquids have to be modeled as compressible, the density (equivalently, the total mass) have the property that a small numerical error in them is amplified via a gain given by V p/Vρhh to the corresponding pressure given by the EOS. The pressure in turn influences strongly the mass flows into the control volume and the change in mass in the next time step. The result is a fluctuation in the pressures and mass flows that looks like a noise signal for moderate tolerance choices of the integration routine. Thus, density is a bad choice of state variable in the liquid region. A good visualization of this property is given by the plots

4.6 Choice of Dynamic State Variables

Density as a Function of Enthalpy and Pressure

200

1000 2000

4000 1

0.1 1 10 100 1000 Density [kg/m3]

Enthalpy [kJ/kg]

100 1000

10 Pressure [bar]

400

x = 0

x = 1

Figure 4.4 EOS for water: density as a function of pressure and specific enthalpy.

Used with permission from[Mühlthaler, 2000].

of the EOS for water in Figure 4.4 and 4.5. Note the logarithmic scales for all variables, which are necessary to catch the technically interesting region.

Multi-Component Fluid Mixtures

For multi-component flows, the number of possible choices for the dynamic states gets larger and the availability of numerically robust and simple definitions for the EOS gets worse. For the EOS, the basis are the EOS of the single components which are combined using empirical mixing rules.

A detailed presentation of mixing rules is found in [Poling et al., 2001].

Most of the equations of state which are in use in process engineering are cubic6 equations of state of the general form

p= RT

V− ba

V2+ ubV + wb2 (4.35)

where a,b,u and w are component specific constants, R is the gas constant, T is the temperature and V is the volume. This is a simplified version of (4.28) assuming thatη = b. It can easily be seen that this equation can not be made explicit in variables which can be used as dynamic states,

6These equations are called cubic because they can be transformed into a cubic polynomial in the compressibility, see[Polinget al., 2001].

Chapter 4. Physical Models for Thermo-Hydraulics

Pressure as a Function of Density and Enthalpy

0.1 0.1

1 10 100 1000 10000

200 10000 bar

1000 300

100 30

10 3

1 bar

2000 4000 1000

Enthalpy [kJ/kg]

Density [kg/m3]

1000 100

10 1 Pressure [bar]

400

Figure 4.5 EOS for water: pressure as a function of density and specific enthalpy.

The strong variations of pressure in the liquid region caused by small density varia-tions are obvious from this plot of the density-pressure-enthalpy surface. Used with permission from[Mühlthaler, 2000].

e. g., p and T. It can be rewritten to a cubic equation in the compressibility Z (see [Polinget al., 2001]), but this equation has three solutions in some areas and only one of them is physically meaningful. A non-linear system of equations is therefore not avoidable, but selecting T instead of U as one of the dynamic states reduces the system of equations to dimension one, solving for p. A common choice of property computations for static calculations is to treat p as an input in the calling structure, using the compressibility form of the cubic EOS. This gives a non-linear system of equations if the volume V is a known input (constant or, in piston engines, a state). The derivative V p/V VhT can be calculated analytically to improve efficiency when solving for p with a Newton iteration.

When dealing with mixtures of components, both mass- and mole based models can be used, they are fully equivalent. Rewriting the inner energy and mole amounts into temperature and moles as dynamic states is done as follows (block-matrix notation, boldface for vectors and matrices):

d dt =

 Nn

U V

 =



In,n 0n,1 0n,1

dU dNi

T,V 1,n dU dT

N,V dU dV

N,T

0 0 1



d dt

 N T V

 (4.36)

The inverse of the Jacobian is used again to make this model explicit in

4.6 Choice of Dynamic State Variables the mole vector, the temperature and the volume:

J−1= 1

dU dT

N,V



In,n 0n,1 0n,1

dNdUi

T,V 1,ndUdT

N,VdUdV

N,T

0 0 1



The structure of the Jacobian inverse reveals that only the equation for the inner energy is transformed into one for the temperature. The equa-tions for the moles remain unchanged from(4.36).

The same transformation can be applied equivalently for component masses. By exchanging moles Ni with component masses Mi and deriva-tives with respect to Ni with derivatives with respect to Mi,(4.36) is the same for a component mass based model.

The generality and multi-purpose formulation of the models makes it difficult to recognize the underlying PDE in the above equations. A variable size volume is rarely assumed in PDE models and only used in lumped control volume models, but this makes it possible to use the same Modelica classes for both cases with different parameters and boundary conditions. Transformation into different forms of states makes it difficult to see the connection between these equations and the balance equations in Section 4.3. Furthermore, PDE formulations are usually written in intensive variables for an infinitesimal control volume. A comparison to the PDE-formulation in(4.4) reveals the following differences:

• Diffusion is neglected because it does not apply to lumped parameter models. Inside distributed models it is a trivial extension to add diffusion to the mass- or energy flow terms.

• The derivations take extensive quantities as the fundamental de-scription and only change to intensive ones if necessary for improv-ing efficiency.

• The transport equations for energy and mass(or component masses) are regarded as vector equations allowing a change of coordinates involving both of them. This is not done in computational fluid dy-namics.

• Source terms and in/outflow terms are lumped together for the change of coordinates.

The different forms of the dynamic state equations for mass and energy are implemented in BaseClasses.StateTransforms , see Section 5.6.

Some other modeling packages, like gPROMS for process modeling, recommend differing guidelines for writing lumped and distributed pa-rameter models. The gPROMS developers recommend to write lumped

Chapter 4. Physical Models for Thermo-Hydraulics

parameter models in extensive variables and distributed parameter mod-els in intensive variables7. This corresponds to the prevailing presenta-tion of lumped and distributed parameter models in the literature. On the other hand, this precludes the savings in coding and maintenance effort which is a major motivation behind object-oriented library development.

Differing guidelines for these two cases are incompatible with the Ther-moFluid principle of unifying lumped and distributed parameter models.