source: branches/gui/eml/stage_separators/column.mso @ 781

Last change on this file since 781 was 781, checked in by gerson bicca, 13 years ago

updated column/tank model

File size: 111.8 KB
Line 
1#*-------------------------------------------------------------------
2* EMSO Model Library (EML) Copyright (C) 2004 - 2007 ALSOC.
3*
4* This LIBRARY is free software; you can distribute it and/or modify
5* it under the therms of the ALSOC FREE LICENSE as available at
6* http://www.enq.ufrgs.br/alsoc.
7*
8* EMSO Copyright (C) 2004 - 2007 ALSOC, original code
9* from http://www.rps.eng.br Copyright (C) 2002-2004.
10* All rights reserved.
11*
12* EMSO is distributed under the therms of the ALSOC LICENSE as
13* available at http://www.enq.ufrgs.br/alsoc.
14*
15*----------------------------------------------------------------------
16* File containg models of columns: distillation, stripping, absorbers
17* rectifier, ....
18*
19* The default nomenclature is:
20*               Type_Column_reboilertype_condensertyper
21*
22* where:
23*       Type = refluxed or reboiled or section
24*       Column = Stripping, Absorption, Rectifier, Distillation
25*       Reboiler type (if exists) = kettle or thermosyphon
26*       Condenser type (if exists) = with subccoling or without subcooling
27*
28*-----------------------------------------------------------------------
29* Author: Paula B. Staudt
30* $Id: column.mso 511 2008-05-12 17:25:33Z paula $
31*---------------------------------------------------------------------*#
32
33using "tray";
34using "reboiler";
35using "condenser";
36using "mixers_splitters/splitter";
37using "tank";
38using "pressure_changers/pump";
39
40Model ControlSection
41
42ATTRIBUTES
43        Pallete = false;
44        Brief = "Control variables for column section.";
45
46PARAMETERS
47        outer NComp             as Integer      (Brief="Number of components");
48
49        Tindicator_TrayNumber   as Integer      (Brief="Temperature Indicator in the tray");
50        Pindicator_TrayNumber   as Integer      (Brief="Pressure Indicator in the tray");
51
52end
53
54Model InitializeSection
55
56ATTRIBUTES
57        Pallete = false;
58        Brief = "Initial conditions for column section.";
59
60PARAMETERS
61        outer NComp             as Integer      (Brief="Number of components");
62
63        TopTemperature          as temperature  (Brief = "Tray Temperature at Column Top", Default = 300);
64        BottomTemperature       as temperature  (Brief = "Tray Temperature at Column Bottom", Default = 330);
65        LevelFraction           as fraction             (Brief = "Tray Level Fraction", Default = 0.5);
66
67        TopComposition(NComp)           as fraction     (Brief = "Component Molar Fraction at Column Top", Default = 0.30);
68        BottomComposition(NComp)        as fraction     (Brief = "Component Molar Fraction at Column Bottom", Default = 0.30);
69
70end
71
72Model InitializeStage
73
74ATTRIBUTES
75        Pallete = false;
76        Brief = "Initial conditions for Packed column section.";
77
78PARAMETERS
79        outer NComp             as Integer      (Brief="Number of components");
80
81        TopStageTemperature             as temperature  (Brief = "Tray Temperature at Column Top", Default = 300);
82        BottomStageTemperature          as temperature  (Brief = "Tray Temperature at Column Bottom", Default = 300);
83       
84        TopStageComposition(NComp)              as fraction     (Brief = "Component Molar Fraction at Top");
85        BottomStageComposition(NComp)   as fraction     (Brief = "Component Molar Fraction at Bottom");
86        LiquidMolarHoldup                               as mol          (Brief="Molar liquid holdup", Default=0.01);
87
88end
89
90Model Section_ColumnBasic
91
92ATTRIBUTES
93        Pallete         = false;
94        Brief   = "Model of a basic column section.";
95        Info            =
96"Model of a basic column section containing a vetor of TRAYS numbered from the top-down.";
97
98PARAMETERS
99        outer PP                                                        as Plugin                       (Brief="External Physical Properties", Type="PP");
100        outer NComp                                     as Integer              (Brief="Number of components");
101#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
102# Section Column Feed Tray - Side Streams  Location and Numbering
103#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
104        NumberOfTrays                                           as Integer                      (Brief="Number of trays", Default=8);
105        LiqSideTrayIndex(NumberOfTrays)         as Integer                      (Brief="Liquid Side Tray Index", Default=0,Hidden=true);
106        VapSideTrayIndex(NumberOfTrays)         as Integer                      (Brief="Vapour Side Tray Index", Default=0,Hidden=true);
107        FeedTrayTopLocation                                     as Integer                      (Brief="Top Feed tray Location", Default=2);
108        FeedTrayBottomLocation                                  as Integer                      (Brief="Bottom Feed tray Location", Default=3);
109        LiquidSideStreamLocation                        as Integer                      (Brief="Liquid Side Stream Location", Default=2);
110        VapourSideStreamLocation                        as Integer                      (Brief="Vapour Side Stream Location", Default=2);
111        g                                                                       as acceleration         (Brief="Gravity Acceleration",Default=9.81,Hidden=true);
112        Mw(NComp)                                                       as molweight            (Brief="Component Mol Weight",Hidden=true);
113#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
114# Section Column Flow Model for Liquid and Vapour
115#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
116        VapourFlowModel         as Switcher     (Valid = ["Reepmeyer", "Feehery_Fv", "Roffel_Fv", "Klingberg", "Wang_Fv", "Elgue"], Default = "Reepmeyer");
117        LiquidFlowModel         as Switcher     (Valid = ["default", "Wang_Fl", "Olsen", "Feehery_Fl", "Roffel_Fl"], Default = "default");
118#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
119# Section Column Tray Geometry and Auxiliar Parameters
120#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
121        VolumeOfTray            as volume               (Brief="Total Volume of the tray");
122        HeatSupply                      as heat_rate    (Brief="Rate of heat supply");
123        PlateArea                       as area                 (Brief="Plate area = Atray - Adowncomer");
124        HolesArea                       as area                 (Brief="Total holes area");
125        WeirLength                      as length               (Brief="Weir length");
126        WeirHeight                      as length               (Brief="Weir height");
127        FeeheryCoeff            as Real                 (Brief="Feeherys correlation coefficient", Unit='1/m^4', Default=1);
128        ElgueCoeff                      as Real                 (Brief="Elgues correlation coefficient", Unit='kg/m/mol^2', Default=1);
129        OlsenCoeff                      as Real                 (Brief="Olsens correlation coefficient", Default=1);
130        TrayLiquidPasses        as Real                 (Brief="Number of liquid passes in the tray", Default=1);
131       
132        V                               as volume               (Brief="Total Volume of the tray",Hidden=true);
133        Q                               as heat_rate    (Brief="Rate of heat supply",Hidden=true);
134        Ap                              as area                 (Brief="Plate area = Atray - Adowncomer",Hidden=true);
135        Ah                              as area                 (Brief="Total holes area",Hidden=true);
136        lw                              as length               (Brief="Weir length",Hidden=true);
137        hw                              as length               (Brief="Weir height",Hidden=true);
138        beta                    as fraction     (Brief="Aeration fraction");
139        alfa                    as fraction     (Brief="Dry pressure drop coefficient");
140        w                               as Real                 (Brief="Feeherys correlation coefficient", Unit='1/m^4', Default=1,Hidden=true);
141        btray                   as Real                 (Brief="Elgues correlation coefficient", Unit='kg/m/mol^2', Default=1,Hidden=true);
142        fw                              as Real                 (Brief="Olsens correlation coefficient", Default=1,Hidden=true);
143        Np                              as Real                 (Brief="Number of liquid passes in the tray", Default=1,Hidden=true);
144
145        VapourFlow      as Switcher     (Valid = ["on", "off"], Default = "on",Hidden=true);
146        LiquidFlow      as Switcher     (Valid = ["on", "off"], Default = "on",Hidden=true);
147
148SET
149        VapSideTrayIndex(VapourSideStreamLocation) =1;
150        LiqSideTrayIndex(LiquidSideStreamLocation) =1;
151        Mw = PP.MolecularWeight();
152
153        V=VolumeOfTray;
154        Q=HeatSupply;
155        Ap=PlateArea;
156        Ah=HolesArea;
157        lw=WeirLength;
158        hw=WeirHeight ;
159        w=FeeheryCoeff;
160        btray=ElgueCoeff;
161        fw=OlsenCoeff;
162        Np=TrayLiquidPasses;
163
164VARIABLES
165#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
166# Tray Initialization For the Whole Column Section
167#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
168        INITIALIZATION as InitializeSection (Brief = "Column Model Initialization");
169#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
170# Control Ports
171#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
172        CONTROL as ControlSection (Brief = "Control");
173        out     TCI as control_signal   (Brief="Temperature  Indicator", Protected = true, PosX=1, PosY=0.73);
174        out     PCI as control_signal   (Brief="Pressure Indicator", Protected = true, PosX=0, PosY=0.24);
175#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
176# Column Feed - Side Stream Flow and Murphree Efficiency
177#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++             
178        in      FeedTrayTop                             as stream               (Brief="Feed stream", PosX=0, PosY=0.45);
179        in      FeedTrayBottom                  as stream               (Brief="Feed stream", PosX=0, PosY=0.65);
180       
181                TRAYS(NumberOfTrays)    as tray                 (Brief="Number of trays in the Column Section");
182                VapourDrawOffFlow               as flow_mol     (Brief="Vapour Draw Off Stream Molar Flow Rate");
183                LiquidDrawOffFlow               as flow_mol     (Brief="Vapour Draw Off Stream Molar Flow Rate");
184                MurphreeEff                     as Real                 (Brief="Murphree efficiency for All Trays",Lower=0.01,Upper=1);
185
186CONNECTIONS
187#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
188# Connecting Intermediate Trays
189#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
190        TRAYS([2:NumberOfTrays]).OutletVapour   to TRAYS([1:NumberOfTrays-1]).InletVapour;
191        TRAYS([1:NumberOfTrays-1]).OutletLiquid         to TRAYS([2:NumberOfTrays]).InletLiquid;
192       
193INITIAL
194#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
195# Tray Initialization
196#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
197for i in 1:NumberOfTrays do
198
199"The initial temperature of the TRAYS"
200        TRAYS(i).OutletLiquid.T = INITIALIZATION.TopTemperature+(INITIALIZATION.BottomTemperature-INITIALIZATION.TopTemperature)*((i-1)/(NumberOfTrays-1));
201
202"The initial Level of the TRAYS"
203        TRAYS(i).Level = INITIALIZATION.LevelFraction*hw;
204end
205
206for i in 1:NComp-1 do
207
208for j in 1:NumberOfTrays do
209
210"The initial composition of the TRAYS - Normalized"
211        TRAYS(j).OutletLiquid.z(i) = INITIALIZATION.TopComposition(i)/sum(INITIALIZATION.TopComposition) +(INITIALIZATION.BottomComposition(i)/sum(INITIALIZATION.BottomComposition)-INITIALIZATION.TopComposition(i)/sum(INITIALIZATION.TopComposition) )*((j-1)/(NumberOfTrays-1));
212end
213
214end
215
216EQUATIONS
217#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
218# Control Ports
219#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
220
221"Tray Temperature Indicator"   
222        #TCI*'K' = TRAYS(min([NumberOfTrays, CONTROL.Tindicator_TrayNumber])).OutletVapour.T;
223        TCI*'K' = TRAYS(CONTROL.Tindicator_TrayNumber).OutletVapour.T;
224
225"Tray Pressure Indicator"       
226        #PCI*'atm' = TRAYS(min([NumberOfTrays, CONTROL.Pindicator_TrayNumber])).OutletVapour.P;
227        PCI*'atm' = TRAYS(CONTROL.Pindicator_TrayNumber).OutletVapour.P;
228
229#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
230# Equating Feed Trays Variables to Trays Variables
231#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
232
233for i in 1:NumberOfTrays do
234
235if   i equal FeedTrayTopLocation then   
236
237"FeedTrayTop Inlet Flow"       
238        FeedTrayTop.F= TRAYS(i).Inlet.F;
239
240"FeedTrayTop Inlet Temperature"
241        FeedTrayTop.T = TRAYS(i).Inlet.T;
242
243"FeedTrayTop Inlet Pressure"
244        FeedTrayTop.P = TRAYS(i).Inlet.P;
245
246"FeedTrayTop Inlet Composition"
247        FeedTrayTop.z = TRAYS(i).Inlet.z;
248
249"FeedTrayTop Inlet Vapour Fraction"
250        FeedTrayTop.v = TRAYS(i).Inlet.v;
251
252"FeedTrayTop Inlet Enthalpy"
253        FeedTrayTop.h = TRAYS(i).Inlet.h;
254
255else if   i equal FeedTrayBottomLocation then   
256
257"FeedTrayBottom Inlet Flow"     
258        FeedTrayBottom.F= TRAYS(i).Inlet.F;
259
260"FeedTrayBottom Inlet Temperature"
261        FeedTrayBottom.T = TRAYS(i).Inlet.T;
262
263"FeedTrayBottom Inlet Pressure"
264        FeedTrayBottom.P = TRAYS(i).Inlet.P;
265
266"FeedTrayBottom Inlet Composition"
267        FeedTrayBottom.z = TRAYS(i).Inlet.z;
268
269"FeedTrayBottom Inlet Vapour Fraction"
270        FeedTrayBottom.v = TRAYS(i).Inlet.v;
271
272"FeedTrayBottom Inlet Enthalpy"
273        FeedTrayBottom.h = TRAYS(i).Inlet.h;
274
275else
276
277"Inlet Tray - Flow Sealed"     
278        0*'mol/h'= TRAYS(i).Inlet.F;
279
280"Inlet Tray -  Temperature"
281        FeedTrayBottom.T = TRAYS(i).Inlet.T;
282
283"Inlet Tray -  Pressure"
284        FeedTrayBottom.P = TRAYS(i).Inlet.P;
285
286"Inlet Tray -  Composition"
287        FeedTrayBottom.z = TRAYS(i).Inlet.z;
288
289"Inlet Tray -  Vapour Fraction"
290        FeedTrayBottom.v = TRAYS(i).Inlet.v;
291
292"Inlet Tray -  Enthalpy"
293        FeedTrayBottom.h = TRAYS(i).Inlet.h;
294
295end
296
297end
298
299end
300
301#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
302# Trays Equations
303#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
304
305for i in [1:NumberOfTrays] do
306
307"Murphree Efficiency"
308        TRAYS(i).OutletVapour.z =  MurphreeEff * (TRAYS(i).yideal - TRAYS(i).InletVapour.z) + TRAYS(i).InletVapour.z;
309
310"Level of clear liquid over the weir"
311        TRAYS(i).Level = TRAYS(i).ML*TRAYS(i).vL/Ap;
312
313"Geometry Constraint"
314        V = TRAYS(i).ML* TRAYS(i).vL + TRAYS(i).MV*TRAYS(i).vV;
315
316"Energy Holdup"
317        TRAYS(i).E = TRAYS(i).ML*TRAYS(i).OutletLiquid.h + TRAYS(i).MV*TRAYS(i).OutletVapour.h - TRAYS(i).OutletLiquid.P*V;
318
319"Energy Balance"
320        diff(TRAYS(i).E) = ( TRAYS(i).Inlet.F*TRAYS(i).Inlet.h + TRAYS(i).InletLiquid.F*TRAYS(i).InletLiquid.h + TRAYS(i).InletVapour.F*TRAYS(i).InletVapour.h- TRAYS(i).OutletLiquid.F*TRAYS(i).OutletLiquid.h - TRAYS(i).OutletVapour.F*TRAYS(i).OutletVapour.h
321        -TRAYS(i).VapourSideStream.F*TRAYS(i).VapourSideStream.h - TRAYS(i).LiquidSideStream.F*TRAYS(i).LiquidSideStream.h + Q );
322
323switch LiquidFlow
324                case "on":
325                        switch LiquidFlowModel
326                                case "default":
327                                "Francis Equation"
328                                TRAYS(i).OutletLiquid.F*TRAYS(i).vL = 1.84*'1/s'*lw*((TRAYS(i).Level-(beta*hw))/(beta))^2;
329                       
330                                case "Wang_Fl":
331                                TRAYS(i).OutletLiquid.F*TRAYS(i).vL = 1.84*'m^0.5/s'*lw*((TRAYS(i).Level-(beta*hw))/(beta))^1.5;
332                       
333                                case "Olsen":
334                                TRAYS(i).OutletLiquid.F / 'mol/s'= lw*Np*TRAYS(i).rhoL/sum(Mw*TRAYS(i).OutletVapour.z)/(0.665*fw)^1.5 * ((TRAYS(i).ML*sum(Mw*TRAYS(i).OutletLiquid.z)/TRAYS(i).rhoL/Ap)-hw)^1.5 * 'm^0.5/mol';
335                       
336                                case "Feehery_Fl":
337                                TRAYS(i).OutletLiquid.F = lw*TRAYS(i).rhoL/sum(Mw*TRAYS(i).OutletLiquid.z) * ((TRAYS(i).Level-hw)/750/'mm')^1.5 * 'm^2/s';
338                       
339                                case "Roffel_Fl":
340                                TRAYS(i).OutletLiquid.F = 2/3*TRAYS(i).rhoL/sum(Mw*TRAYS(i).OutletLiquid.z)*lw*(TRAYS(i).ML*sum(Mw*TRAYS(i).OutletLiquid.z)/(Ap*1.3)/TRAYS(i).rhoL)^1.5*sqrt(2*g/
341                                                        (2*(1 - 0.3593/'Pa^0.0888545'*abs(TRAYS(i).OutletVapour.F*sum(Mw*TRAYS(i).OutletVapour.z)/(Ap*1.3)/sqrt(TRAYS(i).rhoV))^0.177709)-1)); #/'(kg/m)^0.0888545/s^0.177709';
342                        end
343                when TRAYS(i).Level < (beta *hw) switchto "off";
344               
345                case "off":
346                "Low level"
347                TRAYS(i).OutletLiquid.F = 0 * 'mol/h';
348                when TRAYS(i).Level > (beta * hw) + 1e-6*'m' switchto "on";
349        end
350       
351switch VapourFlow
352                case "on":
353                        switch VapourFlowModel
354                                case "Reepmeyer":
355                                TRAYS(i).InletVapour.F*TRAYS(i).vV = sqrt((TRAYS(i).InletVapour.P - TRAYS(i).OutletVapour.P)/(TRAYS(i).rhoV*alfa))*Ah;
356                       
357                                case "Feehery_Fv":
358                                TRAYS(i).InletVapour.F = TRAYS(i).rhoV/Ap/w/sum(Mw*TRAYS(i).OutletVapour.z) * sqrt(((TRAYS(i).InletVapour.P - TRAYS(i).OutletVapour.P)-(TRAYS(i).rhoV*g*TRAYS(i).ML*TRAYS(i).vL/Ap))/TRAYS(i).rhoV);
359                       
360                                case "Roffel_Fv":
361                                TRAYS(i).InletVapour.F^1.08 * 0.0013 * 'kg/m/mol^1.08/s^0.92*1e5' = (TRAYS(i).InletVapour.P - TRAYS(i).OutletVapour.P)*1e5 - (beta*sum(TRAYS(i).M*Mw)/(Ap*1.3)*g*1e5) * (TRAYS(i).rhoV*Ah/sum(Mw*TRAYS(i).OutletVapour.z))^1.08 * 'm^1.08/mol^1.08';
362                       
363                                case "Klingberg":
364                                TRAYS(i).InletVapour.F * TRAYS(i).vV = Ap * sqrt(((TRAYS(i).InletVapour.P - TRAYS(i).OutletVapour.P)-TRAYS(i).rhoL*g*TRAYS(i).Level)/TRAYS(i).rhoV);
365                       
366                                case "Wang_Fv":
367                                TRAYS(i).InletVapour.F * TRAYS(i).vV = Ap * sqrt(((TRAYS(i).InletVapour.P - TRAYS(i).OutletVapour.P)-TRAYS(i).rhoL*g*TRAYS(i).Level)/TRAYS(i).rhoV*alfa);
368                               
369                                case "Elgue":
370                                TRAYS(i).InletVapour.F  = sqrt((TRAYS(i).InletVapour.P - TRAYS(i).OutletVapour.P)/btray);
371                        end
372                when TRAYS(i).InletVapour.F < 1e-6 * 'kmol/h' switchto "off";
373               
374                case "off":
375                TRAYS(i).InletVapour.F = 0 * 'mol/s';
376                when TRAYS(i).InletVapour.P > TRAYS(i).OutletVapour.P + TRAYS(i).Level*g*TRAYS(i).rhoL + 1e-1 * 'atm' switchto "on";
377        end
378
379end
380
381end
382
383
384Model Section_Column
385
386ATTRIBUTES
387        Pallete         = true;
388        Icon            = "icon/SectionColumn";
389        Brief   = "Model of a column section.";
390        Info            =
391"== Model of a column section containing ==
392* NumberOfTrays TRAYS.
393       
394== Specify ==
395* the feed stream of each tray (Inlet);
396* the Murphree eficiency for each tray Emv;
397* the InletLiquid stream of the top tray;
398* the InletVapour stream of the bottom tray.
399       
400== Initial Conditions ==
401* the TRAYS temperature (OutletLiquid.T);
402* the TRAYS liquid level (Level) OR the TRAYS liquid flow (OutletLiquid.F);
403* (NoComps - 1) OutletLiquid (OR OutletVapour) compositions for each tray.
404";
405
406PARAMETERS
407        outer PP                                                        as Plugin                       (Brief="External Physical Properties", Type="PP");
408        outer NComp                                             as Integer                      (Brief="Number of components");
409#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
410# Section Column Feed Tray - Side Streams  Location and Numbering
411#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
412        NumberOfTrays                                           as Integer                      (Brief="Number of trays", Default=8);
413        FeedTrayIndex(NumberOfTrays)            as Integer                      (Brief="Feed Tray Index", Default=0,Hidden=true);
414        LiqSideTrayIndex(NumberOfTrays)         as Integer                      (Brief="Liquid Side Tray Index", Default=0,Hidden=true);
415        VapSideTrayIndex(NumberOfTrays)         as Integer                      (Brief="Vapour Side Tray Index", Default=0,Hidden=true);
416        FeedTrayLocation                                        as Integer                      (Brief="Feed tray Location", Default=2);
417        LiquidSideStreamLocation                        as Integer                      (Brief="Liquid Side Stream Location", Default=2);
418        VapourSideStreamLocation                        as Integer                      (Brief="Vapour Side Stream Location", Default=2);
419        g                                                                       as acceleration         (Brief="Gravity Acceleration",Default=9.81,Hidden=true);
420        Mw(NComp)                                                       as molweight            (Brief="Component Mol Weight",Hidden=true);
421#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
422# Section Column Flow Model for Liquid and Vapour
423#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
424        VapourFlowModel         as Switcher     (Valid = ["Reepmeyer", "Feehery_Fv", "Roffel_Fv", "Klingberg", "Wang_Fv", "Elgue"], Default = "Reepmeyer");
425        LiquidFlowModel         as Switcher     (Valid = ["default", "Wang_Fl", "Olsen", "Feehery_Fl", "Roffel_Fl"], Default = "default");
426#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
427# Section Column Tray Geometry and Auxiliar Parameters
428#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
429        VolumeOfTray            as volume               (Brief="Total Volume of the tray");
430        HeatSupply                      as heat_rate    (Brief="Rate of heat supply");
431        PlateArea                       as area                 (Brief="Plate area = Atray - Adowncomer");
432        HolesArea                       as area                 (Brief="Total holes area");
433        WeirLength                      as length               (Brief="Weir length");
434        WeirHeight                      as length               (Brief="Weir height");
435        FeeheryCoeff            as Real                 (Brief="Feeherys correlation coefficient", Unit='1/m^4', Default=1);
436        ElgueCoeff                      as Real                 (Brief="Elgues correlation coefficient", Unit='kg/m/mol^2', Default=1);
437        OlsenCoeff                      as Real                 (Brief="Olsens correlation coefficient", Default=1);
438        TrayLiquidPasses        as Real                 (Brief="Number of liquid passes in the tray", Default=1);
439       
440        V                               as volume               (Brief="Total Volume of the tray",Hidden=true);
441        Q                               as heat_rate    (Brief="Rate of heat supply",Hidden=true);
442        Ap                              as area                 (Brief="Plate area = Atray - Adowncomer",Hidden=true);
443        Ah                              as area                 (Brief="Total holes area",Hidden=true);
444        lw                              as length               (Brief="Weir length",Hidden=true);
445        hw                              as length               (Brief="Weir height",Hidden=true);
446        beta                    as fraction     (Brief="Aeration fraction");
447        alfa                    as fraction     (Brief="Dry pressure drop coefficient");
448        w                               as Real                 (Brief="Feeherys correlation coefficient", Unit='1/m^4', Default=1,Hidden=true);
449        btray                   as Real                 (Brief="Elgues correlation coefficient", Unit='kg/m/mol^2', Default=1,Hidden=true);
450        fw                              as Real                 (Brief="Olsens correlation coefficient", Default=1,Hidden=true);
451        Np                              as Real                 (Brief="Number of liquid passes in the tray", Default=1,Hidden=true);
452       
453        VapourFlow      as Switcher     (Valid = ["on", "off"], Default = "on",Hidden=true);
454        LiquidFlow      as Switcher     (Valid = ["on", "off"], Default = "on",Hidden=true);
455
456SET
457        FeedTrayIndex(FeedTrayLocation) =1;
458        VapSideTrayIndex(FeedTrayLocation) =1;
459        LiqSideTrayIndex(FeedTrayLocation) =1;
460        Mw = PP.MolecularWeight();
461
462        V=VolumeOfTray;
463        Q=HeatSupply;
464        Ap=PlateArea;
465        Ah=HolesArea;
466        lw=WeirLength;
467        hw=WeirHeight ;
468        w=FeeheryCoeff;
469        btray=ElgueCoeff;
470        fw=OlsenCoeff;
471        Np=TrayLiquidPasses;
472
473VARIABLES
474#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
475# Tray Initialization For the Whole Column Section
476#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
477        INITIALIZATION as InitializeSection (Brief = "Column Model Initialization");
478#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
479# Control Ports
480#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
481        CONTROL as ControlSection (Brief = "Control");
482        out     TCI as control_signal   (Brief="Temperature  Indicator", Protected = true, PosX=1, PosY=0.90);
483        out     PCI as control_signal   (Brief="Pressure Indicator", Protected = true, PosX=1, PosY=0.80);
484#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
485# Section Inlet Liquid and Outlet Vapour Material Ports
486#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
487        in      LiquidInlet             as      stream                  (Brief="Liquid Inlet in the section", PosX=0.70, PosY=0);
488        out     VapourOutlet    as vapour_stream        (Brief="Vapour Outlet in the section", PosX=0.30, PosY=0);
489       
490        out     VapourDrawOff   as vapour_stream        (Brief="Vapour Draw Off Port in the section", PosX=1, PosY=0.35,Protected = true);
491        out     LiquidDrawOff   as liquid_stream        (Brief="Liquid Draw Off Port in the section", PosX=1, PosY=0.65,Protected = true);
492#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
493# Column Feed - Side Stream Flow and Murphree Efficiency
494#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++             
495        in      FeedTray                                as stream               (Brief="Feed stream", PosX=0, PosY=0.55);
496                TRAYS(NumberOfTrays)    as tray                 (Brief="Number of trays in the Column Section");
497                VapourDrawOffFlow               as flow_mol     (Brief="Stream Molar Flow Rate");
498                LiquidDrawOffFlow               as flow_mol     (Brief="Stream Molar Flow Rate");
499                MurphreeEff                     as positive             (Brief="Murphree efficiency for All Trays");
500#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
501# Section Inlet Vapour and Outlet Liquid Material Ports
502#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
503        in      VapourInlet             as stream                       (Brief="Vapour Inlet in the section", PosX=0.30, PosY=1);
504        out     LiquidOutlet    as liquid_stream        (Brief="Liquid Outlet in the section", PosX=0.70, PosY=1);
505
506        LiquidConnector as stream       (Brief="Liquid connection in the middle TRAYS", PosX=0.75, PosY=1,Hidden=true);
507        VapourConnector as stream       (Brief="Vapour connection in the middle TRAYS", PosX=0.55, PosY=0,Hidden=true);
508
509CONNECTIONS
510#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
511# Connecting Intermediate Trays
512#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
513        TRAYS([2:NumberOfTrays]).OutletVapour   to TRAYS([1:NumberOfTrays-1]).InletVapour;
514        TRAYS([1:NumberOfTrays-1]).OutletLiquid         to TRAYS([2:NumberOfTrays]).InletLiquid;
515
516#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
517# Connecting Connectors
518#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
519        LiquidConnector to TRAYS(1).InletLiquid;
520        VapourConnector to TRAYS(NumberOfTrays).InletVapour;
521
522INITIAL
523#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
524# Tray Initialization
525#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
526for i in 1:NumberOfTrays do
527
528"The initial temperature of the TRAYS"
529        TRAYS(i).OutletLiquid.T = INITIALIZATION.TopTemperature+(INITIALIZATION.BottomTemperature-INITIALIZATION.TopTemperature)*((i-1)/(NumberOfTrays-1));
530
531"The initial Level of the TRAYS"
532        TRAYS(i).Level = INITIALIZATION.LevelFraction*hw;
533end
534
535for i in 1:NComp-1 do
536
537for j in 1:NumberOfTrays do
538
539"The initial composition of the TRAYS - Normalized"
540        TRAYS(j).OutletLiquid.z(i) = INITIALIZATION.TopComposition(i)/sum(INITIALIZATION.TopComposition) +(INITIALIZATION.BottomComposition(i)/sum(INITIALIZATION.BottomComposition)-INITIALIZATION.TopComposition(i)/sum(INITIALIZATION.TopComposition) )*((j-1)/(NumberOfTrays-1));
541end
542
543end
544
545EQUATIONS
546#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
547# Control Ports
548#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
549
550"Tray Temperature Indicator"   
551        #TCI*'K' = TRAYS(min([NumberOfTrays, CONTROL.Tindicator_TrayNumber])).OutletVapour.T;
552        TCI*'K' = TRAYS(CONTROL.Tindicator_TrayNumber).OutletVapour.T;
553
554"Tray Pressure Indicator"       
555        #PCI*'atm' = TRAYS(min([NumberOfTrays, CONTROL.Pindicator_TrayNumber])).OutletVapour.P;
556        PCI*'atm' = TRAYS(CONTROL.Pindicator_TrayNumber).OutletVapour.P;
557
558#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
559# Equating Feed Tray Variables to Trays Variables
560#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
561"Feed Tray Inlet Flow" 
562        FeedTray.F*FeedTrayIndex= TRAYS.Inlet.F;
563
564"Feed Tray Inlet Temperature"
565        FeedTray.T = TRAYS.Inlet.T;
566
567"Feed Tray Inlet Pressure"
568        FeedTray.P = TRAYS.Inlet.P;
569
570"Feed Tray Inlet Composition"
571        FeedTray.z = TRAYS.Inlet.z;
572
573"Feed Tray Inlet Vapour Fraction"
574        FeedTray.v = TRAYS.Inlet.v;
575
576"Feed Tray Inlet Enthalpy"
577        FeedTray.h = TRAYS.Inlet.h;
578
579#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
580# Trays Equations
581#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
582for i in [1:NumberOfTrays] do
583
584"Murphree Efficiency"
585        TRAYS(i).OutletVapour.z =  MurphreeEff * (TRAYS(i).yideal - TRAYS(i).InletVapour.z) + TRAYS(i).InletVapour.z;
586
587"Level of clear liquid over the weir"
588        TRAYS(i).Level = TRAYS(i).ML*TRAYS(i).vL/Ap;
589
590"Geometry Constraint"
591        V = TRAYS(i).ML* TRAYS(i).vL + TRAYS(i).MV*TRAYS(i).vV;
592
593"Energy Holdup"
594        TRAYS(i).E = TRAYS(i).ML*TRAYS(i).OutletLiquid.h + TRAYS(i).MV*TRAYS(i).OutletVapour.h - TRAYS(i).OutletLiquid.P*V;
595
596"Energy Balance"
597        diff(TRAYS(i).E) = ( TRAYS(i).Inlet.F*TRAYS(i).Inlet.h + TRAYS(i).InletLiquid.F*TRAYS(i).InletLiquid.h + TRAYS(i).InletVapour.F*TRAYS(i).InletVapour.h- TRAYS(i).OutletLiquid.F*TRAYS(i).OutletLiquid.h - TRAYS(i).OutletVapour.F*TRAYS(i).OutletVapour.h
598        -TRAYS(i).VapourSideStream.F*TRAYS(i).VapourSideStream.h - TRAYS(i).LiquidSideStream.F*TRAYS(i).LiquidSideStream.h + Q );
599
600switch LiquidFlow
601                case "on":
602                        switch LiquidFlowModel
603                                case "default":
604                                "Francis Equation"
605                                TRAYS(i).OutletLiquid.F*TRAYS(i).vL = 1.84*'1/s'*lw*((TRAYS(i).Level-(beta*hw))/(beta))^2;
606                       
607                                case "Wang_Fl":
608                                TRAYS(i).OutletLiquid.F*TRAYS(i).vL = 1.84*'m^0.5/s'*lw*((TRAYS(i).Level-(beta*hw))/(beta))^1.5;
609                       
610                                case "Olsen":
611                                TRAYS(i).OutletLiquid.F / 'mol/s'= lw*Np*TRAYS(i).rhoL/sum(Mw*TRAYS(i).OutletVapour.z)/(0.665*fw)^1.5 * ((TRAYS(i).ML*sum(Mw*TRAYS(i).OutletLiquid.z)/TRAYS(i).rhoL/Ap)-hw)^1.5 * 'm^0.5/mol';
612                       
613                                case "Feehery_Fl":
614                                TRAYS(i).OutletLiquid.F = lw*TRAYS(i).rhoL/sum(Mw*TRAYS(i).OutletLiquid.z) * ((TRAYS(i).Level-hw)/750/'mm')^1.5 * 'm^2/s';
615                       
616                                case "Roffel_Fl":
617                                TRAYS(i).OutletLiquid.F = 2/3*TRAYS(i).rhoL/sum(Mw*TRAYS(i).OutletLiquid.z)*lw*(TRAYS(i).ML*sum(Mw*TRAYS(i).OutletLiquid.z)/(Ap*1.3)/TRAYS(i).rhoL)^1.5*sqrt(2*g/
618                                                        (2*(1 - 0.3593/'Pa^0.0888545'*abs(TRAYS(i).OutletVapour.F*sum(Mw*TRAYS(i).OutletVapour.z)/(Ap*1.3)/sqrt(TRAYS(i).rhoV))^0.177709)-1)); #/'(kg/m)^0.0888545/s^0.177709';
619                        end
620                when TRAYS(i).Level < (beta *hw) switchto "off";
621               
622                case "off":
623                "Low level"
624                TRAYS(i).OutletLiquid.F = 0 * 'mol/h';
625                when TRAYS(i).Level > (beta * hw) + 1e-6*'m' switchto "on";
626        end
627       
628switch VapourFlow
629                case "on":
630                        switch VapourFlowModel
631                                case "Reepmeyer":
632                                TRAYS(i).InletVapour.F*TRAYS(i).vV = sqrt((TRAYS(i).InletVapour.P - TRAYS(i).OutletVapour.P)/(TRAYS(i).rhoV*alfa))*Ah;
633                       
634                                case "Feehery_Fv":
635                                TRAYS(i).InletVapour.F = TRAYS(i).rhoV/Ap/w/sum(Mw*TRAYS(i).OutletVapour.z) * sqrt(((TRAYS(i).InletVapour.P - TRAYS(i).OutletVapour.P)-(TRAYS(i).rhoV*g*TRAYS(i).ML*TRAYS(i).vL/Ap))/TRAYS(i).rhoV);
636                       
637                                case "Roffel_Fv":
638                                TRAYS(i).InletVapour.F^1.08 * 0.0013 * 'kg/m/mol^1.08/s^0.92*1e5' = (TRAYS(i).InletVapour.P - TRAYS(i).OutletVapour.P)*1e5 - (beta*sum(TRAYS(i).M*Mw)/(Ap*1.3)*g*1e5) * (TRAYS(i).rhoV*Ah/sum(Mw*TRAYS(i).OutletVapour.z))^1.08 * 'm^1.08/mol^1.08';
639                       
640                                case "Klingberg":
641                                TRAYS(i).InletVapour.F * TRAYS(i).vV = Ap * sqrt(((TRAYS(i).InletVapour.P - TRAYS(i).OutletVapour.P)-TRAYS(i).rhoL*g*TRAYS(i).Level)/TRAYS(i).rhoV);
642                       
643                                case "Wang_Fv":
644                                TRAYS(i).InletVapour.F * TRAYS(i).vV = Ap * sqrt(((TRAYS(i).InletVapour.P - TRAYS(i).OutletVapour.P)-TRAYS(i).rhoL*g*TRAYS(i).Level)/TRAYS(i).rhoV*alfa);
645                               
646                                case "Elgue":
647                                TRAYS(i).InletVapour.F  = sqrt((TRAYS(i).InletVapour.P - TRAYS(i).OutletVapour.P)/btray);
648                        end
649                when TRAYS(i).InletVapour.F < 1e-6 * 'kmol/h' switchto "off";
650               
651                case "off":
652                TRAYS(i).InletVapour.F = 0 * 'mol/s';
653                when TRAYS(i).InletVapour.P > TRAYS(i).OutletVapour.P + TRAYS(i).Level*g*TRAYS(i).rhoL + 1e-1 * 'atm' switchto "on";
654        end
655
656end
657
658#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
659# Equating Inlet Liquid Connector Variables
660#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
661"Liquid Inlet Flow"     
662        LiquidConnector.F = LiquidInlet.F;
663
664"Liquid Inlet Temperature"             
665        LiquidConnector.T = LiquidInlet.T;
666
667"Liquid Inlet Pressure"         
668        LiquidConnector.P = LiquidInlet.P;
669
670"Liquid Inlet Composition"             
671        LiquidConnector.z = LiquidInlet.z;
672
673"Liquid Inlet Vapour Fraction"         
674        LiquidConnector.v = LiquidInlet.v;
675
676"Liquid Inlet Enthalpy"         
677        LiquidConnector.h = LiquidInlet.h;
678#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
679# Equating Inlet Vapour Connector Variables
680#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
681"Vapour Inlet Flow"             
682        VapourConnector.F = VapourInlet.F;
683
684"Vapour Inlet Temperature"             
685        VapourConnector.T = VapourInlet.T;
686
687"Vapour Inlet Pressure"         
688        VapourConnector.P = VapourInlet.P;
689
690"Vapour Inlet Composition"             
691        VapourConnector.z = VapourInlet.z;
692
693"Vapour Inlet Vapour Fraction"         
694        VapourConnector.v = VapourInlet.v;
695
696"Vapour Inlet Enthalpy"         
697        VapourConnector.h = VapourInlet.h;
698#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
699# Equating Outlet Liquid Variables
700#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
701"Liquid Outlet Flow"   
702        LiquidOutlet.F = TRAYS(NumberOfTrays).OutletLiquid.F;
703
704"Liquid Outlet Temperature"     
705        LiquidOutlet.T = TRAYS(NumberOfTrays).OutletLiquid.T;
706
707"Liquid Outlet Pressure"       
708        LiquidOutlet.P = TRAYS(NumberOfTrays).OutletLiquid.P;
709
710"Liquid Outlet Composition"     
711        LiquidOutlet.z = TRAYS(NumberOfTrays).OutletLiquid.z;
712#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
713# Equating Outlet Vapour Variables
714#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
715"Vapour Outlet Flow"           
716        VapourOutlet.F = TRAYS(1).OutletVapour.F;
717
718"Vapour Outlet Temperature"             
719        VapourOutlet.T = TRAYS(1).OutletVapour.T;
720
721"Vapour Outlet Pressure"               
722        VapourOutlet.P = TRAYS(1).OutletVapour.P;
723
724"Vapour Outlet Composition"             
725        VapourOutlet.z = TRAYS(1).OutletVapour.z;
726#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
727# Equating Outlet Vapour Side Stream Variables
728#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
729"Vapour Draw Off Stream - Flow"         
730        VapourDrawOff.F*VapSideTrayIndex= TRAYS.VapourSideStream.F;
731
732"Vapour Draw Off Stream - Temperature"         
733        VapourDrawOff.T = TRAYS(VapourSideStreamLocation).VapourSideStream.T;
734
735"Vapour Draw Off Stream - Pressure"             
736        VapourDrawOff.P = TRAYS(VapourSideStreamLocation).VapourSideStream.P;
737
738"Vapour Draw Off Stream - Composition"         
739        VapourDrawOff.z = TRAYS(VapourSideStreamLocation).VapourSideStream.z;
740
741"Vapour Draw Off Stream"       
742        VapourDrawOffFlow = VapourDrawOff.F;
743#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
744# Equating Outlet Liquid Side Stream Variables
745#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
746"Liquid Draw Off Stream - Flow"         
747        LiquidDrawOff.F*LiqSideTrayIndex= TRAYS.LiquidSideStream.F;
748
749"Liquid Draw Off Stream - Temperature" 
750        LiquidDrawOff.T = TRAYS(LiquidSideStreamLocation).LiquidSideStream.T;
751
752"Liquid Draw Off Stream - Pressure"                     
753        LiquidDrawOff.P = TRAYS(LiquidSideStreamLocation).LiquidSideStream.P;
754
755"Liquid Draw Off Stream - Composition" 
756        LiquidDrawOff.z = TRAYS(LiquidSideStreamLocation).LiquidSideStream.z;
757
758"Liquid Draw Off Stream"       
759        LiquidDrawOffFlow = LiquidDrawOff.F;
760
761end
762
763Model Distillation_kettle_cond  as Section_ColumnBasic
764
765ATTRIBUTES
766        Pallete         = true;
767        Icon            = "icon/DistillationKettleCond";
768        Brief           = "Model of a distillation column with dynamic condenser and dynamic reboiler.";
769        Info            =
770"== Specify ==
771* the feed stream of each tray (Inlet);
772* the Murphree eficiency for each tray Emv;
773* the pump pressure difference;
774* the heat supllied in reboiler and condenser;
775* the condenser vapor outlet flow (OutletVapour.F);
776* the reboiler liquid outlet flow (OutletLiquid.F);
777* both splitter outlet flows OR one of the splitter outlet flows and the splitter frac.
778       
779== Initial Conditions ==
780* the TRAYS temperature (OutletLiquid.T);
781* the TRAYS liquid level (Level) OR the TRAYS liquid flow (OutletLiquid.F);
782* (NoComps - 1) OutletLiquid (OR OutletVapour) compositions for each tray;
783       
784* the condenser temperature (OutletLiquid.T);
785* the condenser liquid level (Level);
786* (NoComps - 1) OutletLiquid (OR OutletVapour) compositions;
787       
788* the reboiler temperature (OutletLiquid.T);
789* the reboiler liquid level (Level);
790* (NoComps - 1) OutletLiquid (OR OutletVapour) compositions.
791";
792       
793PARAMETERS
794        CondenserVapourFlow             as Switcher     (Valid = ["on", "off"], Default = "on",Hidden=true);
795
796VARIABLES
797        out     VapourDrawOff   as vapour_stream                (Brief="Vapour Outlet in the section", PosX=1, PosY=0.375,Protected = true);
798        out     LiquidDrawOff           as liquid_stream                        (Brief="Liquid Outlet in the section", PosX=1, PosY=0.42,Protected = true);
799#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
800# Column Devices
801#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++     
802        CONDENSER               as condenser;
803        REBOILER                as reboiler;
804        SPLITTER                as splitter2;
805        PUMP                    as pump;
806        alfaTopo                as Real;
807#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
808# Heat Ports
809#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
810        in      HeatToReboiler  as power (Brief="Heat supplied to Reboiler",Protected = true, PosX=1, PosY=0.90);
811        in      HeatToCondenser as power (Brief="Heat supplied to Condenser", Protected = true, PosX=1, PosY=0.034);
812#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
813# Column Connectors
814#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++     
815                ConnectorHeatReboiler   as power        (Brief="Heat supplied to Reboiler", Hidden=true);
816                ConnectorHeatCondenser  as power        (Brief="Heat supplied to Condenser", Hidden=true);
817        in      ConnectorCondenserVout  as stream       (Brief="Connector for Vapour outlet stream From Condenser", Hidden=true);
818        in      ConnectorReboilerLout   as stream       (Brief="Connector for Liquid outlet stream From Reboiler", Hidden=true);
819        in      ConnectorSplitterOut    as stream       (Brief="Connector for Liquid outlet stream From Top Splitter", Hidden=true);
820#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
821# Column products
822#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++     
823        out     VapourDistillate        as vapour_stream        (Brief="Vapour outlet stream From Condenser", PosX=0.66, PosY=0);
824        out     LiquidDistillate        as liquid_stream        (Brief="Liquid outlet stream From Top Splitter", PosX=1, PosY=0.20);
825        out     BottomProduct           as liquid_stream        (Brief="Liquid outlet stream From Reboiler", PosX=0.67, PosY=1);
826
827EQUATIONS
828
829switch CondenserVapourFlow
830
831        case "on":
832                CONDENSER.InletVapour.F*TRAYS(1).vV = alfaTopo *Ah * sqrt(2*(TRAYS(1).OutletVapour.P -
833                CONDENSER.OutletLiquid.P + 1e-8 * 'atm') / (alfa*TRAYS(1).rhoV));
834                when CONDENSER.InletVapour.F < 1e-6 * 'kmol/h' switchto "off";
835
836        case "off":
837                CONDENSER.InletVapour.F = 0 * 'mol/s';
838                when TRAYS(1).OutletVapour.P > CONDENSER.OutletLiquid.P + 1e-1 * 'atm' switchto "on";
839
840end     
841
842# Condenser Connector Equations
843        ConnectorCondenserVout.T = VapourDistillate.T;
844        ConnectorCondenserVout.P = VapourDistillate.P;
845        ConnectorCondenserVout.F = VapourDistillate.F;
846        ConnectorCondenserVout.z = VapourDistillate.z;
847
848# Splitter Connector Equations
849        ConnectorSplitterOut.T = LiquidDistillate.T;
850        ConnectorSplitterOut.P = LiquidDistillate.P;
851        ConnectorSplitterOut.F = LiquidDistillate.F;
852        ConnectorSplitterOut.z = LiquidDistillate.z;
853
854# Reboiler Connector Equations
855        ConnectorReboilerLout.T = BottomProduct.T;
856        ConnectorReboilerLout.P = BottomProduct.P;
857        ConnectorReboilerLout.F = BottomProduct.F;
858        ConnectorReboilerLout.z = BottomProduct.z;
859
860        VapourDrawOff.F*VapSideTrayIndex= TRAYS.VapourSideStream.F;
861        VapourDrawOff.T = TRAYS(VapourSideStreamLocation).VapourSideStream.T;
862        VapourDrawOff.P = TRAYS(VapourSideStreamLocation).VapourSideStream.P;
863        VapourDrawOff.z = TRAYS(VapourSideStreamLocation).VapourSideStream.z;
864
865        LiquidDrawOff.F*LiqSideTrayIndex= TRAYS.LiquidSideStream.F;
866        LiquidDrawOff.T = TRAYS(LiquidSideStreamLocation).LiquidSideStream.T;
867        LiquidDrawOff.P = TRAYS(LiquidSideStreamLocation).LiquidSideStream.P;
868        LiquidDrawOff.z = TRAYS(LiquidSideStreamLocation).LiquidSideStream.z;
869
870        VapourDrawOffFlow = VapourDrawOff.F;
871        LiquidDrawOffFlow = LiquidDrawOff.F;
872
873        HeatToReboiler  = ConnectorHeatReboiler;
874        HeatToCondenser = ConnectorHeatCondenser;
875
876CONNECTIONS
877#vapor
878        REBOILER.OutletVapour   to      TRAYS(NumberOfTrays).InletVapour;
879        TRAYS(1).OutletVapour   to      CONDENSER.InletVapour;
880
881#liquid
882        CONDENSER.OutletLiquid                          to      SPLITTER.Inlet;
883        SPLITTER.Outlet2                        to      PUMP.Inlet;
884        PUMP.Outlet                                     to      TRAYS(1).InletLiquid;
885        TRAYS(NumberOfTrays).OutletLiquid       to      REBOILER.InletLiquid;
886
887#Connectors
888        CONDENSER.OutletVapour  to ConnectorCondenserVout;
889        SPLITTER.Outlet1 to ConnectorSplitterOut;
890        REBOILER.OutletLiquid   to ConnectorReboilerLout;
891
892        ConnectorHeatReboiler   to REBOILER.InletQ;
893        ConnectorHeatCondenser  to CONDENSER.InletQ;
894
895end
896
897Model Distillation_thermosyphon_subcooling      as Section_ColumnBasic
898        ATTRIBUTES
899        Pallete         = true;
900        Icon            = "icon/DistillationThermosyphonSubcooling";
901        Brief           = "Model of a distillation column with steady condenser and steady reboiler.";
902        Info            =
903"== Specify ==
904* the feed stream of each tray (Inlet);
905* the Murphree eficiency for each tray Emv;
906* the pump head;
907* the condenser pressure drop;
908* the heat supllied in top and bottom tanks;
909* the heat supllied in condenser and reboiler;
910* the Outlet1 flow in the bottom splitter (spbottom.Outlet1.F) that corresponds to the bottom product;
911* both  top splitter outlet flows OR one of the splitter outlet flows and the splitter frac.
912       
913== Initial Conditions ==
914* the TRAYS temperature (OutletLiquid.T);
915* the TRAYS liquid level (Level) OR the TRAYS liquid flow (OutletLiquid.F);
916* (NoComps - 1) OutletLiquid (OR OutletVapour) compositions for each tray;
917       
918* the top tank temperature (OutletLiquid.T);
919* the top tank liquid level (Level);
920* (NoComps - 1) OutletLiquid (OR OutletVapour) compositions;
921       
922* the bottom tank temperature (OutletLiquid.T);
923* the bottom tank liquid level (Level);
924* (NoComps - 1) OutletLiquid (OR OutletVapour) compositions.
925";
926
927PARAMETERS
928
929        CondenserVapourFlow as Switcher(Valid = ["on", "off"], Hidden=true, Default = "on");
930
931VARIABLES
932#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
933# Column Vapour and Liquid Draw Sides
934#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
935        out     VapourDrawOff   as vapour_stream                (Brief="Vapour Outlet in the section", PosX=1, PosY=0.41,Protected = true);
936        out     LiquidDrawOff   as liquid_stream                (Brief="Liquid Outlet in the section", PosX=1, PosY=0.45,Protected = true);
937#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
938# Column Devices
939#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
940        CONDENSER                       as condenserSteady      (Brief="steady state condenser with subcooling");
941        ACCUMULATOR_TOP         as tank_cylindrical     (Brief="vessel drum (layed cilinder)");
942        SPLITTER_TOP            as splitter2                    (Brief="splitter which separate reflux and distillate");
943        PUMP                            as pump                         (Brief="pump in reflux stream");
944        REBOILER                        as reboilerSteady       (Brief="steady state reboiler (thermosyphon)");
945        ACCUMULATOR_BOTTOM      as tank                         (Brief="vessel in the bottom of column");
946        SPLITTER_BOTTOM         as splitter2                    (Brief="splitter who separate the bottom product and the stream to reboiler");
947        alfaTopo                        as Real;
948#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
949# Heat Ports
950#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
951in              HeatToCondenser                 as power        (Brief="Heat supplied to Condenser",PosX=1, PosY=0.099, Protected=true);
952in              HeatToReboiler                  as power        (Brief="Heat supplied to Reboiler", PosX=1, PosY=0.92,Protected=true);
953in              HeatToBottomAccumulator as power        (Brief="Heat supplied to Bottom Accumulator",PosX=0, PosY=0.925,Protected=true);
954in              HeatToTopAccumulator    as power        (Brief="Heat supplied to Top Accumulator", PosX=1, PosY=0.19,Protected=true);
955#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
956# Column Control Ports
957#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
958        out     TRI as control_signal   (Brief="Temperature Indicator of Reboiler ", PosX=1, PosY=0.88);
959        out     LTAI as control_signal  (Brief="Level Indicator of Top Accumulator ", PosX=1, PosY=0.15);
960        out     TCI as control_signal   (Brief="Temperature Indicator of Condenser ", PosX=1, PosY=0.059);
961        out     LBAI as control_signal  (Brief="Level Indicator of Bottom Accumulator", PosX=1, PosY=0.77);
962#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
963# Column Top and Bottom product
964#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
965out     LiquidDistillate        as liquid_stream        (Brief="Liquid outlet stream From Top Splitter", PosX=1, PosY=0.24);
966out     BottomProduct           as liquid_stream        (Brief="Liquid outlet stream From Bottom Splitter", PosX=0.18, PosY=1);
967#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
968# Column Model Connectors
969#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
970in      ConnectorSplitterBottom         as stream       (Brief="Connector for Liquid outlet stream From Reboiler", Hidden=true);
971in      ConnectorSplitterTop            as stream       (Brief="Connector for Liquid outlet stream From Top Splitter", Hidden=true);
972
973        ConnectorHeatReboiler                   as power        (Brief="Connector for Heat supplied to Reboiler", Hidden=true);
974        ConnectorHeatCondenser                  as power        (Brief="Connector for Heat supplied to Condenser", Hidden=true);
975        ConnectorHeatTopAccumulator     as power        (Brief="Connector for Heat supplied to Top Accumulator", Hidden=true);
976        ConnectorHeatBottomAccumulator  as power        (Brief="Connector for Heat supplied to Bottom Accumulator", Hidden=true);
977       
978EQUATIONS
979
980"Reboiler Temperature indicator"
981        TRI * 'K' = REBOILER.OutletVapour.T;
982
983"Condenser Temperature indicator"
984        TCI * 'K' = CONDENSER.OutletLiquid.T;
985
986"Top Accumulator Level indicator"
987        LTAI*ACCUMULATOR_TOP.Vtotal = ACCUMULATOR_TOP.Vfilled;
988
989"Bottom Accumulator Level indicator"
990        LBAI*ACCUMULATOR_BOTTOM.Vtotal = ACCUMULATOR_BOTTOM.Vfilled;
991       
992# Heat Connector Equations
993        HeatToCondenser                 =       ConnectorHeatCondenser;
994        HeatToReboiler                  =       ConnectorHeatReboiler;
995        HeatToBottomAccumulator =       ConnectorHeatBottomAccumulator;
996        HeatToTopAccumulator    =       ConnectorHeatTopAccumulator;
997
998# Top Splitter Connector Equations
999        ConnectorSplitterTop.T = LiquidDistillate.T;
1000        ConnectorSplitterTop.P = LiquidDistillate.P;
1001        ConnectorSplitterTop.F = LiquidDistillate.F;
1002        ConnectorSplitterTop.z = LiquidDistillate.z;
1003
1004# Bottom Splitter Connector Equations
1005        ConnectorSplitterBottom.T = BottomProduct.T;
1006        ConnectorSplitterBottom.P = BottomProduct.P;
1007        ConnectorSplitterBottom.F = BottomProduct.F;
1008        ConnectorSplitterBottom.z = BottomProduct.z;
1009
1010        VapourDrawOff.F*VapSideTrayIndex= TRAYS.VapourSideStream.F;
1011        VapourDrawOff.T = TRAYS(VapourSideStreamLocation).VapourSideStream.T;
1012        VapourDrawOff.P = TRAYS(VapourSideStreamLocation).VapourSideStream.P;
1013        VapourDrawOff.z = TRAYS(VapourSideStreamLocation).VapourSideStream.z;
1014
1015        LiquidDrawOff.F*LiqSideTrayIndex= TRAYS.LiquidSideStream.F;
1016        LiquidDrawOff.T = TRAYS(LiquidSideStreamLocation).LiquidSideStream.T;
1017        LiquidDrawOff.P = TRAYS(LiquidSideStreamLocation).LiquidSideStream.P;
1018        LiquidDrawOff.z = TRAYS(LiquidSideStreamLocation).LiquidSideStream.z;
1019
1020        VapourDrawOffFlow = VapourDrawOff.F;
1021        LiquidDrawOffFlow = LiquidDrawOff.F;
1022
1023switch CondenserVapourFlow
1024
1025        case "on":
1026                CONDENSER.InletVapour.F*TRAYS(1).vV = alfaTopo * Ah * sqrt(2*(TRAYS(1).OutletVapour.P -
1027                CONDENSER.OutletLiquid.P + 1e-8 * 'atm') / (alfa*TRAYS(1).rhoV));
1028                when CONDENSER.InletVapour.F < 1e-6 * 'kmol/h' switchto "off";
1029
1030        case "off":
1031                CONDENSER.InletVapour.F = 0 * 'mol/s';
1032                when TRAYS(1).OutletVapour.P > CONDENSER.OutletLiquid.P + 1e-1 * 'atm' switchto "on";
1033
1034end     
1035
1036CONNECTIONS
1037#vapor
1038        REBOILER.OutletVapour   to TRAYS(NumberOfTrays).InletVapour;
1039        TRAYS(1).OutletVapour   to CONDENSER.InletVapour;
1040
1041#liquid
1042        CONDENSER.OutletLiquid                          to ACCUMULATOR_TOP.Inlet;       
1043        ACCUMULATOR_TOP.Outlet                  to SPLITTER_TOP.Inlet;
1044        SPLITTER_TOP.Outlet2                    to PUMP.Inlet; 
1045        PUMP.Outlet                                     to TRAYS(1).InletLiquid;
1046        TRAYS(NumberOfTrays).OutletLiquid       to ACCUMULATOR_BOTTOM.Inlet;
1047        ACCUMULATOR_BOTTOM.Outlet               to SPLITTER_BOTTOM.Inlet;
1048        SPLITTER_BOTTOM.Outlet2                 to REBOILER.InletLiquid;
1049
1050#Connectors
1051        ConnectorHeatCondenser                  to CONDENSER.InletQ;
1052        ConnectorHeatReboiler                   to REBOILER.InletQ;
1053        ConnectorHeatBottomAccumulator  to ACCUMULATOR_BOTTOM.InletQ;
1054        ConnectorHeatTopAccumulator             to ACCUMULATOR_TOP.InletQ;
1055        SPLITTER_TOP.Outlet1                    to ConnectorSplitterTop;
1056        SPLITTER_BOTTOM.Outlet1                 to ConnectorSplitterBottom;
1057
1058end
1059
1060Model Distillation_thermosyphon_cond as Section_ColumnBasic
1061        ATTRIBUTES
1062        Pallete         = true;
1063        Icon            = "icon/DistillationThermosyphonCond";
1064        Brief           = "Model of a distillation column with dynamic condenser and steady reboiler.";
1065        Info            =
1066"== Specify ==
1067* the feed stream of each tray (Inlet);
1068* the Murphree eficiency for each tray Emv;
1069* the pump head;
1070* the condenser vapor outlet flow (OutletVapour.F);
1071* the heat supllied in bottom tank;
1072* the heat supllied in condenser and reboiler;
1073* the Outlet1 flow in the bottom splitter (spbottom.Outlet1.F) that corresponds to the bottom product;
1074       
1075== Initial Conditions ==
1076* the TRAYS temperature (OutletLiquid.T);
1077* the TRAYS liquid level (Level) OR the TRAYS liquid flow (OutletLiquid.F);
1078* (NoComps - 1) OutletLiquid (OR OutletVapour) compositions for each tray;
1079       
1080* the condenser temperature (OutletLiquid.T);
1081* the condenser liquid level (Level);
1082* (NoComps - 1) OutletLiquid (OR OutletVapour) compositions;
1083       
1084* the bottom tank temperature (OutletLiquid.T);
1085* the bottom tank liquid level (Level);
1086* (NoComps - 1) OutletLiquid (OR OutletVapour) compositions.
1087";
1088
1089PARAMETERS
1090        CondenserVapourFlow     as Switcher     (Valid = ["on", "off"], Default = "on",Hidden=true);
1091
1092VARIABLES
1093#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1094# Column Vapour and Liquid Draw Sides
1095#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1096        out     VapourDrawOff   as vapour_stream        (Brief="Vapour Outlet in the section", PosX=1, PosY=0.379,Protected = true);
1097        out     LiquidDrawOff   as liquid_stream        (Brief="Liquid Outlet in the section", PosX=1, PosY=0.425,Protected = true);
1098#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1099# Column Devices
1100#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1101        CONDENSER                       as condenser            (Brief="dynamic condenser without subcooling");
1102        SPLITTER_TOP            as splitter2                    (Brief="splitter which separate reflux and distillate");
1103        PUMP                            as pump                         (Brief="pump in reflux stream");
1104        ACCUMULATOR_BOTTOM      as tank                         (Brief="vessel in the bottom of column");
1105        SPLITTER_BOTTOM         as splitter2                    (Brief="splitter who separate the bottom product and the stream to reboiler");
1106        REBOILER                        as reboilerSteady       (Brief="steady state reboiler (thermosyphon)");
1107        alfaTopo                        as Real;
1108#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1109# Heat Ports
1110#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1111in      HeatToCondenser                 as power        (Brief="Heat supplied to Condenser",PosX=1, PosY=0.035, Protected=true);
1112in      HeatToReboiler                  as power        (Brief="Heat supplied to Reboiler", PosX=1, PosY=0.865,Protected=true);
1113in      HeatToBottomAccumulator as power        (Brief="Heat supplied to Bottom Accumulator",PosX=0, PosY=0.92,Protected=true);
1114#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1115# Column Top and Bottom product
1116#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1117out     VapourDistillate        as vapour_stream        (Brief="Vapour outlet stream From Top Condenser", PosX=0.665, PosY=0);
1118out     LiquidDistillate        as liquid_stream        (Brief="Liquid outlet stream From Top Splitter", PosX=1, PosY=0.20);
1119out     BottomProduct           as liquid_stream        (Brief="Liquid outlet stream From Bottom Splitter", PosX=0.18, PosY=1);
1120#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1121# Column Model Connectors
1122#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1123in      ConnectorSplitterBottom as stream       (Brief="Connector for Liquid outlet stream From Reboiler", Hidden=true);
1124in      ConnectorSplitterTop    as stream       (Brief="Connector for Liquid outlet stream From Top Splitter", Hidden=true);
1125in      ConnectorCondenserVout  as stream       (Brief="Connector for Vapour outlet stream From Top Condenser", Hidden=true);
1126
1127        ConnectorHeatReboiler                   as power        (Brief="Connector for Heat supplied to Reboiler", Hidden=true);
1128        ConnectorHeatCondenser                  as power        (Brief="Connector for Heat supplied to Condenser", Hidden=true);
1129        ConnectorHeatBottomAccumulator  as power        (Brief="Connector for Heat supplied to Bottom Accumulator", Hidden=true);
1130
1131EQUATIONS
1132# Heat Connector Equations
1133        HeatToCondenser                 =       ConnectorHeatCondenser;
1134        HeatToReboiler                  =       ConnectorHeatReboiler;
1135        HeatToBottomAccumulator =       ConnectorHeatBottomAccumulator;
1136
1137# Condenser Connector Equations
1138        ConnectorCondenserVout.T = VapourDistillate.T;
1139        ConnectorCondenserVout.P = VapourDistillate.P;
1140        ConnectorCondenserVout.F = VapourDistillate.F;
1141        ConnectorCondenserVout.z = VapourDistillate.z;
1142
1143# Top Splitter Connector Equations
1144        ConnectorSplitterTop.T = LiquidDistillate.T;
1145        ConnectorSplitterTop.P = LiquidDistillate.P;
1146        ConnectorSplitterTop.F = LiquidDistillate.F;
1147        ConnectorSplitterTop.z = LiquidDistillate.z;
1148
1149# Bottom Splitter Connector Equations
1150        ConnectorSplitterBottom.T = BottomProduct.T;
1151        ConnectorSplitterBottom.P = BottomProduct.P;
1152        ConnectorSplitterBottom.F = BottomProduct.F;
1153        ConnectorSplitterBottom.z = BottomProduct.z;
1154
1155        VapourDrawOff.F*VapSideTrayIndex= TRAYS.VapourSideStream.F;
1156        VapourDrawOff.T = TRAYS(VapourSideStreamLocation).VapourSideStream.T;
1157        VapourDrawOff.P = TRAYS(VapourSideStreamLocation).VapourSideStream.P;
1158        VapourDrawOff.z = TRAYS(VapourSideStreamLocation).VapourSideStream.z;
1159
1160        LiquidDrawOff.F*LiqSideTrayIndex= TRAYS.LiquidSideStream.F;
1161        LiquidDrawOff.T = TRAYS(LiquidSideStreamLocation).LiquidSideStream.T;
1162        LiquidDrawOff.P = TRAYS(LiquidSideStreamLocation).LiquidSideStream.P;
1163        LiquidDrawOff.z = TRAYS(LiquidSideStreamLocation).LiquidSideStream.z;
1164
1165        VapourDrawOffFlow = VapourDrawOff.F;
1166        LiquidDrawOffFlow = LiquidDrawOff.F;
1167       
1168switch CondenserVapourFlow
1169                case "on":
1170                CONDENSER.InletVapour.F*TRAYS(1).vV = alfaTopo * Ah * sqrt(2*(TRAYS(1).OutletVapour.P -
1171                CONDENSER.OutletLiquid.P + 1e-8 * 'atm') / (alfa*TRAYS(1).rhoV));
1172                when CONDENSER.InletVapour.F < 1e-6 * 'kmol/h' switchto "off";
1173               
1174                case "off":
1175                CONDENSER.InletVapour.F = 0 * 'mol/s';
1176                when TRAYS(1).OutletVapour.P > CONDENSER.OutletLiquid.P + 1e-1 * 'atm' switchto "on";
1177end     
1178
1179CONNECTIONS
1180#vapor
1181        REBOILER.OutletVapour   to TRAYS(NumberOfTrays).InletVapour;
1182        TRAYS(1).OutletVapour                           to CONDENSER.InletVapour;
1183
1184#liquid
1185        CONDENSER.OutletLiquid          to SPLITTER_TOP.Inlet; 
1186        SPLITTER_TOP.Outlet2                            to PUMP.Inlet;
1187        PUMP.Outlet                                     to TRAYS(1).InletLiquid;
1188        TRAYS(NumberOfTrays).OutletLiquid       to ACCUMULATOR_BOTTOM.Inlet;
1189        ACCUMULATOR_BOTTOM.Outlet                               to SPLITTER_BOTTOM.Inlet;
1190        SPLITTER_BOTTOM.Outlet2                         to REBOILER.InletLiquid;
1191
1192#Connectors
1193ConnectorHeatCondenser                  to CONDENSER.InletQ;
1194ConnectorHeatReboiler                   to REBOILER.InletQ;
1195ConnectorHeatBottomAccumulator  to ACCUMULATOR_BOTTOM.InletQ;
1196CONDENSER.OutletVapour                          to ConnectorCondenserVout;
1197SPLITTER_TOP.Outlet1                    to ConnectorSplitterTop;
1198SPLITTER_BOTTOM.Outlet1                 to ConnectorSplitterBottom;
1199
1200end
1201
1202Model Distillation_kettle_subcooling as Section_ColumnBasic
1203
1204ATTRIBUTES
1205        Pallete         = true;
1206        Icon            = "icon/DistillationKettleSubcooling";
1207        Brief   = "Model of a distillation column with steady condenser and dynamic reboiler.";
1208        Info            =
1209"== Specify ==
1210* the feed stream of each tray (Inlet);
1211* the Murphree eficiency for each tray (Emv);
1212* the pump pressure difference;
1213* the heat supllied in reboiler and condenser;
1214* the heat supllied in the top tank;
1215* the condenser pressure drop;
1216* the reboiler liquid outlet flow (OutletLiquid.F);
1217* both splitter outlet flows OR one of the splitter outlet flows and the splitter frac.
1218       
1219== Initial Conditions ==
1220* the TRAYS temperature (OutletLiquid.T);
1221* the TRAYS liquid level (Level) OR the TRAYS liquid flow (OutletLiquid.F);
1222* (NoComps - 1) OutletLiquid (OR OutletVapour) compositions for each tray;
1223       
1224* the top tank temperature (OutletLiquid.T);
1225* the top tank liquid level (Level);
1226* (NoComps - 1) OutletLiquid (OR OutletVapour) compositions;
1227       
1228* the reboiler temperature (OutletLiquid.T);
1229* the reboiler liquid level (Level);
1230* (NoComps - 1) OutletLiquid (OR OutletVapour) compositions.
1231";
1232       
1233PARAMETERS
1234        CondenserVapourFlow as Switcher(Valid = ["on", "off"], Default = "on",Hidden=true);
1235
1236VARIABLES
1237#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1238# Column Vapour and Liquid Draw Sides
1239#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1240        out     VapourDrawOff   as vapour_stream        (Brief="Vapour Outlet in the section", PosX=1, PosY=0.41,Protected = true);
1241        out     LiquidDrawOff   as liquid_stream        (Brief="Liquid Outlet in the section", PosX=1, PosY=0.45,Protected = true);
1242#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1243# Column Devices
1244#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++     
1245        CONDENSER               as condenserSteady      (Brief="steady state condenser with subcooling");
1246        ACCUMULATOR             as tank_cylindrical     (Brief="vessel drum (layed cilinder)");
1247        SPLITTER                as splitter2                    (Brief="splitter which separate reflux and distillate");
1248        PUMP                    as pump                         (Brief="pump in reflux stream");
1249        REBOILER                as reboiler                     (Brief="kettle reboiler");
1250        alfaTopo                as Real;
1251#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1252# Heat Ports
1253#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1254in              HeatToCondenser         as power        (Brief="Heat supplied to Condenser", PosX=1, PosY=0.065, Protected=true);
1255in              HeatToReboiler          as power        (Brief="Heat supplied to Reboiler", PosX=1, PosY=0.905, Protected=true);
1256in              HeatToAccumulator       as power        (Brief="Heat supplied to Top Vessel", PosX=1, PosY=0.195, Protected=true);
1257#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1258# Column Model Connectors
1259#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1260in      ConnectorSplitterOut            as stream       (Brief="Connector for Liquid outlet stream From Top Splitter", Hidden=true);
1261in      ConnectorReboilerLout           as stream       (Brief="Connector for Liquid outlet stream From Reboiler", Hidden=true);
1262        ConnectorHeatReboiler           as power        (Brief="Connector for Heat supplied to Reboiler", Hidden=true);
1263        ConnectorHeatCondenser          as power        (Brief="Connector for Heat supplied to Condenser", Hidden=true);
1264        ConnectorHeatAccumulator        as power        (Brief="Connector for Heat supplied to TopVessel", Hidden=true);
1265#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1266# Column Top and Bottom product
1267#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1268out     LiquidDistillate as liquid_stream       (Brief="Liquid outlet stream From Top Splitter", PosX=1, PosY=0.24);
1269out     BottomProduct    as liquid_stream       (Brief="Liquid outlet stream From Reboiler", PosX=0.67, PosY=1);
1270
1271EQUATIONS
1272
1273#Heat Connectors
1274HeatToCondenser         = ConnectorHeatCondenser;
1275HeatToReboiler          = ConnectorHeatReboiler;
1276HeatToAccumulator       = ConnectorHeatAccumulator;
1277
1278# Splitter Connector Equations
1279        ConnectorSplitterOut.T = LiquidDistillate.T;
1280        ConnectorSplitterOut.P = LiquidDistillate.P;
1281        ConnectorSplitterOut.F = LiquidDistillate.F;
1282        ConnectorSplitterOut.z = LiquidDistillate.z;
1283
1284# Reboiler Connector Equations
1285        ConnectorReboilerLout.T = BottomProduct.T;
1286        ConnectorReboilerLout.P = BottomProduct.P;
1287        ConnectorReboilerLout.F = BottomProduct.F;
1288        ConnectorReboilerLout.z = BottomProduct.z;
1289       
1290        VapourDrawOff.F*VapSideTrayIndex= TRAYS.VapourSideStream.F;
1291        VapourDrawOff.T = TRAYS(VapourSideStreamLocation).VapourSideStream.T;
1292        VapourDrawOff.P = TRAYS(VapourSideStreamLocation).VapourSideStream.P;
1293        VapourDrawOff.z = TRAYS(VapourSideStreamLocation).VapourSideStream.z;
1294
1295        LiquidDrawOff.F*LiqSideTrayIndex= TRAYS.LiquidSideStream.F;
1296        LiquidDrawOff.T = TRAYS(LiquidSideStreamLocation).LiquidSideStream.T;
1297        LiquidDrawOff.P = TRAYS(LiquidSideStreamLocation).LiquidSideStream.P;
1298        LiquidDrawOff.z = TRAYS(LiquidSideStreamLocation).LiquidSideStream.z;
1299
1300        VapourDrawOffFlow = VapourDrawOff.F;
1301        LiquidDrawOffFlow = LiquidDrawOff.F;
1302       
1303        switch CondenserVapourFlow
1304                case "on":
1305                CONDENSER.InletVapour.F*TRAYS(1).vV = alfaTopo * Ah * sqrt(2*(TRAYS(1).OutletVapour.P -
1306                CONDENSER.OutletLiquid.P + 1e-8 * 'atm') / (alfa*TRAYS(1).rhoV));
1307                when CONDENSER.InletVapour.F < 1e-6 * 'kmol/h' switchto "off";
1308               
1309                case "off":
1310                CONDENSER.InletVapour.F = 0 * 'mol/s';
1311                when TRAYS(1).OutletVapour.P > CONDENSER.OutletLiquid.P + 1e-1 * 'atm' switchto "on";
1312end     
1313
1314CONNECTIONS
1315#vapor
1316        REBOILER.OutletVapour to TRAYS(NumberOfTrays).InletVapour;
1317        TRAYS(1).OutletVapour to CONDENSER.InletVapour;
1318
1319#liquid
1320        CONDENSER.OutletLiquid                          to ACCUMULATOR.Inlet;   
1321        ACCUMULATOR.Outlet                                      to SPLITTER.Inlet;
1322        SPLITTER.Outlet2                        to PUMP.Inlet; 
1323        PUMP.Outlet                                     to TRAYS(1).InletLiquid;
1324        TRAYS(NumberOfTrays).OutletLiquid       to REBOILER.InletLiquid;
1325
1326#Connectors
1327ConnectorHeatCondenser          to CONDENSER.InletQ;
1328ConnectorHeatReboiler           to REBOILER.InletQ;
1329ConnectorHeatAccumulator        to ACCUMULATOR.InletQ;
1330
1331SPLITTER.Outlet1 to ConnectorSplitterOut;
1332REBOILER.OutletLiquid   to ConnectorReboilerLout;
1333
1334end
1335
1336Model Rectifier as Section_ColumnBasic
1337
1338ATTRIBUTES
1339        Pallete         = true;
1340        Icon            = "icon/RefluxedCond";
1341        Brief           = "Model of a rectifier column with dynamic condenser.";
1342        Info            =
1343"== Specify ==
1344* the feed stream of each tray (Inlet);
1345* the Murphree eficiency for each tray Emv;
1346* the InletVapour stream of the bottom tray unless its flow;
1347* the pump pressure difference;
1348* the heat supllied in the condenser;
1349* the condenser vapor outlet flow (OutletVapour.F);
1350* both splitter outlet flows OR one of the splitter outlet flows and the splitter frac.
1351       
1352== Initial Conditions ==
1353* the TRAYS temperature (OutletLiquid.T);
1354* the TRAYS liquid level (Level) OR the TRAYS liquid flow (OutletLiquid.F);
1355* (NoComps - 1) OutletLiquid (OR OutletVapour) compositions for each tray;
1356       
1357* the condenser temperature (OutletLiquid.T);
1358* the condenser liquid level (Level);
1359* (NoComps - 1) OutletLiquid (OR OutletVapour) compositions;
1360";
1361
1362PARAMETERS
1363        CondenserVapourFlow as Switcher(Valid = ["on", "off"], Default = "on",Hidden=true);
1364
1365VARIABLES
1366#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1367# Column Vapour and Liquid Draw Sides
1368#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1369        out     VapourDrawOff   as vapour_stream        (Brief="Vapour Outlet in the section", PosX=1, PosY=0.45,Protected = true);
1370        out     LiquidDrawOff   as liquid_stream        (Brief="Liquid Outlet in the section", PosX=1, PosY=0.50,Protected = true);
1371#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1372# Column Devices
1373#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1374        CONDENSER       as condenser    (Brief="dymamic condenser without subcooling");
1375        SPLITTER        as splitter2            (Brief="splitter which separate reflux and distillate");
1376        PUMP            as pump                 (Brief="pump in reflux stream");
1377        alfaTopo        as Real;
1378#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1379# Column Top product
1380#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1381        out     VapourDistillate        as vapour_stream        (Brief="Vapour outlet stream From Top Condenser", PosX=0.66, PosY=0);
1382        out     LiquidDistillate        as liquid_stream        (Brief="Liquid outlet stream From Top Splitter", PosX=1, PosY=0.24);
1383#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1384# Heat Port
1385#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1386        in      HeatToCondenser         as power (Brief="Heat supplied to Condenser",PosX=1, PosY=0.04, Protected = true);
1387#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1388# Column Bottom Outlets
1389#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++     
1390        in      VapourInlet             as stream                       (Brief="Vapour Inlet in the section", PosX=0.07, PosY=1);
1391        out     LiquidOutlet    as liquid_stream        (Brief="Liquid Outlet in the section", PosX=0.32, PosY=1);
1392#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1393# Column Model Connectors
1394#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1395        in      ConnectorSplitterOut    as stream       (Brief="Connector for Liquid outlet stream From Top Splitter", Hidden=true);
1396        in      ConnectorCondenserVout  as stream       (Brief="Connector for Vapour outlet stream From Top Condenser", Hidden=true);
1397                VapourConnector                 as stream       (Brief="Vapour connection at the middle TRAYS", PosX=0.55, PosY=0,Hidden=true);
1398                ConnectorHeatCondenser  as power        (Brief="Connector for Heat supplied to Condenser", Hidden=true);
1399       
1400EQUATIONS
1401
1402switch CondenserVapourFlow
1403
1404        case "on":
1405                CONDENSER.InletVapour.F*TRAYS(1).vV = alfaTopo * Ah * sqrt(2*(TRAYS(1).OutletVapour.P -
1406                CONDENSER.OutletLiquid.P + 1e-8 * 'atm') / (alfa*TRAYS(1).rhoV));
1407                when CONDENSER.InletVapour.F < 1e-6 * 'kmol/h' switchto "off";
1408               
1409        case "off":
1410                CONDENSER.InletVapour.F = 0 * 'mol/s';
1411                when TRAYS(1).OutletVapour.P > CONDENSER.OutletLiquid.P + 1e-1 * 'atm' switchto "on";
1412
1413end     
1414
1415HeatToCondenser = ConnectorHeatCondenser;
1416
1417# Condenser Connector Equations
1418        ConnectorCondenserVout.T = VapourDistillate.T;
1419        ConnectorCondenserVout.P = VapourDistillate.P;
1420        ConnectorCondenserVout.F = VapourDistillate.F;
1421        ConnectorCondenserVout.z = VapourDistillate.z;
1422       
1423# Splitter Connector Equations
1424        ConnectorSplitterOut.T = LiquidDistillate.T;
1425        ConnectorSplitterOut.P = LiquidDistillate.P;
1426        ConnectorSplitterOut.F = LiquidDistillate.F;
1427        ConnectorSplitterOut.z = LiquidDistillate.z;
1428       
1429        LiquidOutlet.F= TRAYS(NumberOfTrays).OutletLiquid.F;
1430        LiquidOutlet.T = TRAYS(NumberOfTrays).OutletLiquid.T;
1431        LiquidOutlet.P = TRAYS(NumberOfTrays).OutletLiquid.P;
1432        LiquidOutlet.z = TRAYS(NumberOfTrays).OutletLiquid.z;
1433
1434        VapourConnector.F= VapourInlet.F;
1435        VapourConnector.T = VapourInlet.T;
1436        VapourConnector.P = VapourInlet.P;
1437        VapourConnector.z = VapourInlet.z;
1438        VapourConnector.v = VapourInlet.v;
1439        VapourConnector.h = VapourInlet.h;
1440
1441        VapourDrawOff.F*VapSideTrayIndex= TRAYS.VapourSideStream.F;
1442        VapourDrawOff.T = TRAYS(VapourSideStreamLocation).VapourSideStream.T;
1443        VapourDrawOff.P = TRAYS(VapourSideStreamLocation).VapourSideStream.P;
1444        VapourDrawOff.z = TRAYS(VapourSideStreamLocation).VapourSideStream.z;
1445
1446        LiquidDrawOff.F*LiqSideTrayIndex= TRAYS.LiquidSideStream.F;
1447        LiquidDrawOff.T = TRAYS(LiquidSideStreamLocation).LiquidSideStream.T;
1448        LiquidDrawOff.P = TRAYS(LiquidSideStreamLocation).LiquidSideStream.P;
1449        LiquidDrawOff.z = TRAYS(LiquidSideStreamLocation).LiquidSideStream.z;
1450
1451        VapourDrawOffFlow = VapourDrawOff.F;
1452        LiquidDrawOffFlow = LiquidDrawOff.F;
1453
1454CONNECTIONS
1455#vapor
1456        TRAYS(1).OutletVapour to CONDENSER.InletVapour;
1457
1458#liquid
1459        CONDENSER.OutletLiquid  to SPLITTER.Inlet;     
1460        SPLITTER.Outlet2        to PUMP.Inlet; 
1461        PUMP.Outlet             to TRAYS(1).InletLiquid;
1462
1463#Connectors
1464ConnectorHeatCondenser  to CONDENSER.InletQ;
1465VapourConnector                 to TRAYS(NumberOfTrays).InletVapour;
1466SPLITTER.Outlet1                to ConnectorSplitterOut;
1467CONDENSER.OutletVapour          to ConnectorCondenserVout;
1468
1469end
1470
1471Model Rectifier_subcooling as Section_ColumnBasic
1472
1473ATTRIBUTES
1474        Pallete         = true;
1475        Icon            = "icon/RefluxedSubcooling";
1476        Brief           = "Model of a rectifier column with steady condenser.";
1477        Info            =
1478"== Specify ==
1479* the feed stream of each tray (Inlet);
1480* the Murphree eficiency for each tray Emv;
1481* the InletVapour stream of the bottom tray unless its flow;
1482* the pump head;
1483* the condenser pressure drop;
1484* the heat supllied in  the top tank;
1485* the heat supllied in condenser;
1486* both  top splitter outlet flows OR one of the splitter outlet flows and the splitter frac.
1487       
1488== Initial Conditions ==
1489* the TRAYS temperature (OutletLiquid.T);
1490* the TRAYS liquid level (Level) OR the TRAYS liquid flow (OutletLiquid.F);
1491* (NoComps - 1) OutletLiquid (OR OutletVapour) compositions for each tray;
1492       
1493* the top tank temperature (OutletLiquid.T);
1494* the top tank liquid level (Level);
1495* (NoComps - 1) OutletLiquid (OR OutletVapour) compositions;
1496";
1497       
1498PARAMETERS
1499        CondenserVapourFlow             as Switcher     (Valid = ["on", "off"], Default = "on",Hidden=true);
1500
1501VARIABLES
1502#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1503# Column Vapour and Liquid Draw Sides
1504#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1505        out     VapourDrawOff   as vapour_stream        (Brief="Vapour Outlet in the section", PosX=1, PosY=0.485,Protected = true);
1506        out     LiquidDrawOff   as liquid_stream        (Brief="Liquid Outlet in the section", PosX=1, PosY=0.535,Protected = true);
1507#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1508# Column Devices
1509#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1510        CONDENSER               as condenserSteady      (Brief="steady state condenser with subcooling");
1511        ACCUMULATOR             as tank_cylindrical     (Brief="vessel drum (layed cilinder)");
1512        SPLITTER                as splitter2                    (Brief="plitter which separate reflux and distillate");
1513        PUMP                    as pump                         (Brief="pump in reflux stream");
1514        alfaTopo                as Real;
1515#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1516# Column Bottom outlets
1517#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1518        in      VapourInlet             as stream                       (Brief="Vapour Inlet in the section", PosX=0.07, PosY=1);
1519        out     LiquidOutlet    as liquid_stream        (Brief="Liquid Outlet in the section", PosX=0.32, PosY=1);
1520#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1521# Heat Ports
1522#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1523        in      HeatToCondenser         as power        (Brief="Heat supplied to Condenser", PosX=1, PosY=0.070, Protected=true);
1524        in      HeatToAccumulator       as power        (Brief="Heat supplied to Top Accumulator", PosX=1, PosY=0.23, Protected=true);
1525#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1526# Column Top Product
1527#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1528        out     LiquidDistillate                as liquid_stream        (Brief="Liquid outlet stream From Top Splitter", PosX=1, PosY=0.285);
1529#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1530# Column Connectors
1531#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1532in      ConnectorSplitterTop            as stream       (Brief="Connector for Liquid outlet stream From Top Splitter", Hidden=true);
1533        VapourConnector                         as stream       (Brief="Vapour connection at the middle TRAYS", PosX=0.55, PosY=0,Hidden=true);
1534        ConnectorHeatCondenser          as power        (Brief="Connector for Heat supplied to Condenser", Hidden=true);
1535        ConnectorHeatAccumulator        as power        (Brief="Connector for Heat supplied to Top Accumulator", Hidden=true);
1536
1537EQUATIONS
1538#Heat Connectors
1539        HeatToCondenser         = ConnectorHeatCondenser;
1540        HeatToAccumulator       = ConnectorHeatAccumulator;
1541       
1542        LiquidOutlet.F= TRAYS(NumberOfTrays).OutletLiquid.F;
1543        LiquidOutlet.T = TRAYS(NumberOfTrays).OutletLiquid.T;
1544        LiquidOutlet.P = TRAYS(NumberOfTrays).OutletLiquid.P;
1545        LiquidOutlet.z = TRAYS(NumberOfTrays).OutletLiquid.z;
1546
1547        VapourConnector.F= VapourInlet.F;
1548        VapourConnector.T = VapourInlet.T;
1549        VapourConnector.P = VapourInlet.P;
1550        VapourConnector.z = VapourInlet.z;
1551        VapourConnector.v = VapourInlet.v;
1552        VapourConnector.h = VapourInlet.h;
1553       
1554# Splitter Connector Equations
1555        ConnectorSplitterTop.T = LiquidDistillate.T;
1556        ConnectorSplitterTop.P = LiquidDistillate.P;
1557        ConnectorSplitterTop.F = LiquidDistillate.F;
1558        ConnectorSplitterTop.z = LiquidDistillate.z;
1559
1560        VapourDrawOff.F*VapSideTrayIndex= TRAYS.VapourSideStream.F;
1561        VapourDrawOff.T = TRAYS(VapourSideStreamLocation).VapourSideStream.T;
1562        VapourDrawOff.P = TRAYS(VapourSideStreamLocation).VapourSideStream.P;
1563        VapourDrawOff.z = TRAYS(VapourSideStreamLocation).VapourSideStream.z;
1564
1565        LiquidDrawOff.F*LiqSideTrayIndex= TRAYS.LiquidSideStream.F;
1566        LiquidDrawOff.T = TRAYS(LiquidSideStreamLocation).LiquidSideStream.T;
1567        LiquidDrawOff.P = TRAYS(LiquidSideStreamLocation).LiquidSideStream.P;
1568        LiquidDrawOff.z = TRAYS(LiquidSideStreamLocation).LiquidSideStream.z;
1569
1570        VapourDrawOffFlow = VapourDrawOff.F;
1571        LiquidDrawOffFlow = LiquidDrawOff.F;
1572       
1573switch CondenserVapourFlow
1574
1575        case "on":
1576                CONDENSER.InletVapour.F*TRAYS(1).vV = alfaTopo *Ah * sqrt(2*(TRAYS(1).OutletVapour.P -
1577                CONDENSER.OutletLiquid.P + 1e-8 * 'atm') / (alfa*TRAYS(1).rhoV));
1578        when CONDENSER.InletVapour.F < 1e-6 * 'kmol/h' switchto "off";
1579               
1580        case "off":
1581                CONDENSER.InletVapour.F = 0 * 'mol/s';
1582        when TRAYS(1).OutletVapour.P > CONDENSER.OutletLiquid.P + 1e-1 * 'atm' switchto "on";
1583
1584end     
1585
1586CONNECTIONS
1587#vapor
1588        TRAYS(1).OutletVapour to CONDENSER.InletVapour;
1589
1590#liquid
1591        CONDENSER.OutletLiquid          to ACCUMULATOR.Inlet;   
1592        ACCUMULATOR.Outlet                                      to SPLITTER.Inlet;
1593        SPLITTER.Outlet2                to PUMP.Inlet; 
1594        PUMP.Outlet                                             to TRAYS(1).InletLiquid;
1595
1596#Connectors
1597        VapourConnector                         to TRAYS(NumberOfTrays).InletVapour;
1598        ConnectorHeatCondenser                  to CONDENSER.InletQ;
1599        SPLITTER.Outlet1        to ConnectorSplitterTop;
1600        ConnectorHeatAccumulator                        to ACCUMULATOR.InletQ;
1601
1602end
1603
1604Model Reboiled_Stripping_kettle as Section_ColumnBasic
1605       
1606ATTRIBUTES
1607        Pallete         = true;
1608        Icon            = "icon/ReboiledKettle";
1609        Brief           = "Model of a reboiled stripping column with dynamic reboiler.";
1610        Info            =
1611"== Specify ==
1612* the feed stream of each tray (Inlet);
1613* the Murphree eficiency for each tray Emv;
1614* the vapour flow leaving the top of the column;
1615* the InletLiquidiquid stream of the top tray;
1616* the heat supllied in the reboiler;
1617* the reboiler liquid outlet flow (OutletLiquid.F);
1618       
1619== Initial Conditions ==
1620* the TRAYS temperature (OutletLiquid.T);
1621* the TRAYS liquid level (Level) OR the TRAYS liquid flow (OutletLiquid.F);
1622* (NoComps - 1) OutletLiquid (OR OutletVapour) compositions for each tray;
1623       
1624* the reboiler temperature (OutletLiquid.T);
1625* the reboiler liquid level (Level);
1626* (NoComps - 1) OutletLiquid (OR OutletVapour) compositions.
1627";
1628
1629VARIABLES
1630#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1631# Column Vapour and Liquid Draw Sides
1632#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1633        out     VapourDrawOff   as vapour_stream        (Brief="Vapour Outlet in the section", PosX=1, PosY=0.28,Protected = true);
1634        out     LiquidDrawOff   as liquid_stream        (Brief="Liquid Outlet in the section", PosX=1, PosY=0.33,Protected = true);
1635#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1636# Column Devices
1637#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 
1638        REBOILER as reboiler (Brief="Kettle Reboiler");
1639#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1640# Heat Port
1641#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++     
1642        in      HeatToReboiler  as power        (Brief="Heat supplied to Reboiler",PosX=1, PosY=0.865,Protected=true);
1643#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1644# Column Top Outlets
1645#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++             
1646        in      LiquidInlet             as      stream                  (Brief="Liquid Inlet in the section", PosX=0.30, PosY=0);
1647        out     VapourOutlet    as vapour_stream        (Brief="Vapour Outlet in the section", PosX=0.07, PosY=0);
1648#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1649# Column Bottom Product
1650#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++     
1651        out     BottomProduct   as liquid_stream        (Brief="Liquid outlet stream From Reboiler", PosX=0.68, PosY=1);
1652#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1653# Column Connectors
1654#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1655        in      ConnectorReboilerLout   as stream       (Brief="Connector for Liquid outlet stream From Reboiler", Hidden=true);
1656                LiquidConnector                 as stream       (Brief="Liquid connection at the middle TRAYS", PosX=0.75, PosY=1,Hidden=true);
1657                ConnectorHeatReboiler   as power        (Brief="Connector for Heat supplied to Reboiler", Hidden=true);
1658
1659CONNECTIONS
1660#vapor
1661        REBOILER.OutletVapour to TRAYS(NumberOfTrays).InletVapour;
1662       
1663#liquid
1664        TRAYS(NumberOfTrays).OutletLiquid to REBOILER.InletLiquid;
1665
1666#Connectors
1667REBOILER.OutletLiquid           to ConnectorReboilerLout;
1668LiquidConnector                 to TRAYS(1).InletLiquid;
1669ConnectorHeatReboiler   to REBOILER.InletQ;
1670
1671EQUATIONS
1672#Heat Connectors
1673        HeatToReboiler = ConnectorHeatReboiler;
1674       
1675        LiquidConnector.F= LiquidInlet.F;
1676        LiquidConnector.T = LiquidInlet.T;
1677        LiquidConnector.P = LiquidInlet.P;
1678        LiquidConnector.z = LiquidInlet.z;
1679        LiquidConnector.v = LiquidInlet.v;
1680        LiquidConnector.h = LiquidInlet.h;
1681       
1682        VapourOutlet.F= TRAYS(1).OutletVapour.F;
1683        VapourOutlet.T = TRAYS(1).OutletVapour.T;
1684        VapourOutlet.P = TRAYS(1).OutletVapour.P;
1685        VapourOutlet.z = TRAYS(1).OutletVapour.z;
1686       
1687# Reboiler Connector Equations
1688        ConnectorReboilerLout.T = BottomProduct.T;
1689        ConnectorReboilerLout.P = BottomProduct.P;
1690        ConnectorReboilerLout.F = BottomProduct.F;
1691        ConnectorReboilerLout.z = BottomProduct.z;
1692       
1693        VapourDrawOff.F*VapSideTrayIndex= TRAYS.VapourSideStream.F;
1694        VapourDrawOff.T = TRAYS(VapourSideStreamLocation).VapourSideStream.T;
1695        VapourDrawOff.P = TRAYS(VapourSideStreamLocation).VapourSideStream.P;
1696        VapourDrawOff.z = TRAYS(VapourSideStreamLocation).VapourSideStream.z;
1697
1698        LiquidDrawOff.F*LiqSideTrayIndex= TRAYS.LiquidSideStream.F;
1699        LiquidDrawOff.T = TRAYS(LiquidSideStreamLocation).LiquidSideStream.T;
1700        LiquidDrawOff.P = TRAYS(LiquidSideStreamLocation).LiquidSideStream.P;
1701        LiquidDrawOff.z = TRAYS(LiquidSideStreamLocation).LiquidSideStream.z;
1702
1703        VapourDrawOffFlow = VapourDrawOff.F;
1704        LiquidDrawOffFlow = LiquidDrawOff.F;
1705
1706end
1707
1708Model Reboiled_Stripping_thermosyphon as Section_ColumnBasic
1709
1710ATTRIBUTES
1711        Pallete         = true;
1712        Icon            = "icon/ReboiledThermosyphon";
1713        Brief           = "Model of a reboiled stripping column with steady reboiler.";
1714        Info            =
1715"== Specify ==
1716* the feed stream of each tray (Inlet);
1717* the Murphree eficiency for each tray (Emv);
1718* the vapour flow leaving the top of the column;
1719* the InletLiquidiquid stream of the top tray;
1720* the heat supllied in bottom tank;
1721* the heat supllied in the reboiler;
1722* the Outlet1 flow in the bottom splitter (spbottom.Outlet1.F) that corresponds to the bottom product;
1723       
1724== Initial Conditions ==
1725* the TRAYS temperature (OutletLiquid.T);
1726* the TRAYS liquid level (Level) OR the TRAYS liquid flow (OutletLiquid.F);
1727* (NoComps - 1) OutletLiquid (OR OutletVapour) compositions for each tray;
1728
1729* the bottom tank temperature (OutletLiquid.T);
1730* the bottom tank liquid level (Level);
1731* (NoComps - 1) OutletLiquid (OR OutletVapour) compositions.
1732";
1733
1734VARIABLES
1735#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1736# Column Vapour and Liquid Draw Sides
1737#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1738        out     VapourDrawOff   as vapour_stream        (Brief="Vapour Outlet in the section", PosX=1, PosY=0.28,Protected = true);
1739        out     LiquidDrawOff   as liquid_stream        (Brief="Liquid Outlet in the section", PosX=1, PosY=0.33,Protected = true);
1740#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1741# Column Devices
1742#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++     
1743        REBOILER                as reboilerSteady       (Brief="steady state reboiler (thermosyphon)");
1744        SPLITTER                as splitter2            (Brief="splitter which separate the bottom product and the stream to reboiler");
1745        ACCUMULATOR     as tank                         (Brief="vessel in the bottom of column");
1746#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1747# Heat Ports
1748#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++     
1749        in      HeatToReboiler          as power        (Brief="Heat supplied to Reboiler",PosX=1, PosY=0.84,Protected=true);
1750        in      HeatToAccumulator       as power        (Brief="Heat supplied to Bottom Vessel",PosX=0, PosY=0.91,Protected=true);
1751#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1752# Column Top Outlets
1753#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++     
1754        in      LiquidInlet             as      stream                  (Brief="Liquid Inlet in the section", PosX=0.32, PosY=0);
1755        out     VapourOutlet    as vapour_stream        (Brief="Vapour Outlet in the section", PosX=0.07, PosY=0);
1756#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1757# Column Bottom Product
1758#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++     
1759        out     BottomProduct   as liquid_stream        (Brief="Liquid outlet stream From Reboiler", PosX=0.19, PosY=1);
1760        LiquidConnector         as stream                       (Brief="Liquid connection at the middle TRAYS", PosX=0.75, PosY=1,Hidden=true);
1761#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1762# Column Connectors
1763#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1764        in      ConnectorSplitterBottom         as stream       (Brief="Connector for Liquid outlet stream From Reboiler", Hidden=true);
1765        ConnectorHeatReboiler                   as power        (Brief="Connector for Heat supplied to Reboiler", Hidden=true);
1766        ConnectorHeatAccumulator                as power        (Brief="Connector for Heat supplied to Bottom Accumulator", Hidden=true);
1767
1768CONNECTIONS
1769#vapor
1770        REBOILER.OutletVapour to TRAYS(NumberOfTrays).InletVapour;
1771       
1772#liquid
1773        TRAYS(NumberOfTrays).OutletLiquid       to ACCUMULATOR.Inlet;
1774        ACCUMULATOR.Outlet                              to SPLITTER.Inlet;
1775        SPLITTER.Outlet2                                to REBOILER.InletLiquid;
1776
1777#Connectors
1778LiquidConnector                         to TRAYS(1).InletLiquid;
1779ConnectorHeatReboiler           to REBOILER.InletQ;
1780ConnectorHeatAccumulator        to ACCUMULATOR.InletQ;
1781SPLITTER.Outlet1                        to ConnectorSplitterBottom;
1782
1783EQUATIONS
1784#Heat Connectors
1785        HeatToReboiler  = ConnectorHeatReboiler;
1786        HeatToAccumulator       = ConnectorHeatAccumulator;
1787       
1788        ConnectorSplitterBottom.T = BottomProduct.T;
1789        ConnectorSplitterBottom.P = BottomProduct.P;
1790        ConnectorSplitterBottom.F = BottomProduct.F;
1791        ConnectorSplitterBottom.z = BottomProduct.z;
1792       
1793        LiquidConnector.F= LiquidInlet.F;
1794        LiquidConnector.T = LiquidInlet.T;
1795        LiquidConnector.P = LiquidInlet.P;
1796        LiquidConnector.z = LiquidInlet.z;
1797        LiquidConnector.v = LiquidInlet.v;
1798        LiquidConnector.h = LiquidInlet.h;
1799       
1800        VapourOutlet.F= TRAYS(1).OutletVapour.F;
1801        VapourOutlet.T = TRAYS(1).OutletVapour.T;
1802        VapourOutlet.P = TRAYS(1).OutletVapour.P;
1803        VapourOutlet.z = TRAYS(1).OutletVapour.z;
1804       
1805        VapourDrawOff.F*VapSideTrayIndex= TRAYS.VapourSideStream.F;
1806        VapourDrawOff.T = TRAYS(VapourSideStreamLocation).VapourSideStream.T;
1807        VapourDrawOff.P = TRAYS(VapourSideStreamLocation).VapourSideStream.P;
1808        VapourDrawOff.z = TRAYS(VapourSideStreamLocation).VapourSideStream.z;
1809
1810        LiquidDrawOff.F*LiqSideTrayIndex= TRAYS.LiquidSideStream.F;
1811        LiquidDrawOff.T = TRAYS(LiquidSideStreamLocation).LiquidSideStream.T;
1812        LiquidDrawOff.P = TRAYS(LiquidSideStreamLocation).LiquidSideStream.P;
1813        LiquidDrawOff.z = TRAYS(LiquidSideStreamLocation).LiquidSideStream.z;
1814
1815        VapourDrawOffFlow = VapourDrawOff.F;
1816        LiquidDrawOffFlow = LiquidDrawOff.F;
1817
1818end
1819
1820Model ReactiveDistillation
1821       
1822ATTRIBUTES
1823        Pallete         = true;
1824        Icon            = "icon/DistillationReac";
1825        Brief           = "Model of a reactive distillation column with dynamic condenser and reboiler.";
1826        Info            =
1827"== Specify ==
1828* the reaction related variables for each tray, condenser and reboiler;
1829* the feed stream of each tray (Inlet);
1830* the Murphree eficiency for each tray Emv;
1831* the pump pressure difference;
1832* the heat supllied in reboiler and condenser;
1833* the condenser vapor outlet flow (OutletVapour.F);
1834* the reboiler liquid outlet flow (OutletLiquid.F);
1835* both splitter outlet flows OR one of the splitter outlet flows and the splitter frac.
1836       
1837== Initial Conditions ==
1838* the TRAYS temperature (OutletLiquid.T);
1839* the TRAYS liquid level (Level) OR the TRAYS liquid flow (OutletLiquid.F);
1840* (NoComps - 1) OutletLiquid (OR OutletVapour) compositions for each tray;
1841       
1842* the condenser temperature (OutletLiquid.T);
1843* the condenser liquid level (Level);
1844* (NoComps - 1) OutletLiquid (OR OutletVapour) compositions;
1845       
1846* the reboiler temperature (OutletLiquid.T);
1847* the reboiler liquid level (Level);
1848* (NoComps - 1) OutletLiquid (OR OutletVapour) compositions.
1849";
1850       
1851PARAMETERS
1852        outer PP        as Plugin       (Type="PP");
1853        outer NComp as Integer  (Brief="Number of Components");
1854#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1855# Section Column Feed Tray - Side Streams  Location and Numbering
1856#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1857        NumberOfTrays                                           as Integer      (Brief="Number of TRAYS", Default=2);
1858        FeedTrayIndex(NumberOfTrays)            as Integer      (Brief="Feed Tray Index", Default=0,Hidden=true);
1859        LiqSideTrayIndex(NumberOfTrays)         as Integer      (Brief="Liquid Side Tray Index", Default=0,Hidden=true);
1860        VapSideTrayIndex(NumberOfTrays)         as Integer      (Brief="Vapour Side Tray Index", Default=0,Hidden=true);
1861        FeedTrayLocation                                        as Integer      (Brief="Feed tray Location", Default=2);
1862        LiquidSideStreamLocation                        as Integer      (Brief="Liquid Side Stream Location", Default=2);
1863        VapourSideStreamLocation                        as Integer      (Brief="Vapour Side Stream Location", Default=2);
1864#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1865# Section Column Flow Model for Liquid and Vapour
1866#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1867        VapourFlow              as Switcher     (Valid = ["on", "off"], Default = "off",Hidden=true);
1868        TrayVapourFlow  as Switcher     (Valid = ["on", "off"], Default = "off",Hidden=true);
1869        TrayLiquidFlow  as Switcher     (Valid = ["on", "off"], Default = "off",Hidden=true);
1870        alfacond                as Real;
1871#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1872# Section Column Tray Geometry and Auxiliar Parameters
1873#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1874        V               as volume               (Brief="Total Volume of the tray",Hidden=true);
1875        Q               as power                (Brief="Rate of heat supply",Hidden=true);
1876        Ap              as area                 (Brief="Plate area = Atray - Adowncomer",Hidden=true);
1877        Ah              as area                 (Brief="Total holes area",Hidden=true);
1878        lw              as length               (Brief="Weir length",Hidden=true);
1879        g               as acceleration (Brief="Gravity Acceleration",Default=9.81,Hidden=true);
1880        hw              as length               (Brief="Weir height",Hidden=true);
1881        beta    as fraction     (Brief="Aeration fraction");
1882        alfa    as fraction     (Brief="Dry pressure drop coefficient");
1883
1884        VolumeOfTray            as volume               (Brief="Total Volume of the tray");
1885        HeatSupply                      as heat_rate    (Brief="Rate of heat supply");
1886        PlateArea                       as area                 (Brief="Plate area = Atray - Adowncomer");
1887        HolesArea                       as area                 (Brief="Total holes area");
1888        WeirLength                      as length               (Brief="Weir length");
1889        WeirHeight                      as length               (Brief="Weir height");
1890
1891        stoic(NComp)    as Real(Brief="Stoichiometric matrix");
1892        Hr                                              as energy_mol;
1893       
1894SET
1895
1896        FeedTrayIndex(FeedTrayLocation)         =1;
1897        VapSideTrayIndex(FeedTrayLocation)      =1;
1898        LiqSideTrayIndex(FeedTrayLocation)      =1;
1899
1900        V=VolumeOfTray;
1901        Q=HeatSupply;
1902        Ap=PlateArea;
1903        Ah=HolesArea;
1904        lw=WeirLength;
1905        hw=WeirHeight ;
1906       
1907VARIABLES
1908#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1909# Tray Initialization For the Whole Column Section
1910#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1911        INITIALIZATION          as InitializeSection    (Brief = "Column Model Initialization");
1912#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1913# Column Feed - Side Stream Flow and Murphree Efficiency
1914#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++     
1915        in      FeedTray                        as stream       (Brief="Feed stream", PosX=0, PosY=0.55);
1916                VapourDrawOffFlow       as flow_mol (Brief = "Stream Molar Flow Rate");
1917                LiquidDrawOffFlow   as flow_mol (Brief = "Stream Molar Flow Rate");
1918                MurphreeEff             as Real         (Brief = "Murphree efficiency");
1919#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1920# Column Vapour and Liquid Draw Sides
1921#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1922        out     VapourDrawOff   as vapour_stream        (Brief="Vapour Outlet in the section", PosX=1, PosY=0.395,Protected = true);
1923        out     LiquidDrawOff   as liquid_stream        (Brief="Liquid Outlet in the section", PosX=1, PosY=0.44,Protected = true);
1924#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1925# Heat Ports
1926#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1927        in      HeatToReboiler  as power (Brief="Heat supplied to Reboiler", PosX=1, PosY=0.89);
1928        in      HeatToCondenser as power (Brief="Heat supplied to Condenser", PosX=1, PosY=0.07);
1929#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1930# Column Devices
1931#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1932        TRAYS(NumberOfTrays)    as trayReac;
1933        CONDENSER                               as condenserReact;
1934        REBOILER                                as reboilerReact;
1935        SPLITTER                                as splitter2;
1936        PUMP                                    as pump;
1937#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1938# Column Outlets
1939#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1940        out     VapourDistillate        as vapour_stream        (Brief="Vapour outlet stream From Condenser", PosX=0.59, PosY=0);
1941        out     LiquidDistillate        as liquid_stream        (Brief="Liquid outlet stream From Splitter", PosX=1, PosY=0.23);
1942        out     BottomProduct           as liquid_stream        (Brief="Liquid outlet stream From Reboiler", PosX=0.67, PosY=1);
1943#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1944# Column Connectors
1945#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1946in      ConnectorCondenserVout  as stream       (Brief="Connector for Vapour outlet stream From Top Condenser", Hidden=true);
1947in      ConnectorSplitterOut    as stream       (Brief="Connector for Liquid outlet stream From Top Splitter", Hidden=true);
1948in      ConnectorReboilerLout   as stream       (Brief="Connector for Liquid outlet stream From Reboiler", Hidden=true);
1949#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1950# Column Control Ports
1951#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1952        out     TRI as control_signal   (Brief="Temperature of Reboiler Indicator", PosX=1, PosY=0.83);
1953        out     LRI as control_signal   (Brief="Level of Reboiler Indicator", PosX=1, PosY=0.855);
1954        out     TCI as control_signal   (Brief="Temperature of Condenser Indicator", PosX=1, PosY=0.01);
1955        out     LCI as control_signal   (Brief="Level of Condenser Indicator", PosX=1, PosY=0.04);
1956
1957CONNECTIONS
1958#vapor
1959        REBOILER.OutletVapour                                   to TRAYS(NumberOfTrays).InletVapour;
1960        TRAYS(1).OutletVapour                                   to CONDENSER.InletVapour;
1961        TRAYS([2:NumberOfTrays]).OutletVapour   to TRAYS([1:NumberOfTrays-1]).InletVapour;
1962
1963#liquid
1964        CONDENSER.OutletLiquid                                  to SPLITTER.Inlet;     
1965        SPLITTER.Outlet2                                        to PUMP.Inlet;
1966        PUMP.Outlet                                             to TRAYS(1).InletLiquid;
1967        TRAYS([1:NumberOfTrays-1]).OutletLiquid         to TRAYS([2:NumberOfTrays]).InletLiquid;
1968        TRAYS(NumberOfTrays).OutletLiquid               to REBOILER.InletLiquid;
1969
1970#Connectors
1971        CONDENSER.OutletVapour  to ConnectorCondenserVout;
1972        SPLITTER.Outlet1        to ConnectorSplitterOut;
1973        REBOILER.OutletLiquid   to ConnectorReboilerLout;
1974
1975INITIAL
1976#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1977# Tray Initialization
1978#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1979for i in 1:NumberOfTrays do
1980
1981"The initial temperature of the TRAYS"
1982        TRAYS(i).OutletLiquid.T = INITIALIZATION.TopTemperature+(INITIALIZATION.BottomTemperature-INITIALIZATION.TopTemperature)*((i-1)/(NumberOfTrays-1));
1983
1984"The initial Level of the TRAYS"
1985        TRAYS(i).Level = INITIALIZATION.LevelFraction*hw;
1986end
1987
1988for i in 1:NComp-1 do
1989
1990for j in 1:NumberOfTrays do
1991
1992"The initial composition of the TRAYS - Normalized"
1993        TRAYS(j).OutletLiquid.z(i) = INITIALIZATION.TopComposition(i)/sum(INITIALIZATION.TopComposition) +(INITIALIZATION.BottomComposition(i)/sum(INITIALIZATION.BottomComposition)-INITIALIZATION.TopComposition(i)/sum(INITIALIZATION.TopComposition) )*((j-1)/(NumberOfTrays-1));
1994end
1995
1996end
1997
1998EQUATIONS
1999
2000for i in [1:NumberOfTrays] do
2001
2002"Murphree Efficiency"
2003        TRAYS(i).OutletVapour.z =  MurphreeEff * (TRAYS(i).yideal - TRAYS(i).InletVapour.z) + TRAYS(i).InletVapour.z;
2004       
2005"Energy Holdup"
2006        TRAYS(i).E = TRAYS(i).ML*TRAYS(i).OutletLiquid.h + TRAYS(i).MV*TRAYS(i).OutletVapour.h - TRAYS(i).OutletLiquid.P*V;
2007
2008"Component Molar Balance"
2009        diff(TRAYS(i).M)=TRAYS(i).Inlet.F*TRAYS(i).Inlet.z + TRAYS(i).InletLiquid.F*TRAYS(i).InletLiquid.z + TRAYS(i).InletVapour.F*TRAYS(i).InletVapour.z- TRAYS(i).OutletLiquid.F*TRAYS(i).OutletLiquid.z - TRAYS(i).OutletVapour.F*TRAYS(i).OutletVapour.z-
2010        TRAYS(i).LiquidSideStream.F*TRAYS(i).LiquidSideStream.z-TRAYS(i).VapourSideStream.F*TRAYS(i).VapourSideStream.z + stoic*TRAYS(i).r3*TRAYS(i).ML*TRAYS(i).vL;
2011       
2012"Energy Balance"
2013        diff(TRAYS(i).E) = ( TRAYS(i).Inlet.F*TRAYS(i).Inlet.h + TRAYS(i).InletLiquid.F*TRAYS(i).InletLiquid.h + TRAYS(i).InletVapour.F*TRAYS(i).InletVapour.h- TRAYS(i).OutletLiquid.F*TRAYS(i).OutletLiquid.h - TRAYS(i).OutletVapour.F*TRAYS(i).OutletVapour.h
2014        -TRAYS(i).VapourSideStream.F*TRAYS(i).VapourSideStream.h - TRAYS(i).LiquidSideStream.F*TRAYS(i).LiquidSideStream.h + Q ) + Hr * TRAYS(i).r3 *TRAYS(i). vL*TRAYS(i).ML;
2015
2016"Level of clear liquid over the weir"
2017        TRAYS(i).Level = TRAYS(i).ML*TRAYS(i).vL/Ap;
2018
2019"Geometry Constraint"
2020        V = TRAYS(i).ML* TRAYS(i).vL + TRAYS(i).MV*TRAYS(i).vV;
2021
2022end
2023
2024switch VapourFlow
2025                case "on":
2026                "Pressure Drop through the condenser"
2027                CONDENSER.InletVapour.F*TRAYS(1).vV / 'm^2' =
2028                        sqrt((TRAYS(1).OutletVapour.P - CONDENSER.OutletLiquid.P + 1e-8 * 'atm')/(TRAYS(1).rhoV*alfacond));
2029                when TRAYS(1).OutletVapour.P < CONDENSER.OutletLiquid.P switchto "off";
2030               
2031                case "off":
2032                "Prato selado"
2033                CONDENSER.InletVapour.F = 0.0 * 'mol/s';
2034                when TRAYS(1).OutletVapour.P > CONDENSER.OutletLiquid.P + 1e-3 * 'atm' switchto "on";
2035        end
2036
2037for i in [1:NumberOfTrays] do
2038
2039        switch TrayLiquidFlow
2040                case "on":
2041                "Francis Equation"
2042                TRAYS(i).OutletLiquid.F*TRAYS(i).vL = 1.84*'1/s'*lw*((TRAYS(i).Level-(beta*hw)+1e-6*'m')/(beta))^2;
2043                when TRAYS(i).Level < (beta * hw) switchto "off";
2044               
2045                case "off":
2046                "Low level"
2047                TRAYS(i).OutletLiquid.F = 0 * 'mol/h';
2048                when TRAYS(i).Level > (beta * hw) + 1e-6*'m' switchto "on";
2049        end
2050
2051        switch TrayVapourFlow
2052                case "on":
2053                TRAYS(i).InletVapour.F*TRAYS(i).vV = sqrt((TRAYS(i).InletVapour.P - TRAYS(i).OutletVapour.P - TRAYS(i).Level*g*TRAYS(i).rhoL + 1e-8 * 'atm')/(TRAYS(i).rhoV*alfa))*Ah;
2054                when TRAYS(i).InletVapour.P < TRAYS(i).OutletVapour.P + TRAYS(i).Level*g*TRAYS(i).rhoL switchto "off";
2055               
2056                case "off":
2057                TRAYS(i).InletVapour.F = 0 * 'mol/s';
2058                when TRAYS(i).InletVapour.P > TRAYS(i).OutletVapour.P + TRAYS(i).Level*g*TRAYS(i).rhoL + 3e-2 * 'atm' switchto "on";
2059        end
2060
2061end
2062
2063# Connecting Trays
2064        FeedTray.F*FeedTrayIndex= TRAYS.Inlet.F;
2065        FeedTray.T = TRAYS.Inlet.T;
2066        FeedTray.P = TRAYS.Inlet.P;
2067        FeedTray.z = TRAYS.Inlet.z;
2068        FeedTray.v = TRAYS.Inlet.v;
2069        FeedTray.h = TRAYS.Inlet.h;
2070
2071        HeatToReboiler  = REBOILER.InletQ;
2072        HeatToCondenser = CONDENSER.InletQ;
2073
2074"Reboiler Temperature indicator"
2075        TRI * 'K' = REBOILER.OutletLiquid.T;
2076
2077"Reboiler Level indicator"
2078        LRI*REBOILER.V = REBOILER.Level*REBOILER.Across;
2079
2080"Condenser Temperature indicator"
2081        TCI * 'K' = CONDENSER.OutletLiquid.T;
2082
2083"Condenser Level indicator"
2084        LCI*CONDENSER.V = CONDENSER.Level*CONDENSER.Across;
2085
2086# Condenser Connector Equations
2087        ConnectorCondenserVout.T = VapourDistillate.T;
2088        ConnectorCondenserVout.P = VapourDistillate.P;
2089        ConnectorCondenserVout.F = VapourDistillate.F;
2090        ConnectorCondenserVout.z = VapourDistillate.z;
2091
2092# Splitter Connector Equations
2093        ConnectorSplitterOut.T = LiquidDistillate.T;
2094        ConnectorSplitterOut.P = LiquidDistillate.P;
2095        ConnectorSplitterOut.F = LiquidDistillate.F;
2096        ConnectorSplitterOut.z = LiquidDistillate.z;
2097
2098# Reboiler Connector Equations
2099        ConnectorReboilerLout.T = BottomProduct.T;
2100        ConnectorReboilerLout.P = BottomProduct.P;
2101        ConnectorReboilerLout.F = BottomProduct.F;
2102        ConnectorReboilerLout.z = BottomProduct.z;
2103
2104        VapourDrawOff.F*VapSideTrayIndex= TRAYS.VapourSideStream.F;
2105        VapourDrawOff.T = TRAYS(VapourSideStreamLocation).VapourSideStream.T;
2106        VapourDrawOff.P = TRAYS(VapourSideStreamLocation).VapourSideStream.P;
2107        VapourDrawOff.z = TRAYS(VapourSideStreamLocation).VapourSideStream.z;
2108
2109        LiquidDrawOff.F*LiqSideTrayIndex= TRAYS.LiquidSideStream.F;
2110        LiquidDrawOff.T = TRAYS(LiquidSideStreamLocation).LiquidSideStream.T;
2111        LiquidDrawOff.P = TRAYS(LiquidSideStreamLocation).LiquidSideStream.P;
2112        LiquidDrawOff.z = TRAYS(LiquidSideStreamLocation).LiquidSideStream.z;
2113
2114        VapourDrawOffFlow = VapourDrawOff.F;
2115        LiquidDrawOffFlow = LiquidDrawOff.F;
2116
2117end
2118
2119Model Packed_Section_ColumnBasic
2120        ATTRIBUTES
2121        Pallete         = false;
2122        Icon            = "icon/PackedSectionColumn";
2123        Brief           = "Model of a packed column section.";
2124        Info            =
2125"== Model of a packed column section containing ==
2126* NStages theoretical stages.
2127       
2128== Specify ==
2129* the feed stream of each tray (Inlet);
2130* the InletLiquid stream of the top tray;
2131* the InletVapour stream of the bottom tray;
2132* the total pressure drop (dP) of the section.
2133       
2134== Initial Conditions ==
2135* the stages temperature (OutletLiquid.T);
2136* the stages liquid holdup;
2137* (NoComps - 1) OutletLiquid (OR OutletVapour) compositions for each tray.
2138";
2139       
2140PARAMETERS
2141
2142        outer PP                as Plugin(Brief = "External Physical Properties", Type="PP");
2143        outer NComp     as Integer;
2144       
2145        NumberOfStages                                  as Integer      (Brief="Number of Stages", Default=3);
2146        FeedStageIndex(NumberOfStages)  as Integer      (Brief="Number of Stages", Default=0,Hidden=true);
2147        FeedStageLocation                               as Integer      (Brief="Feed Stage Location", Default=2);
2148       
2149        PackingHeight           as length               (Brief="Height of packing");
2150        HeatSupply                      as heat_rate    (Brief="Rate of heat supply");
2151        ColumnDiameter          as length               (Brief="Column diameter");
2152        VoidFraction            as Real                 (Brief="Void fraction of packing, m^3/m^3");
2153        ResistanceCoeff         as positive     (Brief="Resistance coefficient on the liquid load", Default=1);
2154        AreaPerPackingVol       as Real                 (Brief="surface area per packing volume", Unit='m^2/m^3');
2155       
2156        V                               as volume               (Brief="Total Volume of the tray",Hidden=true);
2157        g                               as acceleration (Brief="Gravity Acceleration",Default=9.81,Hidden=true);
2158        hs                              as length               (Brief="Height of the packing stage",Hidden=true);
2159        ColumnArea              as area                 (Brief="Column Sectional Cross Area",Hidden=true);
2160
2161VARIABLES
2162#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2163# Stages Initialization For the Whole Column Section
2164#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2165        INITIALIZATION          as InitializeStage      (Brief = "Column Model Initialization");
2166        in      FeedStage       as stream               (Brief="Feed stream", PosX=0, PosY=0.55);
2167       
2168        STAGES(NumberOfStages) as packedStage;
2169        PressureDrop               as pressure;
2170       
2171SET
2172        FeedStageIndex(FeedStageLocation) =1;
2173       
2174        ColumnArea = ColumnDiameter^2*3.14159*0.25;
2175        hs =PackingHeight/NumberOfStages;       
2176        V = hs * ColumnArea;
2177       
2178CONNECTIONS
2179
2180        STAGES([2:NumberOfStages]).OutletVapour                 to STAGES([1:NumberOfStages-1]).InletVapour;
2181        STAGES([1:NumberOfStages-1]).OutletLiquid       to STAGES([2:NumberOfStages]).InletLiquid;
2182
2183EQUATIONS
2184# Connecting STAGES
2185        FeedStage.F*FeedStageIndex= STAGES.Inlet.F;
2186        FeedStage.T = STAGES.Inlet.T;
2187        FeedStage.P = STAGES.Inlet.P;
2188        FeedStage.z = STAGES.Inlet.z;
2189        FeedStage.v = STAGES.Inlet.v;
2190        FeedStage.h = STAGES.Inlet.h;
2191
2192        STAGES.deltaP = PressureDrop/NumberOfStages;
2193
2194for i in [1:NumberOfStages] do
2195
2196"Energy Balance"
2197        diff(STAGES(i).E) = ( STAGES(i).Inlet.F*STAGES(i).Inlet.h + STAGES(i).InletLiquid.F*STAGES(i).InletLiquid.h + STAGES(i).InletVapour.F*STAGES(i).InletVapour.h- STAGES(i).OutletLiquid.F*STAGES(i).OutletLiquid.h
2198        - STAGES(i).OutletVapour.F*STAGES(i).OutletVapour.h + HeatSupply );
2199       
2200"Energy Holdup"
2201        STAGES(i).E = STAGES(i).ML*STAGES(i).OutletLiquid.h + STAGES(i).MV*STAGES(i).OutletVapour.h - STAGES(i).OutletLiquid.P*V;
2202       
2203"Geometry Constraint"
2204        V*VoidFraction= STAGES(i).ML*STAGES(i).vL + STAGES(i).MV*STAGES(i).vV;
2205       
2206"Volume flow rate of vapor, m^3/m^2/s"
2207        STAGES(i).uV * ((ColumnArea)*VoidFraction - STAGES(i).Al) = STAGES(i).OutletVapour.F * STAGES(i).vV;
2208       
2209"Liquid holdup"
2210        STAGES(i).hl = STAGES(i).ML*STAGES(i).vL/V/VoidFraction;
2211       
2212"Particle diameter"
2213        STAGES(i).dp = 6 * (1-VoidFraction)/AreaPerPackingVol;
2214       
2215"Wall Factor"
2216        STAGES(i).invK = (1 + (2*STAGES(i).dp/(3*ColumnDiameter*(1-VoidFraction))));
2217       
2218"Reynolds number of the vapor stream"
2219        STAGES(i).Rev*STAGES(i).invK = STAGES(i).dp*STAGES(i).uV*STAGES(i).rhoV / (STAGES(i).miV*(1-VoidFraction));
2220       
2221"Pressure drop and Vapor flow"
2222        STAGES(i).deltaP/hs  = ResistanceCoeff*AreaPerPackingVol*STAGES(i).uV^2*STAGES(i).rhoV*STAGES(i).invK / (2*(VoidFraction-STAGES(i).hl)^3);
2223
2224"Liquid holdup"
2225        STAGES(i).hl = (12*STAGES(i).miL*AreaPerPackingVol^2*STAGES(i).uL/STAGES(i).rhoL/g)^1/3;
2226
2227"Area occupied by the liquid"
2228        STAGES(i).Al = STAGES(i).ML*STAGES(i).vL/hs;
2229
2230end
2231
2232INITIAL
2233
2234for i in 1:NumberOfStages do
2235
2236"The initial temperature of the STAGES"
2237        STAGES(i).OutletLiquid.T = INITIALIZATION.TopStageTemperature+(INITIALIZATION.BottomStageTemperature-INITIALIZATION.TopStageTemperature)*((i-1)/(NumberOfStages-1));
2238
2239"The Liquid Holdup of the STAGES"
2240        STAGES(i).ML = INITIALIZATION.LiquidMolarHoldup;
2241
2242end
2243
2244for i in 1:NComp-1 do
2245       
2246for j in 1:NumberOfStages do
2247
2248"The initial composition of the TRAYS"
2249        STAGES(j).OutletLiquid.z(i) = INITIALIZATION.TopStageComposition(i)/sum(INITIALIZATION.TopStageComposition) +(INITIALIZATION.BottomStageComposition(i)/sum(INITIALIZATION.BottomStageComposition)-INITIALIZATION.TopStageComposition(i)/sum(INITIALIZATION.TopStageComposition) )*((j-1)/(NumberOfStages-1));
2250
2251end
2252
2253end
2254
2255end
2256
2257Model Packed_Section_Column as Packed_Section_ColumnBasic
2258
2259        ATTRIBUTES
2260        Pallete         = true;
2261        Icon            = "icon/PackedSectionColumn";
2262        Brief           = "Model of a packed column section.";
2263        Info            =
2264"== Model of a packed column section containing ==
2265* NStages theoretical stages.
2266       
2267== Specify ==
2268* the feed stream of each tray (Inlet);
2269* the InletLiquid stream of the top tray;
2270* the InletVapour stream of the bottom tray;
2271* the total pressure drop (dP) of the section.
2272       
2273== Initial Conditions ==
2274* the stages temperature (OutletLiquid.T);
2275* the stages liquid holdup;
2276* (NoComps - 1) OutletLiquid (OR OutletVapour) compositions for each tray.
2277";
2278
2279VARIABLES
2280
2281        in              LiquidInlet             as      stream                          (Brief="Liquid Inlet in the section", PosX=0.70, PosY=0);
2282        out     VapourOutlet            as vapour_stream        (Brief="Vapour Outlet in the section", PosX=0.30, PosY=0);
2283       
2284        in              VapourInlet             as stream                               (Brief="Vapour Inlet in the section", PosX=0.30, PosY=1);
2285        out     LiquidOutlet            as liquid_stream                (Brief="Liquid Outlet in the section", PosX=0.70, PosY=1);
2286       
2287        LiquidConnector as stream       (Brief="Liquid connection at the middle STAGES", PosX=0.75, PosY=1,Hidden=true);
2288        VapourConnector as stream       (Brief="Vapour connection at the middle STAGES", PosX=0.55, PosY=0,Hidden=true);
2289
2290CONNECTIONS
2291
2292        LiquidConnector to STAGES(1).InletLiquid;
2293        VapourConnector to STAGES(NumberOfStages).InletVapour;
2294       
2295EQUATIONS
2296
2297        LiquidConnector.F= LiquidInlet.F;
2298        LiquidConnector.T = LiquidInlet.T;
2299        LiquidConnector.P = LiquidInlet.P;
2300        LiquidConnector.z = LiquidInlet.z;
2301        LiquidConnector.v = LiquidInlet.v;
2302        LiquidConnector.h = LiquidInlet.h;
2303       
2304        VapourConnector.F= VapourInlet.F;
2305        VapourConnector.T = VapourInlet.T;
2306        VapourConnector.P = VapourInlet.P;
2307        VapourConnector.z = VapourInlet.z;
2308        VapourConnector.v = VapourInlet.v;
2309        VapourConnector.h = VapourInlet.h;
2310       
2311        LiquidOutlet.F= STAGES(NumberOfStages).OutletLiquid.F;
2312        LiquidOutlet.T = STAGES(NumberOfStages).OutletLiquid.T;
2313        LiquidOutlet.P = STAGES(NumberOfStages).OutletLiquid.P;
2314        LiquidOutlet.z = STAGES(NumberOfStages).OutletLiquid.z;
2315       
2316        VapourOutlet.F= STAGES(1).OutletVapour.F;
2317        VapourOutlet.T = STAGES(1).OutletVapour.T;
2318        VapourOutlet.P = STAGES(1).OutletVapour.P;
2319        VapourOutlet.z = STAGES(1).OutletVapour.z;
2320
2321end
2322
2323Model PackedDistillation_kettle_cond as Packed_Section_ColumnBasic
2324        ATTRIBUTES
2325        Pallete         = true;
2326        Icon            = "icon/PackedDistillationKettleCond";
2327        Brief           = "Model of a distillation column with dynamic condenser and dynamic reboiler.";
2328        Info            =
2329"== Specify ==
2330* the feed stream of each tray (Inlet);
2331* the pump pressure difference;
2332* the total pressure drop (dP) of the packing;
2333* the heat supllied in reboiler and condenser;
2334* the condenser vapor outlet flow (OutletVapour.F);
2335* the reboiler liquid outlet flow (OutletLiquid.F);
2336* both splitter outlet flows OR one of the splitter outlet flows and the splitter frac.
2337       
2338== Initial Conditions ==
2339* the stages temperature (OutletLiquid.T);
2340* the stages initial molar holdup;
2341* (NoComps - 1) OutletLiquid (OR OutletVapour) compositions for each stage;
2342       
2343* the condenser temperature (OutletLiquid.T);
2344* the condenser liquid level (Level);
2345* (NoComps - 1) OutletLiquid (OR OutletVapour) compositions;
2346       
2347* the reboiler temperature (OutletLiquid.T);
2348* the reboiler liquid level (Level);
2349* (NoComps - 1) OutletLiquid (OR OutletVapour) compositions.
2350";
2351       
2352PARAMETERS
2353
2354        VapourFlow as Switcher  (Valid = ["on", "off"], Hidden = true ,Default = "on");
2355       
2356VARIABLES
2357#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2358# Column Devices
2359#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++     
2360        CONDENSER       as condenser    (Brief="dymamic condenser");
2361        REBOILER        as reboiler             (Brief="kettle reboiler");
2362        SPLITTER        as splitter2            (Brief="splitter which separate reflux and distillate");
2363        PUMP            as pump                 (Brief="pump in reflux stream");
2364#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2365# Heat Ports
2366#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++     
2367        in      HeatToReboiler  as power (Brief="Heat supplied to Reboiler",Protected = true, PosX=1, PosY=0.885);
2368        in      HeatToCondenser as power (Brief="Heat supplied to Condenser", Protected = true, PosX=1, PosY=0.034);
2369#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2370# Column Products
2371#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++     
2372        out     VapourDistillate        as vapour_stream        (Brief="Vapour outlet stream From Top Condenser", PosX=0.66, PosY=0);
2373        out     LiquidDistillate        as liquid_stream        (Brief="Liquid outlet stream From Top Splitter", PosX=1, PosY=0.20);
2374        out     BottomProduct           as liquid_stream        (Brief="Liquid outlet stream From Reboiler", PosX=0.68, PosY=1);
2375#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2376# Column Connectors
2377#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++             
2378        in      ConnectorCondenserVout  as stream       (Brief="Connector for Vapour outlet stream From Top Condenser", Hidden=true);
2379        in      ConnectorSplitterOut    as stream       (Brief="Connector for Liquid outlet stream From Top Splitter", Hidden=true);
2380        in      ConnectorReboilerLout   as stream       (Brief="Connector for Liquid outlet stream From Reboiler", Hidden=true);
2381                ConnectorHeatReboiler   as power        (Brief="Heat supplied to Reboiler", Hidden=true);
2382                ConnectorHeatCondenser  as power        (Brief="Heat supplied to Condenser", Hidden=true);
2383
2384CONNECTIONS
2385
2386#vapor
2387        REBOILER.OutletVapour           to STAGES(NumberOfStages).InletVapour;
2388        STAGES(1).OutletVapour          to CONDENSER.InletVapour;
2389
2390#liquid
2391        CONDENSER.OutletLiquid                          to SPLITTER.Inlet;     
2392        SPLITTER.Outlet2                                to PUMP.Inlet;
2393        PUMP.Outlet                                     to STAGES(1).InletLiquid;
2394        STAGES(NumberOfStages).OutletLiquid     to REBOILER.InletLiquid;
2395
2396#Connectors
2397ConnectorHeatReboiler   to REBOILER.InletQ;
2398ConnectorHeatCondenser  to CONDENSER.InletQ;
2399
2400CONDENSER.OutletVapour          to ConnectorCondenserVout;
2401SPLITTER.Outlet1                to ConnectorSplitterOut;
2402REBOILER.OutletLiquid           to ConnectorReboilerLout;
2403
2404EQUATIONS
2405        HeatToReboiler  = ConnectorHeatReboiler;
2406        HeatToCondenser = ConnectorHeatCondenser;
2407       
2408# Condenser Connector Equations
2409        ConnectorCondenserVout.T = VapourDistillate.T;
2410        ConnectorCondenserVout.P = VapourDistillate.P;
2411        ConnectorCondenserVout.F = VapourDistillate.F;
2412        ConnectorCondenserVout.z = VapourDistillate.z;
2413
2414# Splitter Connector Equations
2415        ConnectorSplitterOut.T = LiquidDistillate.T;
2416        ConnectorSplitterOut.P = LiquidDistillate.P;
2417        ConnectorSplitterOut.F = LiquidDistillate.F;
2418        ConnectorSplitterOut.z = LiquidDistillate.z;
2419
2420# Reboiler Connector Equations
2421        ConnectorReboilerLout.T = BottomProduct.T;
2422        ConnectorReboilerLout.P = BottomProduct.P;
2423        ConnectorReboilerLout.F = BottomProduct.F;
2424        ConnectorReboilerLout.z = BottomProduct.z;
2425
2426switch VapourFlow
2427        case "on":
2428                STAGES(NumberOfStages).InletVapour.F*STAGES(NumberOfStages).vV = sqrt((REBOILER.OutletVapour.P - STAGES(NumberOfStages).OutletVapour.P)/
2429                                        (STAGES(NumberOfStages).rhoV*ResistanceCoeff*20))*(ColumnArea*VoidFraction - STAGES(NumberOfStages).Al);
2430                when STAGES(NumberOfStages).InletVapour.F < 1e-6 * 'kmol/h' switchto "off";
2431
2432        case "off":
2433                STAGES(NumberOfStages).InletVapour.F = 0 * 'mol/s';
2434                when REBOILER.OutletVapour.P > STAGES(NumberOfStages).OutletVapour.P + 1e-1 * 'atm' switchto "on";
2435end
2436
2437end
2438
Note: See TracBrowser for help on using the repository browser.