Chemical Components

For our last example of component-oriented modelling, we’ll return to the Chemical System we discussed in the chapter on Vectors and Arrays. However, this time we will create component models for the various effects and show how connections in Modelica automatically ensure the conservation of species.


The species we will be dealing with in this example are defined by the following enumeration:

within ModelicaByExample.Components.ChemicalReactions.ABX;
type Species = enumeration(A, B, X);

Note that this definition exists within a package called ABX. This indicates that the component models are designed to work with this three species system involving AB and X.


Also contained in the ABX package is the following connector definition (which can be found in the Interfaces sub-package):

within ModelicaByExample.Components.ChemicalReactions.ABX.Interfaces;
connector Mixture
  Modelica.SIunits.Concentration C[Species];
  flow ConcentrationRate R[Species];
end Mixture;

Here we see that our Mixture connector uses concentrations as the across variables and a concentration rate as the flow variable. Although the flow variable, in this case, is not strictly the flow of a conserved quantity, it will suffice in this example since all reactions are contained within the same volume.

Note that both C and R in this connector are arrays where the subscript is given by an enumeration type. We saw earlier how Enumerations can be used in this way.


Our first component model is used to track the concentration of the various chemical species within a control volume. As alluded to earlier, since all reactions occur within the same volume, we don’t need to actually specify the size of the control volume.

The Solution model is quite simple. Like the Regional Population the model discussed earlier in this chapter, the rate of change of the across variable associated with its sole connector is equal to the flow variable on that same connector:

within ModelicaByExample.Components.ChemicalReactions.ABX.Components;
model Solution "A mixture of species A, B and X"
  Interfaces.Mixture mixture
  Modelica.SIunits.Concentration C[Species]=mixture.C
  der(mixture.C) = mixture.R;
end Solution;



As we saw previously, this system has three reactions. Each of the specific reactions we’ll examine extend from the following partial model:

within ModelicaByExample.Components.ChemicalReactions.ABX.Interfaces;
partial model Reaction "A reaction potentially involving species A, B and X"
  parameter Real k "Reaction coefficient";
  Mixture mixture
  ConcentrationRate consumed[Species];
  ConcentrationRate produced[Species];
  Modelica.SIunits.Concentration C[Species] = mixture.C;
  consumed = -produced;
  mixture.R = consumed;
end Reaction;

We see that each reaction has a reaction coefficient, k, and a Mixture connector, mixture, that ultimately connects it to the Solution where the reaction is to take place. The internal vector variables consumed and produced play a role that is similar to the decline and growth variables in the SinkOrSource discussed earlier in this chapter (i.e., they allow us to write contributions from individual reactions using an intuitive terminology).


The first complete reaction model we will consider is the one that turns one molecule of A and one molecule of B into one molecule of X. Using the Reactionmodel, we can model this reaction as follows:

model 'A+B->X' "A+B -> X"
  extends Interfaces.Reaction;
  Interfaces.ConcentrationRate R = k*C[Species.A]*C[Species.B];
  consumed[Species.A] = R;
  consumed[Species.B] = R;
  produced[Species.X] = R;
end 'A+B->X';

The first thing to note about this model is that it is composed of non-alphanumeric characters. Specifically, the name of this model contains +- and >. This is permitted in Modelica as long as the name is quoted using single quote characters. The rate of the reaction, R, is used in conjunction with the consumed and produced variables inherited from the Reaction model to create equations that clearly describe both the reactants and the products in this reaction.


The next reaction we will consider is one that takes one molecule of X and transforms it (back) into one molecule of A and one molecule of B. This is the reverse of the previous reaction. The Modelica code for this reaction would be:

model 'A+B<-X' "A+B <- X"
  extends Interfaces.Reaction;
  Interfaces.ConcentrationRate R = k*C[Species.X];
  produced[Species.A] = R;
  produced[Species.B] = R;
  consumed[Species.X] = R;
end 'A+B<-X';

Again, the equations convey clearly which species are reactants (i.e., are consumed in the reaction) and which are the products (i.e., those species that are produced in the reaction).


Finally, our last reaction converts molecules of X and B into molecules of R and S:

model 'X+B->R+S' "X+B->R+S"
  extends Interfaces.Reaction;
  Interfaces.ConcentrationRate R = k*C[Species.B]*C[Species.X];
  consumed[Species.A] = 0;
  consumed[Species.B] = R;
  consumed[Species.X] = R;
end 'X+B->R+S';

We do not track the concentration of the R and S species since they are simply byproducts and do not participate in any other reactions. This model follows the same familiar pattern as before with the exception that the A species is not involved.


We can combine the Solution model along with the various reaction models as follows:

within ModelicaByExample.Components.ChemicalReactions.Examples;
model ABX_System "Model of simple two reaction system"
  ABX.Components.Solution solution(C(each fixed=true, start={1,1,0}))
  ABX.Components.'A+B->X' 'A+B->X'(k=0.1)
  ABX.Components.'A+B<-X' 'A+B<-X'(k=0.1)
  ABX.Components.'X+B->R+S' 'X+B->R+S'(k=10)
  connect('A+B<-X'.mixture, solution.mixture) annotation...
  connect('X+B->R+S'.mixture, solution.mixture) annotation...
  connect('A+B->X'.mixture, solution.mixture) annotation...
end ABX_System;

Note how modifications to the solution component are used to set the initial concentration of species within the solution component. Also, the reaction coefficients are specified via modifications to each of the reaction components. Finally, each of the reaction components is attached to the solution.mixtureconnector.

Simulating this system for 10 seconds yields the following concentration trajectories:


From our earlier discussion of this chemical system, you may recall that the resulting system of equations was:

Each equation represents the accumulation of a particular species and each term on the right-hand side of those equations is computing the net flow of that particular species into the control volume. Constructing this system by hand for even a relatively small number of participating species is rife with opportunities to introduce errors. By using a component-oriented approach instead, we never had to assemble such a system of equations. As a result, these equations were generated automatically. By automating this process, we can avoid many potential errors and the time required to identify and fix them.

Pure-component System

Let us start with a well-known single component system: water — the most plentiful substance on earth. What is the behaviour of water under different conditions of pressure and temperature? Or even more specific, is there a single answer to the question: what is the boiling point of water? Most people would say, “of course, 100 °C”, but a more accurate response would pose a clarifying question: “At what pressure?” It is common knowledge that water boils at 100 °C (212 °F) at atmospheric pressure. By requiring a pressure specification in order to uniquely define the boiling point of water, we are acknowledging that the boiling temperature of a pure substance is pressure-dependent. In reality, we are also implicitly applying a very useful thermodynamic principle, the Gibbs Rule, but this will be the topic for later discussion.

In thermodynamics, we refer to the Normal Boiling Point as the boiling temperature of a fluid at 1 atm of pressure (that is, atmospheric pressure.) Therefore, 100 °C (212 °F) is the normal boiling point of water.

What if we want to communicate this idea? We would like to communicate the concept that the temperature at which water boils varies with pressure. What about a picture to represent this information? Here is our first phase diagram, Figure 2.1. Whereas several sentences may be required to describe the variability of the boiling point of water, the single line shown in Figure 2.1 is adequate. What does Figure 2.1 tell us? It tells us that the boiling temperature of a liquid increases as pressure increases. In other words, it says that the vapour pressure of a liquid increase as temperature increases. That is to be expected because as the temperature increases, more liquid molecules are able to escape into the vapour phase, thus increasing the pressure that the aggregate of all vapour molecules exerts on the system (i.e. vapour pressure).

See text above image

Figure 2.1: Vapor pressure curve for a pure substance

The curve in Figure 2.1 is called the vapor pressure curve or boiling point curve. The line also represents the dew point curve and the bubble point curve; one on top of the other. This curve represents the transition between the vapour and liquid states.

Definition of Basic Terms

Vapour Pressure: The pressure that the vapour phase of a fluid exerts over its own liquid at equilibrium at a given temperature.

Dew Point: The pressure and temperature condition at which an infinitesimal quantity of liquid (a droplet) exists in equilibrium with vapour. It represents the condition of incipient liquid formation in an initially gaseous system. Notice that it can be also visualized as a “liquid system” where all but an infinitesimal quantity of liquid has been vaporized.

Bubble Point: The pressure and temperature condition at which the system is all liquid, and in equilibrium with an infinitesimal quantity (a bubble) of gas. This situation is, in essence, the opposite of that of the dew point.


For single-component systems, one single curve represents all three of these conditions (vapour pressure, dew point and bubble point conditions) simply because of Vapor Pressure = Dew Point = Bubble Point for unary systems.

In Figure 2.1, once a saturation pressure has been selected, there is one (and only one) saturation temperature associated with it. This is only true for a single component system. In other words, this is the only temperature (at the given pressure), at which the liquid and gas phase will co-exist in equilibrium. The rule that governs the uniqueness of this point, for a single-component system, is called the Gibbs Phase Rule. This is the second time we have mentioned this rule, pointing to its great importance in phase behaviour. Let us postpone any detailed discussion of the Gibbs Phase Rule until later.

see text below image

Figure 2.2: Complete P-T diagram for pure-component systems

The vapor curve, shown in Figure 2.1, represents the transition between the vapor and liquid states for a pure component. Obviously, this is not the whole story. If we cool the liquid system, it makes sense to expect ice to form (a solid phase). We can communicate this new idea by adding more information to Figure 2.1. In fact, there is a line that defines the liquid-solid transition; it is called the solidification (or melting) curve (see Figure 2.2). Furthermore, even though it is counter-intuitive, it is possible to go from solid to vapour without going through a liquid state, if the pressure is low enough. This information can be added to the diagram by including the sublimation curve. Thus, Figure 2.2 represents a more complete phase diagram for a pure-component system.

See how more and more information can be represented within the limits of the phase diagram. As petroleum and natural gas engineers, we focus our attention on the Boiling Point Curve, as it represents the transition between liquid and gas, the phases with which we deal most often. Let us focus our attention on it.

Figure 2.3 presents a P-T diagram representing the vapour pressure curve and its extremities. Two very important thermodynamic points bound the vapour pressure curve: the Critical Point at its upper end and the Triple Point at its lower end.

See text above image

Figure 2.3: Vapor pressure curve and the triple and critical points

The Triple Point is the meeting point of the vapour pressure, solidification and sublimation curves (see Figure 2.2); hence, it represents the only condition at which all three phases of a pure substance (solid, liquid and gas) can co-exist in equilibrium.

At the Critical Point, gas and liquid are in equilibrium without any interface to differentiate them; they are no longer distinguishable in terms of their properties. As we recall, the only location on the P-T diagram where liquid and gas can be found together in equilibrium is along the vapour pressure curve. Hence, the critical point is clearly the maximum value of temperature and pressure at which liquid and vapour can be at equilibrium. This maximum temperature is called the critical temperature (Tc); the corresponding maximum pressure is called the critical pressure (Pc).

Let us conclude this first module by highlighting the most important properties of the critical point of pure substances, as shown below. The next module will be providing more details of interest that are embedded in Figure 2.3.

Properties Of The Critical Point (Tc,Pc) (For Pure Substances):

    1. Temperature and pressure for which liquid and vapour are no longer distinguishable.
    2. For T > Tc, liquid and vapour will not co-exist, no matter what the pressure is.
    3. For P > Pc, liquid and vapour will not co-exist, no matter what the temperature is.



Welcome to FAWE

STEM Elearning

We at FAWE have built this platform to aid learners, trainers and mentors get practical help with content, an interactive platform and tools to power their teaching and learning of STEM subjects, more

How to find your voice as a woman in Africa

© FAWE, Powered by: Yaaka DN.