ASCEND/C2/Solving-Cubic-EOS/English

From Script | Spoken-Tutorial
Jump to: navigation, search

Tutorial 4: Cubic EOS: Peng Robinson


Visual Cue
Narration
Show Slide number 1

Title slide

Welcome to the spoken tutorial on Solving Cubic Equation Of State in ASCEND
Show Slide 2 In this tutorial, we will learn how to
  • Create a reusable model
  • Reuse the model for different components
  • Import data from the Thermodynamics library
  • Solve the model
Show Slide number 3

System Requirement

Here I am using
  • Ubuntu Linux OS v. 12.04
  • ASCEND v. 0.9.8
Show Slide number 4

Pre-requisites

To follow this tutorial, user must have basic knowledge of
  • Linux
  • ASCEND and
  • Peng Robinson cubic Equation Of State
Show Slide number 5

Pre-requisites

To know more about ASCEND, please visit ascend4.org


For relevant tutorials please visit our website http://spoken-tutorial.org

Show Slide number 6

Peng Robinson Cubic EOS

Let’s write a general model to solve Peng Robinson cubic equation of state.


Peng Robinson equation of state is a cubic equation of state which contains volume terms to the third power.


It is usually expressed to give pressure in terms of temperature and molar volume.


These are the equations for Peng Robinson equation of state

Show Slide number 7

Peng Robinson Cubic EOS

It is sometimes more convenient to express the polynomial in terms of the compressibility factor Z.


These are the equations which we will be using in our model to compute the value of Z.

Let's now look at the code for Peng Robinson model.


I already have the code for Peng Robinson model in a text file.

Open the code file in gedit Open the file Peng Robinson.a4c in a text editor.


Let me explain the code.

Highlight REQUIRE "thermodynamics.a4l"; For solving this model, we require data from the thermodynamics library.

So, add REQUIRE “thermodynamics.a4l”.

Highlight the lines sequentially I have named this model as pengrobinson.


After this, we define variables like P, T, V etc. using WILL underscore BE operator.


WILL_BE operator is used to make our model reusable.

The variables defined using WILL_BE are used as parameters in our test model


I will come back to the explanation of WILL_BE as we move ahead in our tutorial.

Highlight the following declaration statements

R IS_A molar_gas_constant;

Pc IS_A pressure;

Tc IS_A temperature;

T_degC IS_A factor;

alpha, beta, q,Tr, Pr, omega IS_A factor;

PSI, OMEGA, sigma, eps IS_A real_constant;

Now we define rest of the variables accordingly. Like, R IS_A molar gas constant, Pc IS_A pressure and so on,


Note that factor denotes a dimensionless variable, Thus alpha, beta, q etc. are defined as a factor

Highlight the given constants used in the code

PSI :== 0.45724;

OMEGA :== 0.07780;

sigma :== 2.414213562;

eps :== 0.414213562;

Now we mention the values of all the constants used in Peng Robinson equation of state.

Please note that the values of these constants will be reused in our test model.

So we use a colon and is equal to sign twice, to assign values to constants
Highlight the following syntax

Pc = data.Pc;

Tc = data.Tc;

omega = data.omega;

Tr = T/Tc;

Pr = P/Pc;

T_degC = T/1{K} - 273.15;

We take the critical temperature, critical pressure and omega data from the thermodynamics library.


And so we define

  • Pc=data.Pc
  • Tc=data.Tc
  • and so on.
Highlight the lines Now we define the reduced temperature and reduced pressure" in terms of Tc and Pc.


Highlight the lines Now we mention the Peng Robinson equation as shown in the previous slide


Note that labels like eq 4, eq 5 etc. are not compulsory to write but they help in debugging the problem.

Highlight the line Now let’s define methods to solve this model.
Highlight the line We use the method default to solve this model and run the METHOD specify and METHOD values under it.
Highlight the line Under specify we fix the variables by writing , P.fixed := TRUE;and T.fixed := TRUE;
Highlight the line Note that
  • True implies fixed variables
  • whereas all other variables which are not mentioned here
  • are, by default, set to False, i.e. free variables
Highlight the line Now under values, we define values to the fixed variables.

For Z, we set the upper and lower bound and also provide a nominal value to initiate the solution.

Highlight the line The syntax used is
  • Z.lower_bound := 0.0;
  • Z.nominal := 0.1;
Highlight the line Now we end Peng Robinson model.
Highlight the line Parameters defined in this model, can now be reused by any model to calculate Z for specific components.
Highlight the line Let's now see how to use these parameters and calculate Z for ethylene in a test model.

Let's now look at the code for test model.

Highlight the line Note that the test model is written below the Peng Robinson model in the same document.

We name this model as test

We define a symbol constantc1.

And assign c1 is equal to ethylene.

Highlight the line We use a colon and equal to sign twice as this c1 is passed as a parameter to another variable components underscore data, which is present in thermodynamics library.

Here we define cd as components_data of ethylene.

Highlight the line Note that
  • in the parenthesis, c1 in square bracket implies fetch data for ethylene from thermodynamics library
  • whereas c1 outside square bracket is set as reference component.


More on this will be explained in future tutorials.

Highlight the line Note that we used WILL_BE to define P,V,Z etc
Highlight the line To reuse these parameters from previous model, we need to define them here using IS_A operator

Thus we define

  • P IS_A pressure;
  • T IS_A temperature and so on
Highlight the line We define tpeng IS_A pengrobinson.


Now tpeng includes all the equations and methods defined in the peng robinson model.

Highlight the line We have passed the required parameters to the pengrobinson model in parenthesis.


So we don't have to write the equations and variables again.

Highlight the line The values of constants and other variables will be called in the test model from peng robinson model.


This is how we make our model reusable.

Highlight the line We define equations for Tr and Pr as
  • Tr = T/cd.data[c1].Tc; *and similarly for Pr;


Highlight the line

cd.date c1.Tc imports the value of Tc for ethylene from thermodynamics library.

Highlight the line

In METHODS, we define the standard methods again.

But now

  • under method specify, we run tpeng.specify
  • under method values, we run tpeng.values
Highlight the line This is done to run the methods from pengrobinson model in our test model.


Highlight the line In the end, we define the METHOD on_load in which we run specify and values.

Now end the test model.

Open the model in ASCEND and run the on_load method Open this model in ASCEND.
Point as per narration Under Modules section, you will see two names

peng robinsing and test model

Point as per narration In the panel below you will see the message


'won’t auto-initiate the model peng robinson


model requires parameters'

Point as per narration As we have used WILL_BE in peng robinson, we can’t execute this model.


But the parameters defined here, will be executed in our test model.

Point as per narration Now double click on test.

The model opens under Simulation.

Point as per narration Now run the on_load method and click on Solve
Point as per narration You will see pressure, temperature are the fixed variables.


And ASCEND has successfully calculated values for z, volume, reduced Temperature and reduced Pressure

Open Slide number 8

Summary

Now, let us summarize. In this tutorial, we have learnt how to:
  • Create a reusable model
  • Reuse the model for different components
  • Import data from the Thermodynamics library
  • Solve the model


Open Slide number 9

Assignment

As an assignment, try to modify pengrobinson model to solve the value of V.

Also re-use this model in a test model, to compute value of V for ethylene.

Open Slide number 10

About the Spoken Tutorial Project

Information on the spoken tutorial project is available on our website

spoken-tutorial.org

Open Slide number 11

Spoken Tutorial Workshops

Details on Workshops based on spoken tutorials is also available on the website
Open Slide number 12

Acknowledgements

Spoken tutorial project is funded by NMEICT,MHRD



Open Slide number 13

Thank You

This is Priya Bagde from IIT Bombay signing off

Thank You for joining

Contributors and Content Editors

Gaurav, Nancyvarkey, Tarung