chemical reaction modeling with thermofluid/mf and

11
Chemical Reaction Modeling with ThermoFluid/MF and MultiFlash Tummescheit, Hubertus; Eborn, Jonas Published in: Modelica'2002 Proceedings 2002 Link to publication Citation for published version (APA): Tummescheit, H., & Eborn, J. (2002). Chemical Reaction Modeling with ThermoFluid/MF and MultiFlash. In Modelica'2002 Proceedings (pp. 31-39). Modelica Association. http://www.modelica.org/events/Conference2002/papers/p05_Tummescheit.pdf Total number of authors: 2 General rights Unless other specific re-use rights are stated the following general rights apply: Copyright and moral rights for the publications made accessible in the public portal are retained by the authors and/or other copyright owners and it is a condition of accessing publications that users recognise and abide by the legal requirements associated with these rights. • Users may download and print one copy of any publication from the public portal for the purpose of private study or research. • You may not further distribute the material or use it for any profit-making activity or commercial gain • You may freely distribute the URL identifying the publication in the public portal Read more about Creative commons licenses: https://creativecommons.org/licenses/ Take down policy If you believe that this document breaches copyright please contact us providing details, and we will remove access to the work immediately and investigate your claim.

Upload: others

Post on 12-May-2022

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Chemical Reaction Modeling with ThermoFluid/MF and

LUND UNIVERSITY

PO Box 117221 00 Lund+46 46-222 00 00

Chemical Reaction Modeling with ThermoFluid/MF and MultiFlash

Tummescheit, Hubertus; Eborn, Jonas

Published in:Modelica'2002 Proceedings

2002

Link to publication

Citation for published version (APA):Tummescheit, H., & Eborn, J. (2002). Chemical Reaction Modeling with ThermoFluid/MF and MultiFlash. InModelica'2002 Proceedings (pp. 31-39). Modelica Association.http://www.modelica.org/events/Conference2002/papers/p05_Tummescheit.pdf

Total number of authors:2

General rightsUnless other specific re-use rights are stated the following general rights apply:Copyright and moral rights for the publications made accessible in the public portal are retained by the authorsand/or other copyright owners and it is a condition of accessing publications that users recognise and abide by thelegal requirements associated with these rights. • Users may download and print one copy of any publication from the public portal for the purpose of private studyor research. • You may not further distribute the material or use it for any profit-making activity or commercial gain • You may freely distribute the URL identifying the publication in the public portal

Read more about Creative commons licenses: https://creativecommons.org/licenses/Take down policyIf you believe that this document breaches copyright please contact us providing details, and we will removeaccess to the work immediately and investigate your claim.

Page 2: Chemical Reaction Modeling with ThermoFluid/MF and

������������ ���������������������� ������ �������������������� ������������������������������������������� ����������� ��� !" #

������������������������������������������������ �����!$"!# �%%� &�������'������(�)��"���*���������+�,&)*- .��������������� /�����0�

1�������������2��3�����������2������������������������� ��������������������������������

���������� ������� ����� .�� &������� '����� �(� )��" ��� *������� ��+� ,&)*- ����� �(�

*����3 ��� ���������3 .��������������� /�����0 ,�������� �� �� ��������������-�

�� ����������45�� &0�����16 )��� 72������� ���� 8��9��� ��)16 &������� �� ������� ��� ���������� 7������ )��3:����

;��5����0 72�����

��������� ����������.�� 1������������3� ��������7��2����� ���3�<������ ������6��� &�������'������(�)��"���*���������+�,&)*- ������(�*����3������������3 .��������������� /�����0

Page 3: Chemical Reaction Modeling with ThermoFluid/MF and

Tummescheit H., Eborn J. Chemical Reaction Modeling with ThermoFluid/MF and MultiFlash

The Modelica Association 31 Modelica 2002, March 18−19, 2002

Chemical Reaction Modeling withThermoFluid/MF and MultiFlash

Hubertus Tummescheit† and Jonas Eborn‡

†Department of Automatic ControlLund University, [email protected]

‡United Technologies Research CenterEast Hartford, Connecticut, USA

[email protected]

Abstract

The free Modelica library THERMOFLUID (see [2]and [11]) was developed for simulation of thermo-hydraulic applications, both for single-species appli-cations like the water-steam cycle in a thermal powerplant and for multi-species applications with gas mix-tures. It has demonstrated its flexibility for model-ing thermodynamic and process applications in a va-riety of industrial and academic projects, see [10], [3]and [7]. This article describes how support for chemi-cal reactions and membrane diffusion has been addedto THERMOFLUID, thus expanding the area of pos-sible applications to include reacting flows, chemi-cal batch reactors, catalytic converters, etc. Anothercrucial part of the modeling work has to be spent ongetting physical property data of sufficient accuracyand with acceptable computational complexity for en-gineering purposes into the model. This has beenadressed in the development of a commercial inter-face to the industry-standard physical property pack-age MultiFlash. The new Modelica library THER-MOFLUID/MF provides the modeler with two tool-boxes. Firstly, a low-level Modelica function interfaceto MultiFlash. MultiFlash consists of a core of physi-cal property calculation routines and a basic databaseof the most comman chemical components and a num-ber of add-on property databases. The interface givesaccess to multi-component, multi-phase property cal-culations including gas, several liquid and condensedphases, wax formations and hydrates. Secondly, ahigh-level Modelica model library which is fully in-tegrated with the THERMOFLUID library and imple-ments robust and efficient dynamical models for themost common process engineering equipment. In ad-dition, reliable crossing functions for detecting phaseboundaries in multi-phase, multi-component mixtures

have been implemented for the first time in a high-level modeling language. The crossing functions makeit possible to simulate processes correctly even at off-design operating points and under start-up conditions.A flash volume may in such cases be filled with onlyliquid or only gas. Crossing functions for phase transi-tions ensure high performance simulation even in thesecases.

1 Flexible handling of chemical reac-tions

In standard chemical textbooks, reactions are treatedas source terms in component concentration balances:

dcidt

� cini � couti�ri (1)

where ri are the component reaction rates, given bya kinetic expression. In a more general way, we caninclude the reaction terms in the component mass bal-ance and total energy balance

dMi

dt� min

i� mout

i�rZi � MWi (2)

dUdt

� qin � qout� nc

∑i � 1

rZi � Hfi (3)

where rZ are reaction rates in moles/s, q is convectiveheat flow, m mass flow and Hf is component enthalpyof formation.

1.1 ThermoFluid balance equations

In THERMOFLUID, the general balance equa-tions are implemented in the package Base-Classes.Balances. The basic balance equationsshould not be modified by the average user and thus

Page 4: Chemical Reaction Modeling with ThermoFluid/MF and

Chemical Reaction Modeling with ThermoFluid/MF and MultiFlash Tummescheit H., Eborn J.

Modelica 2002, March 18−19, 2002 32 The Modelica Association

Figure 1: Schematic of the HeatAndMassObject withheat interaction and reaction objects (no diffusion con-nector present).

need to be general enough to handle all cases from anisolated gas volume to a reactor with added mass- andheat transfer laws. The model structure has to providethe option to add any kind of heat- and mass transferinteraction with the control volume later, as an add-oncomponent. The basic balance equation of a controlvolume with two connectors is implemented as

dM_x = a.mdot_x + b.mdot_x + rM;dU = a.q_conv + b.q_conv + Q_s;

This means that rM and Q_s, corresponding to thesource terms in (3) should be unspecified in the gen-eral base class, and then specified at a later stage whenthe balance class is reused in the model of a specificcomponent. When there are no reactions or heat inter-action with the volume there is no need for any sourceterms. In this case the model should provide a defaultvalue of zero production.

1.2 The HeatAndMassObject, a gateway tothe balances

The contradiction of leaving the option open to spec-ify production terms but not having to add a defaultvalue of zero can be handled with open flow connec-tors. In Modelica, all quantities which are flows aremarked with the flow-prefix. Flow variables obeythe zero-sum rule (Kirchhoffs’ current law) and havein unconnected connectors a zero default value. Sincethese connectors should be internal to the volume,

they need to be attached to an object inside the vol-ume model. This is the HeatAndMassObject,seeFigure 1, which acts as a gateway between the bal-ance equations and possible heat- and mass transferobjects. External connectors can also be connected tothe HeatAndMassObject.

Interfaces

The HeatAndMassObject interact with other ob-jects through a number of different connectors. Thecurrently implemented connectors include the Heat-Flow connector for pure heat interaction (conduc-tion/radiation), the ChemFlow connector for chemi-cal reactions, both kinetic and equilibrium, and a con-nector for membrane diffusion.

connector HeatFlowparameter Integer n;Temperature[n] T;flow Power[n] q;

end HeatFlow;

connector ChemFlowparameter Integer n, nc;parameter String MediumType;Temperature[n] T;Pressure[n] p;Concentration[n,nc] conc;flow MolarFlowRate[n,nc] rZ;flow Power[n] q;

end ChemFlow

The diffusion connector is similar to the ChemFlowconnector but has mass flow rate instead of molar flowrate since this is standard for diffusion.The flow semantics of Modelica for the molar flow rZand the heat flow q make sure that all contributionsto the mass- and energy balances are correctly takeninto account, no matter whether there are zero, oneor many connections to the HeatAndMassObject, seeFigure 1. Inside the HeatAndMassObject the con-tributions from the different connectors are summedup and transferred to the balance equations in the vol-ume.

1.3 Objects for encapsulating reactions

To be able to drag and drop reaction models into a vol-ume model (a reactor), they are encapsulated in reac-tion objects. As shown in the code example below, theBasic reaction inherits interfaces and basic parame-ters from the reaction BaseObject.

Page 5: Chemical Reaction Modeling with ThermoFluid/MF and

Tummescheit H., Eborn J. Chemical Reaction Modeling with ThermoFluid/MF and MultiFlash

The Modelica Association 33 Modelica 2002, March 18−19, 2002

package Reactions

partial model BaseObjectparameter Integer n, nc, nr;MolarReactionRate[n,nr] reacRate;Enthalpy[nc] compHf;parameter StoichiometricNumber[nr,nc]

stoich=zeros(nr,nc);equation

for i in 1:n loopr.rZ[i,:] =

transpose(stoich)*reacRate[i,:];end for;

end BaseObject;

model Basic "Simple Arrhenius reaction"extends BaseObject;parameter Rate[nr] A0;parameter Real[nr] b;parameter MolarInternalEnergy[nr] Ea;Concentration[n,nc] conc;

equationfor i in 1:n loop

reacRate[i,:] = ...;r.q[i] = -compHf*r.rZ[i,:];

end for;end Basic;

end Reactions;

The reaction rates are calculated from standard Arrhe-nius expressions using the concentrations and the pa-rameters. To use the reaction component, like in thekinetic reaction in Figure 1, the user simply needs tospecify the parameters. The stoichiometry matrix isconstructed as shown in Table 1 and the heat of forma-tion parameters are added from the medium model.To construct models of other types of reactions the re-action BaseObject can be reused. The customizedreaction model needs to give expressions for the reac-tion rates, either by adding equations or by calling arate function. In this way packages of reactions can be

H � O2 � OH � OOH � O � H � O2

O � H2 � OH � HH2O � H � H2 � OHH2 � OH � H2O � HH2O � O � 2 OH2 H � Ar � H2 � Ar2 O � Ar � O2 � Ar

�O2 H2 H2O O H OH Ar ������������

� 1 0 0 1 � 1 1 01 0 0 � 1 1 � 1 00 � 1 0 � 1 1 1 00 1 � 1 0 � 1 1 00 � 1 1 0 1 � 1 00 0 � 1 � 1 0 2 00 1 0 0 � 2 0 01 0 0 � 2 0 0 0

�����������

Table 1: Reactions included in the H2 O2 reaction sys-tem and the corresponding stoichiometric matrix.

Figure 2: Schematic of example system with H2–O2

reaction.

built and reactions can graphically be added to stan-dard reactor models.

1.4 Example, combustion of hydrogen

As an example, we consider the combustion of hydro-gen and oxygen into water. In a simple setting, seeFigure 2, the system consists of a reservoir supplyingthe reactants, a reactor volume and a sink for the prod-uct flow. A heat source is added to provide the heatnecessary to ignite the mixture.The complete set of sub-reactions for this process in-volves a large number ( 40) of very fast reactions,see [12]. Here we only consider the 8 main reactions,involving the components � O2, H2, H2O, O, H, OH,Ar � . Argon is included as an inert gas. The includedreactions are listed in Table 1. The corresponding sto-ichiometry matrix and reaction rate parameters havebeen coded into a Basic reaction object inside theGasCV reaction vessel.The result plots show clearly that the reactions are ex-tremely fast once they started. They saturate whenall H2 is burned up and the flow through the volumereaches steady state. The mass flows in Figure 3 showa violent explosion when the mixture ignites. After the

0 1 2 3 4 5

x 10−3

−2.5

−2

−1.5

−1

−0.5

0

0.5

1

1.5

2

2.5

Time [s]

Mas

sflo

w [k

g/s]

outflowinflow

Figure 3: Mass flows into and out of the control vol-ume during the ignition phase

Page 6: Chemical Reaction Modeling with ThermoFluid/MF and

Chemical Reaction Modeling with ThermoFluid/MF and MultiFlash Tummescheit H., Eborn J.

Modelica 2002, March 18−19, 2002 34 The Modelica Association

0 1 2 3 4 5

x 10−3

0

0.5

1

Time [s]

Mol

efra

ctio

n [1

]

mole fraction of H2

mole fraction of O2

mole fraction of H20

Figure 4: Molar fractions of the principal reactants andproducts

initial ignition, a steady inflow of premixed gases leadsto a steady combustion with plenty of surplus oxygen.The speed of the reactions makes the system very stiff.The whole simulation shown in Figures 4-3 spans onlya few milliseconds.

2 The MultiFlash interface

MultiFlash is the generic name for a physical prop-erty software from Infochem Ltd. It is a comprehen-sive system that calculates the thermophysical proper-ties of pure substances and mixtures and carries outphase and chemical equilibrium calculations for fluidand solid phases. MultiFlash consists of several soft-ware modules: databases with the raw property data,access software to the databases and different mod-ules for pure component property calculation, mix-ture models for thermodynamic properties and trans-port properties, handling of binary interaction parame-ters and phase and chemical equilibrium calculations.A number of process simulators, e. g., gPROMS fromPSE, uses an interface to MultiFlash for the calculationof physical properties. For use in a dynamic simulationprogram typically only a small fraction of the Multi-Flash functions are needed. The current interface iskept as simple as possible, with all necessary interac-tion with the property database encapsulated into onemedium property object. The interface has been testedwith both Dymola by Dynasim AB [4] and MathMod-elica by MathCore AB [6].

2.1 The low-level interface

The low-level interface between Modelica models andthe MultiFlash modules, which are accessible via a

Win32 Dynamic Link Library (dll) under Windows,consists of the standard Modelica foreign function in-terface for the C-language. This means that all callsto MultiFlash routines are provided exactly as docu-mented in the MultiFlash programmers guide, includ-ing identical variable names. There are two minor,but necessary exceptions. Modelica does not allow tooverwrite inputs with outputs in the calling of func-tions. This is common practice in Fortran numericalroutines and in MultiFlash this is exclusively used toprovide estimates of the solutions in the input vari-ables. In the Modelica interface, the estimated solu-tions are provided as additional input arguments to thefunction and the original MultiFlash variables are keptas outputs. The second exception is the handling of er-ror message strings. The handling of errors and warn-ings is done in the C wrapper functions. Diagnosticmessages are written to the simulation log. A flag withthe number of errors is returned in the Modelica func-tion call for error trapping purposes.

2.2 Computational efficiency

Simulation time is an important issue and the inter-face library uses all available methods to make func-tion calls computationally efficient. A simple rule isto get as many physical properties as possible fromone call to MultiFlash. All essential medium prop-erties needed for the default dynamic model are avail-able in one property record which is calculated withone single function call to MultiFlash. The dynamicstate model and other ThermoFluid models need ev-erything in this standard property record, so it is com-putationally not efficient to slim down this functioncall. Boolean flags to the MultiFlash routines are usedto ensure that only the medium properties of interestare calculated. High level functions that return onlya single property have not been implemented in orderto close the door on unnecessarily slow models. How-ever, all low-level MultiFlash functions are availableand thus single function calls to obtain properties canbe used if it is desired.

Providing good estimates of the solution makes a bigdifference in the solution time for any nonlinear sys-tem of equations, especially for phase equilibrium cal-culations. It is obvious that for continuous, dynamicsimulation the result from the last time step usuallyprovides such an estimate. Internal caching of the lastsolution in the same control volume is therefore im-plemented in the THERMOFLUID/MF MultiFlash in-terface.

Page 7: Chemical Reaction Modeling with ThermoFluid/MF and

Tummescheit H., Eborn J. Chemical Reaction Modeling with ThermoFluid/MF and MultiFlash

The Modelica Association 35 Modelica 2002, March 18−19, 2002

2.3 Using MultiFlash with ThermoFluid/MF

Setting up a model that uses MultiFlash properties iscurrently done through the MultiFlash windows userinterface. The user selects the wanted components byquerying the available MultiFlash databases. For com-plex systems, the MultiFlash stream facility is used todefine different component streams to be used in dif-ferent parts of the system. The global stream whichhas to be defined first contains the union of the com-ponents in all streams. If necessary, the thermody-namic models can be changed from the default sug-gested by MultiFlash through the graphical user inter-face. All standard equations-of-state (EOS) models,e. g., Redlich-Kwong-Soave or Peng-Robinson, can beused with a selection of mixing rules. Binary inter-action parameters can be entered if needed. Trans-port property models are selected independently of theEOS models. The problem setup is saved in an mfl-file which is then read and parsed during initialization.The file name is the main parameter to the mediummodels in the THERMOFLUID/MF library. Problemsetup files are read from the current directory or froma repository, where all problem setup definitions canbe managed in a centralized way.

2.4 Dynamic state equations

The most efficient method of combining the dynamicstates and the physical property calculation is tochoose the dynamic states of the model such that theyare inputs to the physical property calculation routines.That avoids the solution of non-linear equation sys-tems during simulation. Otherwise, inputs to the prop-erty functions have to be computed from outputs ofthat functions through a non-linear equation system.This happens when the outputs are dynamic states ortime-invariant parameters, like the volume in a closedvessel. If the property functions are computationallyexpensive relative to the rest of the model, the savingin computation time by using a model which is ex-plicit in the states is significant. When this can not beachieved, as is the case with the MultiFlash routines, itis still preferable to get non-linear equation systems ofthe lowest possible dimension. Due to the MF call-ing structure with pressure p, temperature T and N(mole amounts) as inputs and total volume V as out-put a special state model has been defined. It is incor-porated in the free THERMOFLUID library and can beused interchangeably with the simple ideal gas modelsin the free THERMOFLUID library and the commer-cial MultiFlash property models. The state model uses

temperature T and mole amounts N as dynamic states,while p can be regarded as an algebraic variable thatcontains state information. For the standard case of aconstant volume control volume, the pressure is solvedfor iteratively to ensure that the total volume is keptconstant, Vfixed � V � p � . This is the only non-linearequation system in the model for single phase calcu-lations. The dynamic state model is derived from thestandard text-book form of an energy and mass bal-ances. In block matrix notation, the inner energy andmole amount balance can be recast into temperatureand moles as dynamic states as follows (boldface forvectors and matrices, sizes follow from dimension ofN, the number of components in the mixture.):��

NtUtVt

�� � ��I 0 0

dUdN T �V dU

dT N �V dUdV N � T

0 0 1

�� � �NtTtVt

��(4)

The subscript t is used for the time derivative,N standsfor mole amounts, U for total inner energy. The in-verse of the jacobian is used to make this model ex-plicit in the mole vector, the temperature and the vol-ume as dynamic states:

� 1

�1

dUdT N �V

��I 0 0

dUdN T �V �

dUdT N �V �

dUdV N � T

0 0 1

��(5)

The structure of the jacobian inverse reveals that onlythe equation for the inner energy is transformed intoone for the temperature. The mole balance equationsremain unchanged from (4).The partial derivatives occuring in the transformed dy-namic and initial equations can be calculated fromderivatives that are returned by MultiFlash by settingthe appropriate flags. However, the derivatives must betransformed using thermodynamic determinants sinceMultiFlash returns derivatives at constant pressure andthe THERMOFLUID balances are derived at constantvolume. As an example we pick the derivative of to-tal enthalpy w. r. t. temperature (all derivatives are atconstant composition):

∂H∂T

����V

�∂H∂T

����p

∂H∂V

����T

�∂H∂T

����p

� � ∂H � ∂p � T∂V � ∂p � T � (6)

All derivatives on the right hand side of the equationare returned by standard MultiFlash property calls.

Page 8: Chemical Reaction Modeling with ThermoFluid/MF and

Chemical Reaction Modeling with ThermoFluid/MF and MultiFlash Tummescheit H., Eborn J.

Modelica 2002, March 18−19, 2002 36 The Modelica Association

2.5 Initialization

In the Modelica 2.0 specification and Dymola version4.2 the possibility to separate the equations for steadystate initialization from the dynamic states was intro-duced. Due to that separation, a control volume cannow easily be initialized at steady state pressure, evenwhen the pressure is not a dynamic state. In complexflow sheets, the calculation of an initial steady state isusually numerically much more challenging than thesubsequent dynamic simulation. A helpful way aroundthat problem is to use a suitable “pseudo steady state”instead which avoids harsh initial transients. One pos-sibility to do so is to use steady state initialization onlyfor the states with relatively fast eigenvalues. Settingthe pressure gradient to zero, but supplying initial es-timates for temperature and composition is one suchsuitable choice of a “pseudo steady state”. The fastmodes of the system (pressure and, if a dynamic mo-mentum balance is used, mass flows) are initialized insteady state, while the much slower modes of tempera-ture and composition are set by a non-steady state ini-tial guess. The pressure gradient becomes:

dpdt

� dpdT

����N

dTdt

� n

∑i � 1

dpdNi

����T

dNidt

� 0 � (7)

This equation together with given initial compositionand temperature is much easier to solve than a fullsteady state, especially for large networks, but the ini-tial transients due to errors in the initial guesses areorders of magnitude smaller than the ones obtainedfrom non steady state pressures. The new initializationmethod has been implemented for all state models inthe THERMOFLUID and THERMOFLUID/MF librariesand has improved the handling of model initializa-tion considerably. Before implementation of the im-proved initialization, computation time for small prob-lems was dominated by the time to simulate past theinitial transients. With that obstacle removed, typi-cal simulation times for small systems are an order ofmagnitude faster than before.This initialization is the default setup when the THER-MOFLUID/MF high-level models are used. The initialstate is defined by given temperature and mass frac-tions and an initial pressure estimate. The initializa-tion then solves for the mole amount states.

2.6 Debugging

In order to improve feedback and error messages fordebugging, an identifier for each control volume isallocated during the initialization of the model. The

identifier is passed to the wrapper functions calling theMultiFlash property routines. Using the unique con-trol volume identifier, it is possible to connect error-and warning messages from the MultiFlash routines tothe location in the flow sheet where the error occured,e. g., if a temperature rises above the range of validityof the property function. All error and warning mes-sages from MultiFlash are written to the Dymola sim-ulation log. Information about the version, the config-uration, the number and composition of streams etc. isalso included in the log.

2.7 ThermoFluid/MF high level models

Modeling of process engineering problems can notbe cast into fixed, unchangeable model library com-ponents as for example multibody systems. Insteadflexibility is needed to have basic building blocks tak-ing care of the standard parts of any dynamic model.These basic models need to be easy to adapt to a spe-cific problem. A large part of the physical propertycalculations is identical for all modeling problems.The THERMOFLUID/MF library provides such basicmodels and building blocks for control volume modelsbased on MultiFlash properties. Extensions are sim-ple to add by using elements of the THERMOFLUID

or THERMOFLUID/MF libraries. Some examples oflumped and distributed models demonstrate how tobuild components and larger systems from the build-ing blocks in the library. A mixture which is typical forfuel cell reformer systems is used to demonstrate howthe minmimal physical property model is used and alsohow to add transport properties. Transport propertiesare not included in the THERMOFLUID library exceptfor water, but MultiFlash includes several models forviscosity, thermal conductivity and surface tension forpure components and mixtures.

Figure 5: Example models from the library.

Page 9: Chemical Reaction Modeling with ThermoFluid/MF and

Tummescheit H., Eborn J. Chemical Reaction Modeling with ThermoFluid/MF and MultiFlash

The Modelica Association 37 Modelica 2002, March 18−19, 2002

The number of high level models in the THER-MOFLUID/MF library is fairly small, because moststandard models can be used from the THERMOFLUID

library. The only base models that are differentare control volume models. For flash models newflash control volumes are introduced. They determinewhich phase is flowing in or out at a connector fromthe position of the flow connector and the liquid levelin the volume. Tray models for destillation columnswill be added later.

2 4 6 8 10 12Time

0.05

0.06

0.07

0.08

Liq

uid

Phas

eFr

actio

n

2 4 6 8 10 12Time

350

355

360

365

370

Tem

pera

ture

Figure 6: Change of temperature and liquid phase frac-tion in a water-ehtanol mix during a pressure transient.

The simulation result from the depressurization ofa flash volume filled with a water-ethanol mixturein thermodynamic equilibrium of the two phases isshown in Figure 6. A ramp from 1 bar to 0 � 5 barsis imposed on the volume which has a feed flow ofconstant composition. The jump in the liquid phasefraction at the start and end of the transient is due tothe changing in- and outflow phase fractions.Using MultiFlash properties with the THER-MOFLUID/MF library is very simple and requiresonly few steps of setup:

� Define the components, phases and models to beused in the MultiFlash user interface and save theresult in a model setup file.

� Define a THERMOFLUID-compatible propertymodel, following the examples in the THER-MOFLUID/MF library.

� Use that property model in a suitble control vol-ume model from the THERMOFLUID/MF library.

3 Crossing Functions for multi-component multi-phase mixtures

In Modelica, crossing functions are usually automat-ically generated from all equations that contain state-ments which indicate that a function f � x � is discontin-uous at a certain point x0. For example, in the follow-ing equation:

phase = if h < hliq or h > hvap or p > pcrit then 1 else 2;

three crossing functions are introduced to monitor thestates of the boolean conditions. This is necessary be-cause numerical integration routines assume continu-ity of their right-hand side functions. This assumptionis violated in most if-clauses. This can not be auto-mated for external functions that are discontinuous ata point x0. Thus crossing functions have to be pro-vided by the user in order to make the simulator de-tect the discontinuity. These crossing functions have tobe consistent with the actual discontinuities, otherwisethey will not work. In the context of phase equilib-rium calculations for multi-component fluid mixturesthis means that a unique function of composition, pres-sure and temperature � N � p � T � must be returned fromthe phase equilibrium calculations which has a signchange at the point where a new phase is formed or onephase ceases to exist. At a phase boundary thermo-dynamic variables have discontinuous first derivativesor are discontinuous by itself, like the heat capacityat constant volume cv. For a mixture with n compo-nents the crossing function is a function ℜ

�n � 1 � � � ℜ.

It calculates a measure for the distance to the phaseboundary surface which is in ℜn.

3.1 Deviation index

Collaboration with Infochem Ltd. [5] brought forthan implementation of such a function to increase ef-ficiency and reliability of phase equilibrium calcula-tions in dynamic simulations. It is available in thelatest release of MultiFlash, version 3.1. This is thefirst time that a multi-phase property package has beenequiped with this feature, which is indispensable forbeing able to reliably simulate the formation or dis-appearance of phases in a control volume with high

Page 10: Chemical Reaction Modeling with ThermoFluid/MF and

Chemical Reaction Modeling with ThermoFluid/MF and MultiFlash Tummescheit H., Eborn J.

Modelica 2002, March 18−19, 2002 38 The Modelica Association

quality integrators with event detection and error con-trol. Infochem calls the new function the deviationindex. The calculation of the deviation index is nu-merically much more efficient than other possibilitiesto determine the number of phases at a given � N � p � T �during dynamic simulation. Geometrically, the devia-tion index can be interpreted as a normalized length ofthe normal vector from the current point in the spacespanned by composition, pressure and temperature tothe n-dimensional tangent hyperplane to the phase sep-aration surface. The tangent plane is also known asGibbs' tangent plane. It has been used for stabilityanalysis in phase equilibrium calculations before, see[8], [9] and [1]. The new feature is to assign a value tothe distance from the hyperplane which allows a solverusing interpolation to exactly locate the point in timewhen the simulation trajectory in the N � p � T - spacewill pass through the hyperplane. At equilibrium, theGibbs energy of the system is at a minimum. Thiscondition may be expressed as the equality of fugac-ities for each component in all phases or equivalently([1]) as

ln � Ki j ��ln � Fi j � � ln � Firi � � 0 i � 1 � � nc; j � 1 � � np

(8)where nc is the number of components, np is the num-ber of phases, Ki j is the K-value for component i inphase j, Fi j is the fugacity coefficent for component iin phase j and ri is the the reference phase for compo-nent i. The K-values are defined as

Ki j � yi jyiri

(9)

where yi j is the mole fraction of component i in phasej. In the vicinity of the phase split surface, the lefthand side of (8) gives the value of the desired crossingfunction, the deviation index.Furthermore, the function needs to reliably calculatethe properties used in equation (8) of a phase whichis unstable at the current � N � p � T � . Considering forsimplicity single component mixtures and the calcu-lation of thermodynamic properties for a phase whichis unstable inside the 2-phase dome (i. e., superheatedliquid or subcooled vapour), it becomes clear that thenumerical computation is only possible to the limit ofthe so called spinoidal lines. For simple cubic EOSthe spinoidal lines are defined by the connection linesof the maxima and minima of the theorectical isother-mes inside the two-phase dome. An implementationthus has to guard against erroneous results far fromthe phase boundary.

4 Conclusions

The inclusion of reaction calculations and the inter-face to the physical property database MultiFlash intothe THERMOFLUID library opens new possibilities ofmodeling process systems and combustion processeswhich up to now have been blocked by the large ini-tial investment in modeling work to set up the physicalproperty calculation.The general reaction, diffusion and heat transfer objectprovides a clean and unified way of encapsulating sub-models for heat and mass transfer. Base classes neverneed to be changed no matter how many connectionsto the control volume exist. Standard reactions can bestored in component libraries and used with any re-actor model that has a compatible medium propertymodel. Membrane diffusion uses the same mechanismto couple into the standard dynamical equations.The THERMOFLUID/MF library provides two sets ofmodels: low level models which are one-to-one wrap-pers to the MultiFlash physical property routines andhigh level base models for multi-component liquid-gastwo phase models. Care has been taken to make thetime consuming VLE-calculations as efficient as pos-sible and at the same time numerically robust.Crossing functions for multi-phase, multi-componentmixtures have been implemented in collaboration withInfochem Ltd. They allow a numerically robust detec-tion of the formation of new phases in a multi phasemixture.

References

[1] J. F. Counsell, R. A. S. Moorwood, andR. Szczepanski. Caclulating Multiphase Equilib-ria. In Proceedings of the Conference on Vapour-Liquid Equilibria, Aston, 1990.

[2] Jonas Eborn. On Model Libraries for Thermo-hydraulic Applications. PhD thesis, Departmentof Automatic Control, Lund Institute of Technol-ogy, Lund, Sweden, March 2001.

[3] Rüdiger Franke. Formulation of dynamic opti-mization problems using modelica. In Martin Ot-ter, Hilding Elmqvist, and Peter Fritzson, editors,Proceedings of the International Modelica Con-ference 2002. Modelica Association and DLR,March 2002.

[4] http://www.dynasim.se.

[5] http://www.infochemuk.com.

Page 11: Chemical Reaction Modeling with ThermoFluid/MF and

Tummescheit H., Eborn J. Chemical Reaction Modeling with ThermoFluid/MF and MultiFlash

The Modelica Association 39 Modelica 2002, March 18−19, 2002

[6] http://www.mathcore.com.

[7] Jakob Munch Jensen and HubertusTummescheit. Moving Boundary Modelsfor Dynamic Simulations of Two-Phase Flows.In Martin Otter, Hilding Elmqvist, and PeterFritzson, editors, Proceedings of the Interna-tional Modelica Conference 2002. ModelicaAssociation and DLR, March 2002.

[8] M. L. Michelsen. The isothermal flash problem.I. Stability analysis. Fluid Phase Equilibria, 9:1–19, 1982.

[9] M. L. Michelsen. The isothermal flash problem.II. Phase-split calculation. Fluid Phase Equilib-ria, 9:21–40, 1982.

[10] Torge Pfafferot and G. Schmitz. NumerischeSimulation von CO2-Kühlprozessen mit Model-ica. InDKV-Tagungsbericht 2001, volume IV 28.Jahrgang. DKV, Stuttgart, 2001.

[11] Hubertus Tummescheit, Jonas Eborn, and FalkoWagner. Development of a Modelica base li-brary for modeling of thermo-hydraulic systems.In Modelica 2000 Workshop Proceedings, pages41–51, Lund, October 2000. Modelica Associa-tion.

[12] Stephen R. Turns. An Introduction to Combus-tion. McGraw Hill International Editions, 1993.