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

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

added control ports for packed column model

File size: 107.6 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        ColumnHoldup                                    as positive (Brief = "Column holdup", Default=0.1);
87
88end
89
90
91Model SectionColumnBasic
92
93ATTRIBUTES
94        Pallete = false;
95        Brief   = "Model of a basic column section.";
96        Info    =
97"Model of a basic column section containing a vetor of TRAYS numbered from the top-down.";
98
99PARAMETERS
100        outer PP                as Plugin               (Brief="External Physical Properties", Type="PP");
101        outer NComp     as Integer              (Brief="Number of components");
102
103        NumberOfFeeds                                           as Integer                      (Brief="Number of Feed Trays",Default=3,Protected=true);
104        FeedTrayLocation(NumberOfFeeds)         as Integer                      (Brief="Feed tray Location",Default=2);
105        NumberOfTrays                                           as Integer                      (Brief="Number of trays", Default=8);
106        LiqSideTrayIndex(NumberOfTrays)         as Integer                      (Brief="Liquid Side Tray Index", Default=0,Hidden=true);
107        VapSideTrayIndex(NumberOfTrays)         as Integer                      (Brief="Vapour Side Tray Index", Default=0,Hidden=true);
108
109        LiquidSideStreamLocation                        as Integer                      (Brief="Liquid Side Stream Location", Default=2);
110        VapourSideStreamLocation                        as Integer                      (Brief="Vapour Side Stream Location", Default=2);
111        Pi                                                                      as constant             (Brief="Pi Number",Default=3.14159265, Symbol = "\pi",Hidden=true);
112        Gconst                                                          as acceleration         (Brief="Gravity Acceleration",Default=9.81,Hidden=true);
113        Mw(NComp)                                                       as molweight            (Brief="Component Mol Weight",Hidden=true);
114        zero_flow                                                       as flow_mol             (Brief = "Stream Flow closed",Default = 0, Hidden=true);
115        low_flow                                                        as flow_mol             (Brief = "Low stream Flow",Default = 1E-6, Hidden=true);
116
117        VapourFlowModel         as Switcher     (Valid = ["Reepmeyer", "Feehery_Fv", "Roffel_Fv", "Klingberg", "Wang_Fv", "Elgue"], Default = "Reepmeyer");
118        LiquidFlowModel         as Switcher     (Valid = ["Francis", "Wang_Fl", "Olsen", "Feehery_Fl", "Roffel_Fl"], Default = "Francis");
119
120        TrayDiameter                    as length               (Brief="Tray Diameter",Default=1.600);
121        TraySpacing                             as length               (Brief="Tray Spacing",Default=0.600);
122        Fraction_HoleArea               as fraction     (Brief="Fraction of the active area that is occupied by the holes with respect to the total tray area",Default=0.10);
123        Fraction_DowncomerArea  as fraction     (Brief="Fraction of the downcomer area with respect to the total tray area",Default=0.20);
124        WeirLength                              as length               (Brief="Weir length", Default = 1);
125        WeirHeight                              as length               (Brief="Weir height", Default= 0.05);
126        TrayLiquidPasses                as positive     (Brief="Number of liquid passes in the tray", Lower = 1,Default=1);
127        HeatSupply                              as heat_rate    (Brief="Rate of heat supply",Default = 0);
128        AerationFraction                as Real                 (Brief="Aeration fraction", Default = 1);
129        DryPdropCoeff                   as Real                 (Brief="Dry pressure drop coefficient", Default= 0.60);
130       
131        PlateArea               as area         (Brief="Plate area = Atray - Adowncomer",Protected=true);
132        TrayVolume              as volume       (Brief="Total Volume of the tray",Protected=true);
133        HolesArea               as area         (Brief="Total holes area",Protected=true);
134
135        FeeheryCoeff    as Real         (Brief="Feeherys correlation coefficient", Unit='1/m^4', Default=1,Hidden=true);
136        ElgueCoeff              as Real         (Brief="Elgues correlation coefficient", Unit='kg/m/mol^2', Default=1,Hidden=true);
137        OlsenCoeff              as Real         (Brief="Olsens correlation coefficient", Default=1,Hidden=true);
138       
139        VapourFlow      as Switcher     (Brief="Flag for Vapour Flow condition",Valid = ["on", "off"], Default = "off",Hidden=true);
140        LiquidFlow      as Switcher     (Brief="Flag for Liquid Flow condition",Valid = ["on", "off"], Default = "off",Hidden=true);
141
142SET
143        VapSideTrayIndex(VapourSideStreamLocation) =1;
144        LiqSideTrayIndex(LiquidSideStreamLocation) =1;
145        Mw = PP.MolecularWeight();
146        zero_flow = 0 * 'kmol/h';
147        low_flow = 1E-6 * 'kmol/h';
148
149        PlateArea = 0.25*Pi*(TrayDiameter^2)*(1-Fraction_DowncomerArea);
150        TrayVolume = 0.25*Pi*(TrayDiameter^2)*TraySpacing;
151        HolesArea = 0.25*Pi*(TrayDiameter^2)*Fraction_HoleArea;
152
153VARIABLES
154
155        INITIALIZATION as InitializeSection (Brief="Column Model Initialization");
156        CONTROL                 as ControlSection (Brief="Column Model Control");
157       
158        out     TCI as control_signal   (Brief="Temperature  Indicator", Protected = true, PosX=1, PosY=0.73);
159        out     PCI as control_signal   (Brief="Pressure Indicator", Protected = true, PosX=0, PosY=0.24);
160       
161    in  LiquidInlet     as stream         (Brief="Liquid Inlet in the section", PosX=0.70, PosY=0);
162    out VapourOutlet    as vapour_stream  (Brief="Vapour Outlet in the section", PosX=0.30, PosY=0);
163
164    out VapourDrawOff   as vapour_stream  (Brief="Vapour Draw Off Port in the section", PosX=1, PosY=0.35,Protected = true);
165        out LiquidDrawOff   as liquid_stream  (Brief="Liquid Draw Off Port in the section", PosX=1, PosY=0.65,Protected = true);
166       
167        TRAYS(NumberOfTrays)    as tray                 (Brief="Number of trays in the Column Section",Protected=true);
168        VapourDrawOffFlow               as flow_mol     (Brief="Vapour Draw Off Stream Molar Flow Rate");
169        LiquidDrawOffFlow               as flow_mol     (Brief="Vapour Draw Off Stream Molar Flow Rate");
170        MurphreeEff                     as Real                 (Brief="Murphree efficiency for All Trays",Lower=0.01,Upper=1);
171
172        in      VapourInlet     as stream             (Brief="Vapour Inlet in the section", PosX=0.30, PosY=1);
173        out     LiquidOutlet    as liquid_stream      (Brief="Liquid Outlet in the section", PosX=0.70, PosY=1);
174       
175        LiquidConnector as stream    (Brief="Liquid connection in the middle TRAYS", PosX=0.75, PosY=1,Hidden=true);
176        VapourConnector as stream    (Brief="Vapour connection in the middle TRAYS", PosX=0.55, PosY=0,Hidden=true);
177       
178CONNECTIONS
179        TRAYS([2:NumberOfTrays]).OutletVapour   to TRAYS([1:NumberOfTrays-1]).InletVapour;
180        TRAYS([1:NumberOfTrays-1]).OutletLiquid to TRAYS([2:NumberOfTrays]).InletLiquid;
181       
182    LiquidConnector to TRAYS(1).InletLiquid;
183    VapourConnector to TRAYS(NumberOfTrays).InletVapour;
184       
185INITIAL
186
187for i in 1:NumberOfTrays do
188
189"The initial temperature of the TRAYS"
190        TRAYS(i).OutletLiquid.T = INITIALIZATION.TopTemperature+(INITIALIZATION.BottomTemperature-INITIALIZATION.TopTemperature)*((i-1)/(NumberOfTrays-1));
191
192"The initial Level of the TRAYS"
193        TRAYS(i).Level = INITIALIZATION.LevelFraction*WeirHeight;
194end
195
196for i in 1:NComp-1 do
197
198for j in 1:NumberOfTrays do
199
200"The initial composition of the TRAYS - Normalized"
201        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));
202end
203
204end
205
206EQUATIONS
207
208"Tray Temperature Indicator"   
209        #TCI*'K' = TRAYS(min([NumberOfTrays, CONTROL.Tindicator_TrayNumber])).OutletVapour.T;
210        TCI*'K' = TRAYS(CONTROL.Tindicator_TrayNumber).OutletVapour.T;
211
212"Tray Pressure Indicator"       
213        #PCI*'atm' = TRAYS(min([NumberOfTrays, CONTROL.Pindicator_TrayNumber])).OutletVapour.P;
214        PCI*'atm' = TRAYS(CONTROL.Pindicator_TrayNumber).OutletVapour.P;
215
216for i in [1:NumberOfTrays] do
217
218"Murphree Efficiency"
219        TRAYS(i).OutletVapour.z =  MurphreeEff * (TRAYS(i).yideal - TRAYS(i).InletVapour.z) + TRAYS(i).InletVapour.z;
220
221"Level of clear liquid over the weir"
222        TRAYS(i).Level = TRAYS(i).ML*TRAYS(i).vL/PlateArea;
223
224"Geometry Constraint"
225        TrayVolume = TRAYS(i).ML* TRAYS(i).vL + TRAYS(i).MV*TRAYS(i).vV;
226
227"Energy Holdup"
228        TRAYS(i).E = TRAYS(i).ML*TRAYS(i).OutletLiquid.h + TRAYS(i).MV*TRAYS(i).OutletVapour.h - TRAYS(i).OutletLiquid.P*TrayVolume;
229
230"Energy Balance"
231        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
232        -TRAYS(i).VapourSideStream.F*TRAYS(i).VapourSideStream.h - TRAYS(i).LiquidSideStream.F*TRAYS(i).LiquidSideStream.h + HeatSupply );
233
234switch LiquidFlow
235                case "on":
236                        switch LiquidFlowModel
237                                case "Francis":
238                                "Francis Equation"
239                                TRAYS(i).OutletLiquid.F*TRAYS(i).vL = 1.84*'1/s'*WeirLength*((TRAYS(i).Level-(AerationFraction*WeirHeight))/(AerationFraction))^2;
240                       
241                                case "Wang_Fl":
242                                TRAYS(i).OutletLiquid.F*TRAYS(i).vL = 1.84*'m^0.5/s'*WeirLength*((TRAYS(i).Level-(AerationFraction*WeirHeight))/(AerationFraction))^1.5;
243                       
244                                case "Olsen":
245                                TRAYS(i).OutletLiquid.F / 'mol/s'= WeirLength*TrayLiquidPasses*TRAYS(i).rhoL/sum(Mw*TRAYS(i).OutletVapour.z)/(0.665*OlsenCoeff)^1.5 * ((TRAYS(i).ML*sum(Mw*TRAYS(i).OutletLiquid.z)/TRAYS(i).rhoL/PlateArea)-WeirHeight)^1.5 * 'm^0.5/mol';
246                       
247                                case "Feehery_Fl":
248                                TRAYS(i).OutletLiquid.F = WeirLength*TRAYS(i).rhoL/sum(Mw*TRAYS(i).OutletLiquid.z) * ((TRAYS(i).Level-WeirHeight)/750/'mm')^1.5 * 'm^2/s';
249                       
250                                case "Roffel_Fl":
251                                TRAYS(i).OutletLiquid.F = 2/3*TRAYS(i).rhoL/sum(Mw*TRAYS(i).OutletLiquid.z)*WeirLength*(TRAYS(i).ML*sum(Mw*TRAYS(i).OutletLiquid.z)/(PlateArea*1.3)/TRAYS(i).rhoL)^1.5*sqrt(2*Gconst/
252                                                        (2*(1 - 0.3593/'Pa^0.0888545'*abs(TRAYS(i).OutletVapour.F*sum(Mw*TRAYS(i).OutletVapour.z)/(PlateArea*1.3)/sqrt(TRAYS(i).rhoV))^0.177709)-1)); #/'(kg/m)^0.0888545/s^0.177709';
253                        end
254                when TRAYS(i).Level < (AerationFraction *WeirHeight) switchto "off";
255               
256                case "off":
257               
258                "Low level"
259                TRAYS(i).OutletLiquid.F = zero_flow;
260               
261                when TRAYS(i).Level > (AerationFraction * WeirHeight) switchto "on";
262               
263        end
264       
265switch VapourFlow
266                case "on":
267                        switch VapourFlowModel
268                                case "Reepmeyer":
269                                TRAYS(i).InletVapour.F*TRAYS(i).vV = sqrt((TRAYS(i).InletVapour.P - TRAYS(i).OutletVapour.P)/(TRAYS(i).rhoV*DryPdropCoeff))*HolesArea;
270                       
271                                case "Feehery_Fv":
272                                TRAYS(i).InletVapour.F = TRAYS(i).rhoV/PlateArea/FeeheryCoeff/sum(Mw*TRAYS(i).OutletVapour.z) * sqrt(((TRAYS(i).InletVapour.P - TRAYS(i).OutletVapour.P)-(TRAYS(i).rhoV*Gconst*TRAYS(i).ML*TRAYS(i).vL/PlateArea))/TRAYS(i).rhoV);
273                       
274                                case "Roffel_Fv":
275                                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 - (AerationFraction*sum(TRAYS(i).M*Mw)/(PlateArea*1.3)*Gconst*1e5) * (TRAYS(i).rhoV*HolesArea/sum(Mw*TRAYS(i).OutletVapour.z))^1.08 * 'm^1.08/mol^1.08';
276                       
277                                case "Klingberg":
278                                TRAYS(i).InletVapour.F * TRAYS(i).vV = PlateArea * sqrt(((TRAYS(i).InletVapour.P - TRAYS(i).OutletVapour.P)-TRAYS(i).rhoL*Gconst*TRAYS(i).Level)/TRAYS(i).rhoV);
279                       
280                                case "Wang_Fv":
281                                TRAYS(i).InletVapour.F * TRAYS(i).vV = PlateArea * sqrt(((TRAYS(i).InletVapour.P - TRAYS(i).OutletVapour.P)-TRAYS(i).rhoL*Gconst*TRAYS(i).Level)/TRAYS(i).rhoV*DryPdropCoeff);
282                               
283                                case "Elgue":
284                                TRAYS(i).InletVapour.F  = sqrt((TRAYS(i).InletVapour.P - TRAYS(i).OutletVapour.P)/ElgueCoeff);
285                        end
286                when TRAYS(i).InletVapour.F < low_flow switchto "off";
287               
288                case "off":
289                TRAYS(i).InletVapour.F = zero_flow;
290               
291                when TRAYS(i).InletVapour.P > TRAYS(i).OutletVapour.P switchto "on";
292               
293        end
294
295end
296
297"Liquid Inlet Flow"     
298        LiquidConnector.F = LiquidInlet.F;
299
300"Liquid Inlet Temperature"             
301        LiquidConnector.T = LiquidInlet.T;
302
303"Liquid Inlet Pressure"         
304        LiquidConnector.P = LiquidInlet.P;
305
306"Liquid Inlet Composition"             
307        LiquidConnector.z = LiquidInlet.z;
308
309"Liquid Inlet Vapour Fraction"         
310        LiquidConnector.v = LiquidInlet.v;
311
312"Liquid Inlet Enthalpy"         
313        LiquidConnector.h = LiquidInlet.h;
314
315"Vapour Inlet Flow"             
316        VapourConnector.F = VapourInlet.F;
317
318"Vapour Inlet Temperature"             
319        VapourConnector.T = VapourInlet.T;
320
321"Vapour Inlet Pressure"         
322        VapourConnector.P = VapourInlet.P;
323
324"Vapour Inlet Composition"             
325        VapourConnector.z = VapourInlet.z;
326
327"Vapour Inlet Vapour Fraction"         
328        VapourConnector.v = VapourInlet.v;
329
330"Vapour Inlet Enthalpy"         
331        VapourConnector.h = VapourInlet.h;
332
333"Liquid Outlet Flow"   
334        LiquidOutlet.F = TRAYS(NumberOfTrays).OutletLiquid.F;
335
336"Liquid Outlet Temperature"     
337        LiquidOutlet.T = TRAYS(NumberOfTrays).OutletLiquid.T;
338
339"Liquid Outlet Pressure"       
340        LiquidOutlet.P = TRAYS(NumberOfTrays).OutletLiquid.P;
341
342"Liquid Outlet Composition"     
343        LiquidOutlet.z = TRAYS(NumberOfTrays).OutletLiquid.z;
344
345"Vapour Outlet Flow"           
346        VapourOutlet.F = TRAYS(1).OutletVapour.F;
347
348"Vapour Outlet Temperature"             
349        VapourOutlet.T = TRAYS(1).OutletVapour.T;
350
351"Vapour Outlet Pressure"               
352        VapourOutlet.P = TRAYS(1).OutletVapour.P;
353
354"Vapour Outlet Composition"             
355        VapourOutlet.z = TRAYS(1).OutletVapour.z;
356
357"Vapour Draw Off Stream - Flow"         
358        VapourDrawOff.F*VapSideTrayIndex= TRAYS.VapourSideStream.F;
359
360"Vapour Draw Off Stream - Temperature"         
361        VapourDrawOff.T = TRAYS(VapourSideStreamLocation).VapourSideStream.T;
362
363"Vapour Draw Off Stream - Pressure"             
364        VapourDrawOff.P = TRAYS(VapourSideStreamLocation).VapourSideStream.P;
365
366"Vapour Draw Off Stream - Composition"         
367        VapourDrawOff.z = TRAYS(VapourSideStreamLocation).VapourSideStream.z;
368
369"Vapour Draw Off Stream"       
370        VapourDrawOffFlow = VapourDrawOff.F;
371
372"Liquid Draw Off Stream - Flow"         
373        LiquidDrawOff.F*LiqSideTrayIndex= TRAYS.LiquidSideStream.F;
374
375"Liquid Draw Off Stream - Temperature" 
376        LiquidDrawOff.T = TRAYS(LiquidSideStreamLocation).LiquidSideStream.T;
377
378"Liquid Draw Off Stream - Pressure"                     
379        LiquidDrawOff.P = TRAYS(LiquidSideStreamLocation).LiquidSideStream.P;
380
381"Liquid Draw Off Stream - Composition" 
382        LiquidDrawOff.z = TRAYS(LiquidSideStreamLocation).LiquidSideStream.z;
383
384"Liquid Draw Off Stream"       
385        LiquidDrawOffFlow = LiquidDrawOff.F;
386
387end
388
389Model Section_Column    as SectionColumnBasic
390
391ATTRIBUTES
392        Pallete         = true;
393        Icon            = "icon/SectionColumn";
394        Brief   = "Model of a column section.";
395        Info            =
396"== Model of a column section containing ==
397* NumberOfTrays TRAYS.
398* One Feed Inlet.
399       
400== Specify ==
401* the feed stream of each tray (Inlet);
402* the Murphree eficiency for each tray Emv;
403* the InletLiquid stream of the top tray;
404* the InletVapour stream of the bottom tray.
405       
406== Initial Conditions ==
407* the TRAYS temperature (OutletLiquid.T);
408* the TRAYS liquid level (Level) OR the TRAYS liquid flow (OutletLiquid.F);
409* (NoComps - 1) OutletLiquid (OR OutletVapour) compositions for each tray.
410";
411
412SET
413        NumberOfFeeds = 1;
414
415VARIABLES
416       
417        in      FeedTray        as stream               (Brief="Feed stream", PosX=0, PosY=0.55);
418
419EQUATIONS
420#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
421# Equating Feed Tray Variables to Trays Variables
422#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
423for i in 1:NumberOfTrays do
424
425if   i equal FeedTrayLocation(1) then   
426
427"FeedTrayTop Inlet Flow"       
428        FeedTray.F= TRAYS(i).Inlet.F;
429
430"FeedTrayTop Inlet Temperature"
431        FeedTray.T = TRAYS(i).Inlet.T;
432
433"FeedTrayTop Inlet Pressure"
434        FeedTray.P = TRAYS(i).Inlet.P;
435
436"FeedTrayTop Inlet Composition"
437        FeedTray.z = TRAYS(i).Inlet.z;
438
439"FeedTrayTop Inlet Vapour Fraction"
440        FeedTray.v = TRAYS(i).Inlet.v;
441
442"FeedTrayTop Inlet Enthalpy"
443        FeedTray.h = TRAYS(i).Inlet.h;
444
445else
446
447"Inlet Tray - Flow Sealed"
448    0*'mol/h'= TRAYS(i).Inlet.F;
449       
450"Inlet Tray -  Temperature"
451    300*'K' = TRAYS(i).Inlet.T;
452       
453"Inlet Tray -  Pressure"
454    1*'atm' = TRAYS(i).Inlet.P;
455       
456"Inlet Tray -  Composition"
457    0.1 = TRAYS(i).Inlet.z;
458       
459"Inlet Tray -  Vapour Fraction"
460    0 = TRAYS(i).Inlet.v;
461       
462"Inlet Tray -  Enthalpy"
463    0*'J/mol' = TRAYS(i).Inlet.h;
464
465end
466
467end
468
469end
470
471Model Section_Column2   as SectionColumnBasic
472
473ATTRIBUTES
474        Pallete         = true;
475        Icon            = "icon/SectionColumn";
476        Brief   = "Model of a column section.";
477        Info            =
478"== Model of a column section containing ==
479* NumberOfTrays TRAYS.
480* Two Feed Inlets.
481       
482== Specify ==
483* the feed stream of each tray (Inlet);
484* the Murphree eficiency for each tray Emv;
485* the InletLiquid stream of the top tray;
486* the InletVapour stream of the bottom tray.
487       
488== Initial Conditions ==
489* the TRAYS temperature (OutletLiquid.T);
490* the TRAYS liquid level (Level) OR the TRAYS liquid flow (OutletLiquid.F);
491* (NoComps - 1) OutletLiquid (OR OutletVapour) compositions for each tray.
492";
493
494SET
495        NumberOfFeeds = 2;
496
497VARIABLES
498       
499        in      FeedTrayOne     as stream               (Brief="Feed stream", PosX=0, PosY=0.45);
500        in      FeedTrayTwo     as stream               (Brief="Feed stream", PosX=0, PosY=0.65);
501
502EQUATIONS
503
504for i in 1:NumberOfTrays do
505
506if   i equal FeedTrayLocation(1) then   
507
508"FeedTrayTop Inlet Flow"       
509        FeedTrayOne.F= TRAYS(i).Inlet.F;
510
511"FeedTrayTop Inlet Temperature"
512        FeedTrayOne.T = TRAYS(i).Inlet.T;
513
514"FeedTrayTop Inlet Pressure"
515        FeedTrayOne.P = TRAYS(i).Inlet.P;
516
517"FeedTrayTop Inlet Composition"
518        FeedTrayOne.z = TRAYS(i).Inlet.z;
519
520"FeedTrayTop Inlet Vapour Fraction"
521        FeedTrayOne.v = TRAYS(i).Inlet.v;
522
523"FeedTrayTop Inlet Enthalpy"
524        FeedTrayOne.h = TRAYS(i).Inlet.h;
525
526else if   i equal FeedTrayLocation(2) then   
527
528"FeedTrayBottom Inlet Flow"     
529        FeedTrayTwo.F= TRAYS(i).Inlet.F;
530
531"FeedTrayBottom Inlet Temperature"
532        FeedTrayTwo.T = TRAYS(i).Inlet.T;
533
534"FeedTrayBottom Inlet Pressure"
535        FeedTrayTwo.P = TRAYS(i).Inlet.P;
536
537"FeedTrayBottom Inlet Composition"
538        FeedTrayTwo.z = TRAYS(i).Inlet.z;
539
540"FeedTrayBottom Inlet Vapour Fraction"
541        FeedTrayTwo.v = TRAYS(i).Inlet.v;
542
543"FeedTrayBottom Inlet Enthalpy"
544        FeedTrayTwo.h = TRAYS(i).Inlet.h;
545
546else
547
548"Inlet Tray - Flow Sealed"
549    0*'mol/h'= TRAYS(i).Inlet.F;
550       
551"Inlet Tray -  Temperature"
552    300*'K' = TRAYS(i).Inlet.T;
553       
554"Inlet Tray -  Pressure"
555    1*'atm' = TRAYS(i).Inlet.P;
556       
557"Inlet Tray -  Composition"
558    0.1 = TRAYS(i).Inlet.z;
559       
560"Inlet Tray -  Vapour Fraction"
561    0 = TRAYS(i).Inlet.v;
562       
563"Inlet Tray -  Enthalpy"
564    0*'J/mol' = TRAYS(i).Inlet.h;
565
566end
567
568end
569
570end
571
572end
573
574Model Section_Column3   as SectionColumnBasic
575
576ATTRIBUTES
577        Pallete         = true;
578        Icon            = "icon/SectionColumn";
579        Brief   = "Model of a column section.";
580        Info            =
581"== Model of a column section containing ==
582* NumberOfTrays TRAYS.
583* Three Feed Inlets.
584       
585== Specify ==
586* the feed stream of each tray (Inlet);
587* the Murphree eficiency for each tray Emv;
588* the InletLiquid stream of the top tray;
589* the InletVapour stream of the bottom tray.
590       
591== Initial Conditions ==
592* the TRAYS temperature (OutletLiquid.T);
593* the TRAYS liquid level (Level) OR the TRAYS liquid flow (OutletLiquid.F);
594* (NoComps - 1) OutletLiquid (OR OutletVapour) compositions for each tray.
595";
596
597SET
598        NumberOfFeeds = 3;
599
600VARIABLES
601       
602        in      FeedTrayOne     as stream               (Brief="Feed stream", PosX=0, PosY=0.45);
603        in      FeedTrayTwo     as stream               (Brief="Feed stream", PosX=0, PosY=0.65);
604        in      FeedTrayThree   as stream               (Brief="Feed stream", PosX=0, PosY=0.85);
605
606EQUATIONS
607
608for i in 1:NumberOfTrays do
609
610if   i equal FeedTrayLocation(1) then   
611
612"FeedTrayTop Inlet Flow"       
613        FeedTrayOne.F= TRAYS(i).Inlet.F;
614
615"FeedTrayTop Inlet Temperature"
616        FeedTrayOne.T = TRAYS(i).Inlet.T;
617
618"FeedTrayTop Inlet Pressure"
619        FeedTrayOne.P = TRAYS(i).Inlet.P;
620
621"FeedTrayTop Inlet Composition"
622        FeedTrayOne.z = TRAYS(i).Inlet.z;
623
624"FeedTrayTop Inlet Vapour Fraction"
625        FeedTrayOne.v = TRAYS(i).Inlet.v;
626
627"FeedTrayTop Inlet Enthalpy"
628        FeedTrayOne.h = TRAYS(i).Inlet.h;
629
630else if   i equal FeedTrayLocation(2) then   
631
632"FeedTrayBottom Inlet Flow"     
633        FeedTrayTwo.F= TRAYS(i).Inlet.F;
634
635"FeedTrayBottom Inlet Temperature"
636        FeedTrayTwo.T = TRAYS(i).Inlet.T;
637
638"FeedTrayBottom Inlet Pressure"
639        FeedTrayTwo.P = TRAYS(i).Inlet.P;
640
641"FeedTrayBottom Inlet Composition"
642        FeedTrayTwo.z = TRAYS(i).Inlet.z;
643
644"FeedTrayBottom Inlet Vapour Fraction"
645        FeedTrayTwo.v = TRAYS(i).Inlet.v;
646
647"FeedTrayBottom Inlet Enthalpy"
648        FeedTrayTwo.h = TRAYS(i).Inlet.h;
649
650else if   i equal FeedTrayLocation(3) then   
651
652"FeedTrayBottom Inlet Flow"     
653        FeedTrayThree.F= TRAYS(i).Inlet.F;
654
655"FeedTrayBottom Inlet Temperature"
656        FeedTrayThree.T = TRAYS(i).Inlet.T;
657
658"FeedTrayBottom Inlet Pressure"
659        FeedTrayThree.P = TRAYS(i).Inlet.P;
660
661"FeedTrayBottom Inlet Composition"
662        FeedTrayThree.z = TRAYS(i).Inlet.z;
663
664"FeedTrayBottom Inlet Vapour Fraction"
665        FeedTrayThree.v = TRAYS(i).Inlet.v;
666
667"FeedTrayBottom Inlet Enthalpy"
668        FeedTrayThree.h = TRAYS(i).Inlet.h;
669
670else
671
672"Inlet Tray - Flow Sealed"
673    0*'mol/h'= TRAYS(i).Inlet.F;
674       
675"Inlet Tray -  Temperature"
676    300*'K' = TRAYS(i).Inlet.T;
677       
678"Inlet Tray -  Pressure"
679    1*'atm' = TRAYS(i).Inlet.P;
680       
681"Inlet Tray -  Composition"
682    0.1 = TRAYS(i).Inlet.z;
683       
684"Inlet Tray -  Vapour Fraction"
685    0 = TRAYS(i).Inlet.v;
686       
687"Inlet Tray -  Enthalpy"
688    0*'J/mol' = TRAYS(i).Inlet.h;
689
690end
691
692end
693
694end
695
696end
697
698end
699
700
701Model ColumnBasic
702
703ATTRIBUTES
704        Pallete = false;
705        Brief   = "Model of a basic column.";
706        Info    =
707"Model of a basic column containing a vetor of TRAYS numbered from the top-down.";
708
709PARAMETERS
710        outer PP                as Plugin       (Brief="External Physical Properties", Type="PP");
711        outer NComp     as Integer      (Brief="Number of components");
712
713        NumberOfFeeds                                           as Integer                      (Brief="Number of Feed Trays",Default=3,Protected=true);
714        FeedTrayLocation(NumberOfFeeds)         as Integer                      (Brief="Feed tray Location",Default=2);
715        NumberOfTrays                                           as Integer                      (Brief="Number of trays", Default=8);
716        LiqSideTrayIndex(NumberOfTrays)         as Integer                      (Brief="Liquid Side Tray Index", Default=0,Hidden=true);
717        VapSideTrayIndex(NumberOfTrays)         as Integer                      (Brief="Vapour Side Tray Index", Default=0,Hidden=true);
718        LiquidSideStreamLocation                        as Integer                      (Brief="Liquid Side Stream Location", Default=2);
719        VapourSideStreamLocation                        as Integer                      (Brief="Vapour Side Stream Location", Default=2);
720        g                                                                       as acceleration         (Brief="Gravity Acceleration",Default=9.81,Hidden=true);
721        Mw(NComp)                                                       as molweight            (Brief="Component Mol Weight",Hidden=true);
722
723        VapourFlowModel         as Switcher     (Valid = ["Reepmeyer", "Feehery_Fv", "Roffel_Fv", "Klingberg", "Wang_Fv", "Elgue"], Default = "Reepmeyer");
724        LiquidFlowModel         as Switcher     (Valid = ["default", "Wang_Fl", "Olsen", "Feehery_Fl", "Roffel_Fl"], Default = "default");
725
726        TrayDiameter                    as length               (Brief="Tray Diameter",Default=1.600);
727        TraySpacing                             as length               (Brief="Tray Spacing",Default=0.600);
728        Fraction_HoleArea               as fraction     (Brief="Fraction of the active area that is occupied by the holes with respect to the total tray area",Default=0.10);
729        Fraction_DowncomerArea  as fraction     (Brief="Fraction of the downcomer area with respect to the total tray area",Default=0.20);
730        WeirLength                              as length               (Brief="Weir length", Default = 1);
731        WeirHeight                              as length               (Brief="Weir height", Default= 0.05);
732        TrayLiquidPasses                as positive     (Brief="Number of liquid passes in the tray", Lower = 1,Default=1);
733        HeatSupply                              as heat_rate    (Brief="Rate of heat supply",Default = 0);
734        AerationFraction                as Real                 (Brief="Aeration fraction", Default = 1);
735        DryPdropCoeff                   as Real                 (Brief="Dry pressure drop coefficient", Default= 0.60);
736       
737        PlateArea               as area         (Brief="Plate area = Atray - Adowncomer",Protected=true);
738        TrayVolume              as volume       (Brief="Total Volume of the tray",Protected=true);
739        HolesArea               as area         (Brief="Total holes area",Protected=true);
740       
741        FeeheryCoeff            as Real                 (Brief="Feeherys correlation coefficient", Unit='1/m^4', Default=1,Hidden=true);
742        ElgueCoeff                      as Real                 (Brief="Elgues correlation coefficient", Unit='kg/m/mol^2', Default=1,Hidden=true);
743        OlsenCoeff                      as Real                 (Brief="Olsens correlation coefficient", Default=1,Hidden=true);
744       
745        Pi                      as constant             (Brief="Pi Number",Default=3.14159265, Symbol = "\pi",Hidden=true);
746        zero_flow       as flow_mol             (Brief = "Stream Flow closed",Default = 0, Hidden=true);
747        low_flow        as flow_mol             (Brief = "Low stream Flow",Default = 1E-6, Hidden=true);
748        VapourFlow      as Switcher     (Valid = ["on", "off"], Default = "on",Hidden=true);
749        LiquidFlow      as Switcher     (Valid = ["on", "off"], Default = "on",Hidden=true);
750
751SET
752        VapSideTrayIndex(VapourSideStreamLocation) =1;
753        LiqSideTrayIndex(LiquidSideStreamLocation) =1;
754        Mw = PP.MolecularWeight();
755        zero_flow = 0 * 'kmol/h';
756        low_flow = 1E-6 * 'kmol/h';
757
758        PlateArea = 0.25*Pi*(TrayDiameter^2)*(1-Fraction_DowncomerArea);
759        TrayVolume = 0.25*Pi*(TrayDiameter^2)*TraySpacing;
760        HolesArea = 0.25*Pi*(TrayDiameter^2)*Fraction_HoleArea;
761
762VARIABLES
763
764        INITIALIZATION as InitializeSection (Brief = "Column Model Initialization");
765        CONTROL                 as ControlSection (Brief = "Control");
766       
767        out     TCI as control_signal   (Brief="Temperature  Indicator", Protected = true, PosX=1, PosY=0.55);
768        out     PCI as control_signal   (Brief="Pressure Indicator", Protected = true, PosX=0, PosY=0.23);
769       
770        TRAYS(NumberOfTrays)    as tray                 (Brief="Number of trays in the Column Section");
771        VapourDrawOffFlow               as flow_mol     (Brief="Vapour Draw Off Stream Molar Flow Rate");
772        LiquidDrawOffFlow               as flow_mol     (Brief="Vapour Draw Off Stream Molar Flow Rate");
773        MurphreeEff                     as Real                 (Brief="Murphree efficiency for All Trays",Lower=0.01,Upper=1);
774
775        out     VapourDrawOff   as vapour_stream        (Brief="Vapour Outlet in the section", PosX=1, PosY=0.388,Protected = true);
776        out     LiquidDrawOff   as liquid_stream        (Brief="Liquid Outlet in the section", PosX=1, PosY=0.47,Protected = true);
777
778CONNECTIONS
779
780#Connecting Intermediate Trays
781        TRAYS([2:NumberOfTrays]).OutletVapour   to TRAYS([1:NumberOfTrays-1]).InletVapour;
782        TRAYS([1:NumberOfTrays-1]).OutletLiquid         to TRAYS([2:NumberOfTrays]).InletLiquid;
783       
784INITIAL
785
786for i in 1:NumberOfTrays do
787
788"The initial temperature of the TRAYS"
789        TRAYS(i).OutletLiquid.T = INITIALIZATION.TopTemperature+(INITIALIZATION.BottomTemperature-INITIALIZATION.TopTemperature)*((i-1)/(NumberOfTrays-1));
790
791"The initial Level of the TRAYS"
792        TRAYS(i).Level = INITIALIZATION.LevelFraction*WeirHeight;
793end
794
795for i in 1:NComp-1 do
796
797for j in 1:NumberOfTrays do
798
799"The initial composition of the TRAYS - Normalized"
800        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));
801end
802
803end
804
805EQUATIONS
806
807        VapourDrawOff.F*VapSideTrayIndex= TRAYS.VapourSideStream.F;
808        VapourDrawOff.T = TRAYS(VapourSideStreamLocation).VapourSideStream.T;
809        VapourDrawOff.P = TRAYS(VapourSideStreamLocation).VapourSideStream.P;
810        VapourDrawOff.z = TRAYS(VapourSideStreamLocation).VapourSideStream.z;
811
812        LiquidDrawOff.F*LiqSideTrayIndex= TRAYS.LiquidSideStream.F;
813        LiquidDrawOff.T = TRAYS(LiquidSideStreamLocation).LiquidSideStream.T;
814        LiquidDrawOff.P = TRAYS(LiquidSideStreamLocation).LiquidSideStream.P;
815        LiquidDrawOff.z = TRAYS(LiquidSideStreamLocation).LiquidSideStream.z;
816
817        VapourDrawOffFlow = VapourDrawOff.F;
818        LiquidDrawOffFlow = LiquidDrawOff.F;
819       
820"Tray Temperature Indicator"   
821        #TCI*'K' = TRAYS(min([NumberOfTrays, CONTROL.Tindicator_TrayNumber])).OutletVapour.T;
822        TCI*'K' = TRAYS(CONTROL.Tindicator_TrayNumber).OutletVapour.T;
823
824"Tray Pressure Indicator"       
825        #PCI*'atm' = TRAYS(min([NumberOfTrays, CONTROL.Pindicator_TrayNumber])).OutletVapour.P;
826        PCI*'atm' = TRAYS(CONTROL.Pindicator_TrayNumber).OutletVapour.P;
827
828for i in [1:NumberOfTrays] do
829
830"Murphree Efficiency"
831        TRAYS(i).OutletVapour.z =  MurphreeEff * (TRAYS(i).yideal - TRAYS(i).InletVapour.z) + TRAYS(i).InletVapour.z;
832
833"Level of clear liquid over the weir"
834        TRAYS(i).Level = TRAYS(i).ML*TRAYS(i).vL/PlateArea;
835
836"Geometry Constraint"
837        TrayVolume = TRAYS(i).ML* TRAYS(i).vL + TRAYS(i).MV*TRAYS(i).vV;
838
839"Energy Holdup"
840        TRAYS(i).E = TRAYS(i).ML*TRAYS(i).OutletLiquid.h + TRAYS(i).MV*TRAYS(i).OutletVapour.h - TRAYS(i).OutletLiquid.P*TrayVolume;
841
842"Energy Balance"
843        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
844        -TRAYS(i).VapourSideStream.F*TRAYS(i).VapourSideStream.h - TRAYS(i).LiquidSideStream.F*TRAYS(i).LiquidSideStream.h + HeatSupply );
845
846switch LiquidFlow
847                case "on":
848                        switch LiquidFlowModel
849                                case "default":
850                                "Francis Equation"
851                                TRAYS(i).OutletLiquid.F*TRAYS(i).vL = 1.84*'1/s'*WeirLength*((TRAYS(i).Level-(AerationFraction*WeirHeight))/(AerationFraction))^2;
852                       
853                                case "Wang_Fl":
854                                TRAYS(i).OutletLiquid.F*TRAYS(i).vL = 1.84*'m^0.5/s'*WeirLength*((TRAYS(i).Level-(AerationFraction*WeirHeight))/(AerationFraction))^1.5;
855                       
856                                case "Olsen":
857                                TRAYS(i).OutletLiquid.F / 'mol/s'= WeirLength*TrayLiquidPasses*TRAYS(i).rhoL/sum(Mw*TRAYS(i).OutletVapour.z)/(0.665*OlsenCoeff)^1.5 * ((TRAYS(i).ML*sum(Mw*TRAYS(i).OutletLiquid.z)/TRAYS(i).rhoL/PlateArea)-WeirHeight)^1.5 * 'm^0.5/mol';
858                       
859                                case "Feehery_Fl":
860                                TRAYS(i).OutletLiquid.F = WeirLength*TRAYS(i).rhoL/sum(Mw*TRAYS(i).OutletLiquid.z) * ((TRAYS(i).Level-WeirHeight)/750/'mm')^1.5 * 'm^2/s';
861                       
862                                case "Roffel_Fl":
863                                TRAYS(i).OutletLiquid.F = 2/3*TRAYS(i).rhoL/sum(Mw*TRAYS(i).OutletLiquid.z)*WeirLength*(TRAYS(i).ML*sum(Mw*TRAYS(i).OutletLiquid.z)/(PlateArea*1.3)/TRAYS(i).rhoL)^1.5*sqrt(2*g/
864                                                        (2*(1 - 0.3593/'Pa^0.0888545'*abs(TRAYS(i).OutletVapour.F*sum(Mw*TRAYS(i).OutletVapour.z)/(PlateArea*1.3)/sqrt(TRAYS(i).rhoV))^0.177709)-1)); #/'(kg/m)^0.0888545/s^0.177709';
865                        end
866                when TRAYS(i).Level < (AerationFraction *WeirHeight) switchto "off";
867               
868                case "off":
869                "Low level"
870                TRAYS(i).OutletLiquid.F = 0 * 'mol/h';
871                when TRAYS(i).Level > (AerationFraction * WeirHeight) switchto "on";
872        end
873       
874switch VapourFlow
875                case "on":
876                        switch VapourFlowModel
877                                case "Reepmeyer":
878                                TRAYS(i).InletVapour.F*TRAYS(i).vV = sqrt((TRAYS(i).InletVapour.P - TRAYS(i).OutletVapour.P)/(TRAYS(i).rhoV*DryPdropCoeff))*HolesArea;
879                       
880                                case "Feehery_Fv":
881                                TRAYS(i).InletVapour.F = TRAYS(i).rhoV/PlateArea/FeeheryCoeff/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/PlateArea))/TRAYS(i).rhoV);
882                       
883                                case "Roffel_Fv":
884                                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 - (AerationFraction*sum(TRAYS(i).M*Mw)/(PlateArea*1.3)*g*1e5) * (TRAYS(i).rhoV*HolesArea/sum(Mw*TRAYS(i).OutletVapour.z))^1.08 * 'm^1.08/mol^1.08';
885                       
886                                case "Klingberg":
887                                TRAYS(i).InletVapour.F * TRAYS(i).vV = PlateArea * sqrt(((TRAYS(i).InletVapour.P - TRAYS(i).OutletVapour.P)-TRAYS(i).rhoL*g*TRAYS(i).Level)/TRAYS(i).rhoV);
888                       
889                                case "Wang_Fv":
890                                TRAYS(i).InletVapour.F * TRAYS(i).vV = PlateArea * sqrt(((TRAYS(i).InletVapour.P - TRAYS(i).OutletVapour.P)-TRAYS(i).rhoL*g*TRAYS(i).Level)/TRAYS(i).rhoV*DryPdropCoeff);
891                               
892                                case "Elgue":
893                                TRAYS(i).InletVapour.F  = sqrt((TRAYS(i).InletVapour.P - TRAYS(i).OutletVapour.P)/ElgueCoeff);
894                        end
895                when TRAYS(i).InletVapour.F < 1e-6 * 'kmol/h' switchto "off";
896               
897                case "off":
898                TRAYS(i).InletVapour.F = 0 * 'mol/s';
899                when TRAYS(i).InletVapour.P > TRAYS(i).OutletVapour.P switchto "on";
900        end
901
902end
903
904end
905
906Model Distillation_kettle_cond                          as ColumnBasic
907
908ATTRIBUTES
909        Pallete         = true;
910        Icon            = "icon/DistillationKettleCond";
911        Brief           = "Model of a distillation column with dynamic condenser and dynamic reboiler.";
912        Info            =
913"== Specify ==
914* the feed stream of each tray (Inlet);
915* the Murphree eficiency for each tray Emv;
916* the pump pressure difference;
917* the heat supllied in reboiler and condenser;
918* the condenser vapor outlet flow (OutletVapour.F);
919* the reboiler liquid outlet flow (OutletLiquid.F);
920* both splitter outlet flows OR one of the splitter outlet flows and the splitter frac.
921       
922== Initial Conditions ==
923* the TRAYS temperature (OutletLiquid.T);
924* the TRAYS liquid level (Level) OR the TRAYS liquid flow (OutletLiquid.F);
925* (NoComps - 1) OutletLiquid (OR OutletVapour) compositions for each tray;
926       
927* the condenser temperature (OutletLiquid.T);
928* the condenser liquid level (Level);
929* (NoComps - 1) OutletLiquid (OR OutletVapour) compositions;
930       
931* the reboiler temperature (OutletLiquid.T);
932* the reboiler liquid level (Level);
933* (NoComps - 1) OutletLiquid (OR OutletVapour) compositions.
934";
935
936SET
937        NumberOfFeeds = 1;
938       
939VARIABLES
940
941        CONDENSER               as condenser;
942        REBOILER                as reboiler;
943        SPLITTER                as splitter_column (Brief="splitter which separate reflux and distillate",Protected=true);
944        PUMP                    as pump;
945        RefluxRatio             as positive             (Brief="Reflux Ratio",Default=10, Lower = 0.5);
946       
947        out     TI_reb  as control_signal       (Brief="Temperature Indicator of Reboiler ",Protected = true, PosX=0.515, PosY=1);
948        out     LI_reb  as control_signal       (Brief="Level Indicator of Reboiler", Protected = true, PosX=1, PosY=0.935);
949        out     PI_reb  as control_signal       (Brief="Pressure Indicator of Reboiler", Protected = true, PosX=0.41, PosY=1);
950       
951        out     TI_cond         as control_signal       (Brief="Temperature Indicator of Condenser ", Protected = true, PosX=0.52, PosY=0);
952        out     LI_cond         as control_signal       (Brief="Level Indicator of Condenser", Protected = true, PosX=1, PosY=0.084);
953        out     PI_cond         as control_signal       (Brief="Pressure Indicator of Condenser", Protected = true, PosX=0.42, PosY=0);
954       
955        in      FeedTray        as stream               (Brief="Feed stream", PosX=0, PosY=0.55);
956
957
958
959        in      HeatToReboiler  as power (Brief="Heat supplied to Reboiler",Protected = true, PosX=1, PosY=0.855);
960        in      HeatToCondenser as power (Brief="Heat supplied to Condenser", Protected = true, PosX=1, PosY=0.01);
961
962
963        ConnectorHeatReboiler   as power        (Brief="Heat supplied to Reboiler", Hidden=true);
964        ConnectorHeatCondenser  as power        (Brief="Heat supplied to Condenser", Hidden=true);
965       
966        in      ConnectorCondenserVout  as stream       (Brief="Connector for Vapour outlet stream From Condenser", Hidden=true);
967        in      ConnectorReboilerLout   as stream       (Brief="Connector for Liquid outlet stream From Reboiler", Hidden=true);
968        in      ConnectorSplitterOut    as stream       (Brief="Connector for Liquid outlet stream From Top Splitter", Hidden=true);
969
970        out     VapourDistillate        as vapour_stream        (Brief="Vapour outlet stream From Condenser", PosX=0.615, PosY=0);
971        out     LiquidDistillate        as liquid_stream        (Brief="Liquid outlet stream From Top Splitter", PosX=1, PosY=0.235);
972        out     BottomProduct           as liquid_stream        (Brief="Liquid outlet stream From Reboiler", PosX=0.62, PosY=1);
973
974EQUATIONS
975
976        SPLITTER.RefluxRatio = RefluxRatio;
977
978        TI_reb  = REBOILER.TI ;
979        LI_reb  = REBOILER.LI;
980        PI_reb  = REBOILER.PI;
981       
982        TI_cond = CONDENSER.TI;
983        LI_cond = CONDENSER.LI;
984        PI_cond = CONDENSER.PI;
985       
986for i in 1:NumberOfTrays do
987
988if i equal FeedTrayLocation(1) then   
989
990"FeedTrayTop Inlet Flow"       
991        FeedTray.F= TRAYS(i).Inlet.F;
992
993"FeedTrayTop Inlet Temperature"
994        FeedTray.T = TRAYS(i).Inlet.T;
995
996"FeedTrayTop Inlet Pressure"
997        FeedTray.P = TRAYS(i).Inlet.P;
998
999"FeedTrayTop Inlet Composition"
1000        FeedTray.z = TRAYS(i).Inlet.z;
1001
1002"FeedTrayTop Inlet Vapour Fraction"
1003        FeedTray.v = TRAYS(i).Inlet.v;
1004
1005"FeedTrayTop Inlet Enthalpy"
1006        FeedTray.h = TRAYS(i).Inlet.h;
1007
1008else
1009
1010"Inlet Tray - Flow Sealed"
1011    0*'mol/h'= TRAYS(i).Inlet.F;
1012       
1013"Inlet Tray -  Temperature"
1014    300*'K' = TRAYS(i).Inlet.T;
1015       
1016"Inlet Tray -  Pressure"
1017    1*'atm' = TRAYS(i).Inlet.P;
1018       
1019"Inlet Tray -  Composition"
1020    0.1 = TRAYS(i).Inlet.z;
1021       
1022"Inlet Tray -  Vapour Fraction"
1023    0 = TRAYS(i).Inlet.v;
1024       
1025"Inlet Tray -  Enthalpy"
1026    0*'J/mol' = TRAYS(i).Inlet.h;
1027
1028end
1029
1030end
1031
1032# Condenser Connector Equations
1033        ConnectorCondenserVout.T = VapourDistillate.T;
1034        ConnectorCondenserVout.P = VapourDistillate.P;
1035        ConnectorCondenserVout.F = VapourDistillate.F;
1036        ConnectorCondenserVout.z = VapourDistillate.z;
1037
1038# Splitter Connector Equations
1039        ConnectorSplitterOut.T = LiquidDistillate.T;
1040        ConnectorSplitterOut.P = LiquidDistillate.P;
1041        ConnectorSplitterOut.F = LiquidDistillate.F;
1042        ConnectorSplitterOut.z = LiquidDistillate.z;
1043
1044# Reboiler Connector Equations
1045        ConnectorReboilerLout.T = BottomProduct.T;
1046        ConnectorReboilerLout.P = BottomProduct.P;
1047        ConnectorReboilerLout.F = BottomProduct.F;
1048        ConnectorReboilerLout.z = BottomProduct.z;
1049
1050        HeatToReboiler  = ConnectorHeatReboiler;
1051        HeatToCondenser = ConnectorHeatCondenser;
1052
1053CONNECTIONS
1054#vapor
1055        REBOILER.OutletVapour   to      TRAYS(NumberOfTrays).InletVapour;
1056        TRAYS(1).OutletVapour   to      CONDENSER.InletVapour;
1057
1058#liquid
1059        CONDENSER.OutletLiquid                          to      SPLITTER.Inlet;
1060        SPLITTER.Reflux                                         to      PUMP.Inlet;
1061        PUMP.Outlet                                             to      TRAYS(1).InletLiquid;
1062        TRAYS(NumberOfTrays).OutletLiquid       to      REBOILER.InletLiquid;
1063
1064#Connectors
1065        CONDENSER.OutletVapour  to ConnectorCondenserVout;
1066        SPLITTER.Distillate             to ConnectorSplitterOut;
1067        REBOILER.OutletLiquid   to ConnectorReboilerLout;
1068
1069        ConnectorHeatReboiler   to REBOILER.InletQ;
1070        ConnectorHeatCondenser  to CONDENSER.InletQ;
1071
1072end
1073
1074Model Distillation_thermosyphon_subcooling      as ColumnBasic
1075        ATTRIBUTES
1076        Pallete         = true;
1077        Icon            = "icon/DistillationThermosyphonSubcooling";
1078        Brief           = "Model of a distillation column with steady condenser and steady reboiler.";
1079        Info            =
1080"== Specify ==
1081* the feed stream of each tray (Inlet);
1082* the Murphree eficiency for each tray Emv;
1083* the pump head;
1084* the condenser pressure drop;
1085* the heat supllied in top and bottom tanks;
1086* the heat supllied in condenser and reboiler;
1087* the Outlet1 flow in the bottom splitter (spbottom.Outlet1.F) that corresponds to the bottom product;
1088* both  top splitter outlet flows OR one of the splitter outlet flows and the splitter frac.
1089       
1090== Initial Conditions ==
1091* the TRAYS temperature (OutletLiquid.T);
1092* the TRAYS liquid level (Level) OR the TRAYS liquid flow (OutletLiquid.F);
1093* (NoComps - 1) OutletLiquid (OR OutletVapour) compositions for each tray;
1094       
1095* the top tank temperature (OutletLiquid.T);
1096* the top tank liquid level (Level);
1097* (NoComps - 1) OutletLiquid (OR OutletVapour) compositions;
1098       
1099* the bottom tank temperature (OutletLiquid.T);
1100* the bottom tank liquid level (Level);
1101* (NoComps - 1) OutletLiquid (OR OutletVapour) compositions.
1102";
1103
1104SET
1105
1106        NumberOfFeeds = 1;
1107
1108VARIABLES
1109        CONDENSER                       as condenserSteady      (Brief="steady state condenser with subcooling");
1110        REFLUX_DRUM             as TankL                        (Brief="Reflux Drum");
1111        SPLITTER_TOP            as splitter_column      (Brief="splitter which separate reflux and distillate",Protected=true);
1112        PUMP                            as pump                         (Brief="pump in reflux stream");
1113        REBOILER                        as reboilerSteady       (Brief="steady state reboiler (thermosyphon)");
1114        SUMP                            as SumpTank                     (Brief="vessel in the bottom of column");
1115        SPLITTER_BOTTOM         as splitter2            (Brief="splitter to separate the bottom product and the stream to reboiler");
1116       
1117        in      FeedTray        as stream               (Brief="Feed stream", PosX=0, PosY=0.55);
1118
1119        RefluxRatio             as positive             (Brief="Reflux Ratio",Default=10, Lower = 0.5);
1120
1121in              Q_cond          as power        (Brief="Heat supplied to Condenser",PosX=1, PosY=0, Protected=true);
1122in              Q_reb           as power        (Brief="Heat supplied to Reboiler", PosX=1, PosY=0.96,Protected=true);
1123in              Q_drum  as power        (Brief="Heat supplied to Reflux Drum", PosX=1, PosY=0.30,Protected=true);
1124
1125        out     TI_reb  as control_signal       (Brief="Temperature Indicator of Reboiler ",Protected = true, PosX=1, PosY=0.92);
1126        out     PI_reb  as control_signal       (Brief="Pressure Indicator of Reboiler", Protected = true, PosX=1, PosY=0.875);
1127       
1128        out     TI_cond         as control_signal       (Brief="Temperature Indicator of Condenser ", Protected = true, PosX=0.52, PosY=0);
1129        out     PI_cond         as control_signal       (Brief="Pressure Indicator of Condenser", Protected = true, PosX=0.42, PosY=0);
1130       
1131        out     TI_drum as control_signal       (Brief="Temperature Indicator of Reflux Drum ", Protected = true, PosX=1, PosY=0.20);
1132        out     PI_drum as control_signal       (Brief="Pressure Indicator of Reflux Drum", Protected = true, PosX=1, PosY=0.155);
1133        out     LI_drum as control_signal       (Brief="Level Indicator of Reflux Drum", Protected = true, PosX=1, PosY=0.24);
1134       
1135        out     LI_sump as control_signal       (Brief="Level Indicator of Column Sump", Protected = true, PosX=1, PosY=0.765);
1136        out     TI_sump as control_signal       (Brief="Temperature Indicator of Column Sump ",Protected = true, PosX=1, PosY=0.71);
1137       
1138        out     LiquidDistillate        as liquid_stream        (Brief="Liquid outlet stream From Top Splitter", PosX=1, PosY=0.33);
1139        out     BottomProduct           as liquid_stream        (Brief="Liquid outlet stream From Bottom Splitter", PosX=0.06, PosY=1);
1140
1141        in      ConnectorSplitterBottom         as stream       (Brief="Connector for Liquid outlet stream From Reboiler", Hidden=true);
1142        in      ConnectorSplitterTop            as stream       (Brief="Connector for Liquid outlet stream From Top Splitter", Hidden=true);
1143
1144        ConnectorHeatReboiler           as power        (Brief="Connector for Heat supplied to Reboiler", Hidden=true);
1145        ConnectorHeatCondenser          as power        (Brief="Connector for Heat supplied to Condenser", Hidden=true);
1146        ConnectorHeatRefluxDrum         as power        (Brief="Connector for Heat supplied to Reflux Drum", Hidden=true);
1147
1148EQUATIONS
1149
1150        SPLITTER_TOP.RefluxRatio = RefluxRatio;
1151        TI_reb  = REBOILER.TI ;
1152        PI_reb  = REBOILER.PI;
1153       
1154        TI_cond = CONDENSER.TI;
1155        PI_cond = CONDENSER.PI;
1156       
1157        TI_drum = REFLUX_DRUM.TI;
1158        PI_drum = REFLUX_DRUM.PI;
1159        LI_drum = REFLUX_DRUM.LI;
1160       
1161        TI_sump = SUMP.TI;
1162        LI_sump = SUMP.LI;
1163       
1164for i in 1:NumberOfTrays do
1165
1166if i equal FeedTrayLocation(1) then   
1167
1168"FeedTrayTop Inlet Flow"       
1169        FeedTray.F= TRAYS(i).Inlet.F;
1170
1171"FeedTrayTop Inlet Temperature"
1172        FeedTray.T = TRAYS(i).Inlet.T;
1173
1174"FeedTrayTop Inlet Pressure"
1175        FeedTray.P = TRAYS(i).Inlet.P;
1176
1177"FeedTrayTop Inlet Composition"
1178        FeedTray.z = TRAYS(i).Inlet.z;
1179
1180"FeedTrayTop Inlet Vapour Fraction"
1181        FeedTray.v = TRAYS(i).Inlet.v;
1182
1183"FeedTrayTop Inlet Enthalpy"
1184        FeedTray.h = TRAYS(i).Inlet.h;
1185
1186else
1187
1188"Inlet Tray - Flow Sealed"
1189    0*'mol/h'= TRAYS(i).Inlet.F;
1190       
1191"Inlet Tray -  Temperature"
1192    300*'K' = TRAYS(i).Inlet.T;
1193       
1194"Inlet Tray -  Pressure"
1195    1*'atm' = TRAYS(i).Inlet.P;
1196       
1197"Inlet Tray -  Composition"
1198    0.1 = TRAYS(i).Inlet.z;
1199       
1200"Inlet Tray -  Vapour Fraction"
1201    0 = TRAYS(i).Inlet.v;
1202       
1203"Inlet Tray -  Enthalpy"
1204    0*'J/mol' = TRAYS(i).Inlet.h;
1205
1206end
1207
1208end
1209
1210# Heat Connector Equations
1211        Q_cond  =       ConnectorHeatCondenser;
1212        Q_reb   =       ConnectorHeatReboiler;
1213        Q_drum  =       ConnectorHeatRefluxDrum;
1214
1215# Top Splitter Connector Equations
1216        ConnectorSplitterTop.T = LiquidDistillate.T;
1217        ConnectorSplitterTop.P = LiquidDistillate.P;
1218        ConnectorSplitterTop.F = LiquidDistillate.F;
1219        ConnectorSplitterTop.z = LiquidDistillate.z;
1220
1221# Bottom Splitter Connector Equations
1222        ConnectorSplitterBottom.T = BottomProduct.T;
1223        ConnectorSplitterBottom.P = BottomProduct.P;
1224        ConnectorSplitterBottom.F = BottomProduct.F;
1225        ConnectorSplitterBottom.z = BottomProduct.z;
1226       
1227CONNECTIONS
1228#vapor
1229        REBOILER.OutletVapour   to SUMP.InletVapour;
1230        SUMP.OutletVapour               to TRAYS(NumberOfTrays).InletVapour;
1231        TRAYS(1).OutletVapour   to CONDENSER.InletVapour;
1232
1233#liquid
1234        CONDENSER.OutletLiquid                          to REFLUX_DRUM.Inlet;   
1235        REFLUX_DRUM.OutletLiquid                        to SPLITTER_TOP.Inlet;
1236        SPLITTER_TOP.Reflux                     to PUMP.Inlet; 
1237        PUMP.Outlet                                     to TRAYS(1).InletLiquid;
1238        TRAYS(NumberOfTrays).OutletLiquid       to SUMP.InletLiquid;
1239        SUMP.OutletLiquid               to SPLITTER_BOTTOM.Inlet;
1240        SPLITTER_BOTTOM.Outlet2                 to REBOILER.InletLiquid;
1241
1242#Connectors
1243        ConnectorHeatCondenser                  to CONDENSER.InletQ;
1244        ConnectorHeatReboiler                   to REBOILER.InletQ;
1245        ConnectorHeatRefluxDrum                 to REFLUX_DRUM.InletQ;
1246        SPLITTER_TOP.Distillate                 to ConnectorSplitterTop;
1247        SPLITTER_BOTTOM.Outlet1                 to ConnectorSplitterBottom;
1248
1249end
1250
1251Model Distillation_thermosyphon_cond            as ColumnBasic
1252        ATTRIBUTES
1253        Pallete         = true;
1254        Icon            = "icon/DistillationThermosyphonCond";
1255        Brief           = "Model of a distillation column with dynamic condenser and steady reboiler.";
1256        Info            =
1257"== Specify ==
1258* the feed stream of each tray (Inlet);
1259* the Murphree eficiency for each tray Emv;
1260* the pump head;
1261* the condenser vapor outlet flow (OutletVapour.F);
1262* the heat supllied in bottom tank;
1263* the heat supllied in condenser and reboiler;
1264* the Outlet1 flow in the bottom splitter (spbottom.Outlet1.F) that corresponds to the bottom product;
1265       
1266== Initial Conditions ==
1267* the TRAYS temperature (OutletLiquid.T);
1268* the TRAYS liquid level (Level) OR the TRAYS liquid flow (OutletLiquid.F);
1269* (NoComps - 1) OutletLiquid (OR OutletVapour) compositions for each tray;
1270       
1271* the condenser temperature (OutletLiquid.T);
1272* the condenser liquid level (Level);
1273* (NoComps - 1) OutletLiquid (OR OutletVapour) compositions;
1274       
1275* the bottom tank temperature (OutletLiquid.T);
1276* the bottom tank liquid level (Level);
1277* (NoComps - 1) OutletLiquid (OR OutletVapour) compositions.
1278";
1279
1280SET
1281
1282        NumberOfFeeds = 1;
1283
1284VARIABLES
1285        CONDENSER                       as condenser            (Brief="dynamic condenser without subcooling");
1286        SPLITTER_TOP            as splitter_column      (Brief="splitter which separate reflux and distillate",Protected=true);
1287        PUMP                            as pump                         (Brief="pump in reflux stream");
1288        SUMP                            as SumpTank                     (Brief="vessel in the bottom of column");
1289        SPLITTER_BOTTOM         as splitter2            (Brief="splitter who separate the bottom product and the stream to reboiler");
1290        REBOILER                        as reboilerSteady       (Brief="steady state reboiler (thermosyphon)");
1291        RefluxRatio                     as positive             (Brief="Reflux Ratio",Default=10, Lower = 0.5);
1292       
1293        in      FeedTray        as stream       (Brief="Feed stream", PosX=0, PosY=0.55);
1294
1295in              Q_cond  as power        (Brief="Heat supplied to Condenser",PosX=1, PosY=0, Protected=true);
1296in              Q_reb   as power        (Brief="Heat supplied to Reboiler", PosX=1, PosY=0.96,Protected=true);
1297
1298        out     TI_cond as control_signal       (Brief="Temperature Indicator of Condenser ", Protected = true, PosX=0.48, PosY=0);
1299        out     LI_cond as control_signal       (Brief="Level Indicator of Condenser", Protected = true, PosX=1, PosY=0.084);
1300        out     PI_cond as control_signal       (Brief="Pressure Indicator of Condenser", Protected = true, PosX=0.40, PosY=0);
1301       
1302        out     TI_reb  as control_signal       (Brief="Temperature Indicator of Reboiler ",Protected = true, PosX=1, PosY=0.92);
1303        out     PI_reb  as control_signal       (Brief="Pressure Indicator of Reboiler", Protected = true, PosX=1, PosY=0.878);
1304       
1305        out     LI_sump as control_signal       (Brief="Level Indicator of Column Sump", Protected = true, PosX=1, PosY=0.76);
1306        out     TI_sump as control_signal       (Brief="Temperature Indicator of Column Sump ",Protected = true, PosX=1, PosY=0.71);
1307       
1308out     VapourDistillate as vapour_stream       (Brief="Vapour outlet stream From Top Condenser", PosX=0.62, PosY=0);
1309out     LiquidDistillate as liquid_stream       (Brief="Liquid outlet stream From Top Splitter", PosX=1, PosY=0.185);
1310out     BottomProduct    as liquid_stream       (Brief="Liquid outlet stream From Bottom Splitter", PosX=0.06, PosY=1);
1311
1312in      ConnectorSplitterBottom as stream       (Brief="Connector for Liquid outlet stream From Reboiler", Hidden=true);
1313in      ConnectorSplitterTop    as stream       (Brief="Connector for Liquid outlet stream From Top Splitter", Hidden=true);
1314in      ConnectorCondenserVout  as stream       (Brief="Connector for Vapour outlet stream From Top Condenser", Hidden=true);
1315
1316        ConnectorHeatReboiler   as power        (Brief="Connector for Heat supplied to Reboiler", Hidden=true);
1317        ConnectorHeatCondenser  as power        (Brief="Connector for Heat supplied to Condenser", Hidden=true);
1318
1319EQUATIONS
1320
1321for i in 1:NumberOfTrays do
1322
1323if i equal FeedTrayLocation(1) then   
1324
1325"FeedTrayTop Inlet Flow"       
1326        FeedTray.F= TRAYS(i).Inlet.F;
1327
1328"FeedTrayTop Inlet Temperature"
1329        FeedTray.T = TRAYS(i).Inlet.T;
1330
1331"FeedTrayTop Inlet Pressure"
1332        FeedTray.P = TRAYS(i).Inlet.P;
1333
1334"FeedTrayTop Inlet Composition"
1335        FeedTray.z = TRAYS(i).Inlet.z;
1336
1337"FeedTrayTop Inlet Vapour Fraction"
1338        FeedTray.v = TRAYS(i).Inlet.v;
1339
1340"FeedTrayTop Inlet Enthalpy"
1341        FeedTray.h = TRAYS(i).Inlet.h;
1342
1343else
1344
1345"Inlet Tray - Flow Sealed"
1346    0*'mol/h'= TRAYS(i).Inlet.F;
1347       
1348"Inlet Tray -  Temperature"
1349    300*'K' = TRAYS(i).Inlet.T;
1350       
1351"Inlet Tray -  Pressure"
1352    1*'atm' = TRAYS(i).Inlet.P;
1353       
1354"Inlet Tray -  Composition"
1355    0.1 = TRAYS(i).Inlet.z;
1356       
1357"Inlet Tray -  Vapour Fraction"
1358    0 = TRAYS(i).Inlet.v;
1359       
1360"Inlet Tray -  Enthalpy"
1361    0*'J/mol' = TRAYS(i).Inlet.h;
1362
1363end
1364
1365end
1366
1367        SPLITTER_TOP.RefluxRatio = RefluxRatio;
1368
1369        TI_reb  = REBOILER.TI ;
1370        PI_reb  = REBOILER.PI;
1371       
1372        TI_cond = CONDENSER.TI;
1373        PI_cond = CONDENSER.PI;
1374        LI_cond = CONDENSER.LI;
1375       
1376        TI_sump = SUMP.TI;
1377        LI_sump = SUMP.LI;
1378       
1379# Heat Connector Equations
1380        Q_cond  =       ConnectorHeatCondenser;
1381        Q_reb   =       ConnectorHeatReboiler;
1382
1383# Condenser Connector Equations
1384        ConnectorCondenserVout.T = VapourDistillate.T;
1385        ConnectorCondenserVout.P = VapourDistillate.P;
1386        ConnectorCondenserVout.F = VapourDistillate.F;
1387        ConnectorCondenserVout.z = VapourDistillate.z;
1388
1389# Top Splitter Connector Equations
1390        ConnectorSplitterTop.T = LiquidDistillate.T;
1391        ConnectorSplitterTop.P = LiquidDistillate.P;
1392        ConnectorSplitterTop.F = LiquidDistillate.F;
1393        ConnectorSplitterTop.z = LiquidDistillate.z;
1394
1395# Bottom Splitter Connector Equations
1396        ConnectorSplitterBottom.T = BottomProduct.T;
1397        ConnectorSplitterBottom.P = BottomProduct.P;
1398        ConnectorSplitterBottom.F = BottomProduct.F;
1399        ConnectorSplitterBottom.z = BottomProduct.z;
1400
1401CONNECTIONS
1402#vapor
1403        SUMP.OutletVapour               to TRAYS(NumberOfTrays).InletVapour;
1404        REBOILER.OutletVapour   to SUMP.InletVapour;
1405        TRAYS(1).OutletVapour   to CONDENSER.InletVapour;
1406
1407#liquid
1408        CONDENSER.OutletLiquid          to SPLITTER_TOP.Inlet; 
1409        SPLITTER_TOP.Reflux                             to PUMP.Inlet;
1410        PUMP.Outlet                                     to TRAYS(1).InletLiquid;
1411        TRAYS(NumberOfTrays).OutletLiquid       to SUMP.InletLiquid;
1412        SUMP.OutletLiquid                               to SPLITTER_BOTTOM.Inlet;
1413        SPLITTER_BOTTOM.Outlet2                         to REBOILER.InletLiquid;
1414
1415#Connectors
1416ConnectorHeatCondenser                  to CONDENSER.InletQ;
1417ConnectorHeatReboiler                   to REBOILER.InletQ;
1418CONDENSER.OutletVapour                  to ConnectorCondenserVout;
1419SPLITTER_TOP.Distillate                 to ConnectorSplitterTop;
1420SPLITTER_BOTTOM.Outlet1                 to ConnectorSplitterBottom;
1421
1422end
1423
1424Model Distillation_kettle_subcooling            as ColumnBasic
1425
1426ATTRIBUTES
1427        Pallete         = true;
1428        Icon            = "icon/DistillationKettleSubcooling";
1429        Brief   = "Model of a distillation column with steady condenser and dynamic reboiler.";
1430        Info            =
1431"== Specify ==
1432* the feed stream of each tray (Inlet);
1433* the Murphree eficiency for each tray (Emv);
1434* the pump pressure difference;
1435* the heat supllied in reboiler and condenser;
1436* the heat supllied in the top tank;
1437* the condenser pressure drop;
1438* the reboiler liquid outlet flow (OutletLiquid.F);
1439* both splitter outlet flows OR one of the splitter outlet flows and the splitter frac.
1440       
1441== Initial Conditions ==
1442* the TRAYS temperature (OutletLiquid.T);
1443* the TRAYS liquid level (Level) OR the TRAYS liquid flow (OutletLiquid.F);
1444* (NoComps - 1) OutletLiquid (OR OutletVapour) compositions for each tray;
1445       
1446* the top tank temperature (OutletLiquid.T);
1447* the top tank liquid level (Level);
1448* (NoComps - 1) OutletLiquid (OR OutletVapour) compositions;
1449       
1450* the reboiler temperature (OutletLiquid.T);
1451* the reboiler liquid level (Level);
1452* (NoComps - 1) OutletLiquid (OR OutletVapour) compositions.
1453";
1454
1455SET
1456
1457        NumberOfFeeds = 1;
1458
1459VARIABLES
1460        CONDENSER               as condenserSteady      (Brief="steady state condenser with subcooling");
1461        REFLUX_DRUM             as TankL                        (Brief="reflux drum");
1462        SPLITTER                as splitter_column              (Brief="splitter to separate reflux and distillate",Protected=true);
1463        PUMP                    as pump                         (Brief="pump in reflux stream");
1464        REBOILER                as reboiler                     (Brief="kettle reboiler");
1465
1466        RefluxRatio                     as positive             (Brief="Reflux Ratio",Default=10, Lower = 0.5);
1467
1468        in      Q_cond  as power        (Brief="Heat supplied to Condenser", PosX=1, PosY=0.065, Protected=true);
1469        in      Q_reb   as power        (Brief="Heat supplied to Reboiler", PosX=1, PosY=0.905, Protected=true);
1470        in      Q_drum  as power        (Brief="Heat supplied to Top Vessel", PosX=1, PosY=0.30, Protected=true);
1471
1472        in      FeedTray        as stream               (Brief="Feed stream", PosX=0, PosY=0.55);
1473
1474        out     TI_reb  as control_signal       (Brief="Temperature Indicator of Reboiler ",Protected = true, PosX=0.515, PosY=1);
1475        out     LI_reb  as control_signal       (Brief="Level Indicator of Reboiler", Protected = true, PosX=1, PosY=0.935);
1476        out     PI_reb  as control_signal       (Brief="Pressure Indicator of Reboiler", Protected = true, PosX=0.41, PosY=1);
1477       
1478        out     TI_cond as control_signal       (Brief="Temperature Indicator of Condenser ", Protected = true, PosX=0.52, PosY=0);
1479        out     PI_cond as control_signal       (Brief="Pressure Indicator of Condenser", Protected = true, PosX=0.42, PosY=0);
1480       
1481        out     TI_drum as control_signal       (Brief="Temperature Indicator of Reflux Drum ", Protected = true, PosX=1, PosY=0.20);
1482        out     PI_drum as control_signal       (Brief="Pressure Indicator of Reflux Drum", Protected = true, PosX=1, PosY=0.155);
1483        out     LI_drum as control_signal       (Brief="Level Indicator of Reflux Drum", Protected = true, PosX=1, PosY=0.24);
1484       
1485       
1486in      ConnectorSplitterOut            as stream       (Brief="Connector for Liquid outlet stream From Top Splitter", Hidden=true);
1487in      ConnectorReboilerLout           as stream       (Brief="Connector for Liquid outlet stream From Reboiler", Hidden=true);
1488        ConnectorHeatReboiler           as power        (Brief="Connector for Heat supplied to Reboiler", Hidden=true);
1489        ConnectorHeatCondenser          as power        (Brief="Connector for Heat supplied to Condenser", Hidden=true);
1490        ConnectorHeatAccumulator        as power        (Brief="Connector for Heat supplied to TopVessel", Hidden=true);
1491
1492out     LiquidDistillate as liquid_stream       (Brief="Liquid outlet stream From Top Splitter", PosX=1, PosY=0.33);
1493out     BottomProduct    as liquid_stream       (Brief="Liquid outlet stream From Reboiler", PosX=0.67, PosY=1);
1494
1495EQUATIONS
1496
1497        SPLITTER.RefluxRatio = RefluxRatio;
1498
1499        TI_reb  = REBOILER.TI ;
1500        PI_reb  = REBOILER.PI;
1501        LI_reb  = REBOILER.LI;
1502       
1503        TI_cond = CONDENSER.TI;
1504        PI_cond = CONDENSER.PI;
1505       
1506        TI_drum = REFLUX_DRUM.TI;
1507        PI_drum = REFLUX_DRUM.PI;
1508        LI_drum = REFLUX_DRUM.LI;
1509       
1510for i in 1:NumberOfTrays do
1511
1512if i equal FeedTrayLocation(1) then   
1513
1514"FeedTrayTop Inlet Flow"       
1515        FeedTray.F= TRAYS(i).Inlet.F;
1516
1517"FeedTrayTop Inlet Temperature"
1518        FeedTray.T = TRAYS(i).Inlet.T;
1519
1520"FeedTrayTop Inlet Pressure"
1521        FeedTray.P = TRAYS(i).Inlet.P;
1522
1523"FeedTrayTop Inlet Composition"
1524        FeedTray.z = TRAYS(i).Inlet.z;
1525
1526"FeedTrayTop Inlet Vapour Fraction"
1527        FeedTray.v = TRAYS(i).Inlet.v;
1528
1529"FeedTrayTop Inlet Enthalpy"
1530        FeedTray.h = TRAYS(i).Inlet.h;
1531
1532else
1533
1534"Inlet Tray - Flow Sealed"
1535    0*'mol/h'= TRAYS(i).Inlet.F;
1536       
1537"Inlet Tray -  Temperature"
1538    300*'K' = TRAYS(i).Inlet.T;
1539       
1540"Inlet Tray -  Pressure"
1541    1*'atm' = TRAYS(i).Inlet.P;
1542       
1543"Inlet Tray -  Composition"
1544    0.1 = TRAYS(i).Inlet.z;
1545       
1546"Inlet Tray -  Vapour Fraction"
1547    0 = TRAYS(i).Inlet.v;
1548       
1549"Inlet Tray -  Enthalpy"
1550    0*'J/mol' = TRAYS(i).Inlet.h;
1551
1552end
1553
1554end
1555
1556#Heat Connectors
1557        Q_cond  = ConnectorHeatCondenser;
1558        Q_reb   = ConnectorHeatReboiler;
1559        Q_drum  = ConnectorHeatAccumulator;
1560
1561# Splitter Connector Equations
1562        ConnectorSplitterOut.T = LiquidDistillate.T;
1563        ConnectorSplitterOut.P = LiquidDistillate.P;
1564        ConnectorSplitterOut.F = LiquidDistillate.F;
1565        ConnectorSplitterOut.z = LiquidDistillate.z;
1566
1567# Reboiler Connector Equations
1568        ConnectorReboilerLout.T = BottomProduct.T;
1569        ConnectorReboilerLout.P = BottomProduct.P;
1570        ConnectorReboilerLout.F = BottomProduct.F;
1571        ConnectorReboilerLout.z = BottomProduct.z;
1572
1573CONNECTIONS
1574#vapor
1575        REBOILER.OutletVapour to TRAYS(NumberOfTrays).InletVapour;
1576        TRAYS(1).OutletVapour to CONDENSER.InletVapour;
1577
1578#liquid
1579        CONDENSER.OutletLiquid                          to REFLUX_DRUM.Inlet;   
1580        REFLUX_DRUM.OutletLiquid                        to SPLITTER.Inlet;
1581        SPLITTER.Reflux                                         to PUMP.Inlet; 
1582        PUMP.Outlet                                             to TRAYS(1).InletLiquid;
1583        TRAYS(NumberOfTrays).OutletLiquid       to REBOILER.InletLiquid;
1584
1585#Connectors
1586        ConnectorHeatCondenser          to CONDENSER.InletQ;
1587        ConnectorHeatReboiler           to REBOILER.InletQ;
1588        ConnectorHeatAccumulator        to REFLUX_DRUM.InletQ;
1589
1590        SPLITTER.Distillate             to ConnectorSplitterOut;
1591        REBOILER.OutletLiquid   to ConnectorReboilerLout;
1592
1593end
1594
1595Model Rectifier                                                         as ColumnBasic
1596
1597ATTRIBUTES
1598        Pallete         = true;
1599        Icon            = "icon/RefluxedCond";
1600        Brief           = "Model of a rectifier column with dynamic condenser.";
1601        Info            =
1602"== Specify ==
1603* the feed stream of each tray (Inlet);
1604* the Murphree eficiency for each tray Emv;
1605* the InletVapour stream of the bottom tray unless its flow;
1606* the pump pressure difference;
1607* the heat supllied in the condenser;
1608* the condenser vapor outlet flow (OutletVapour.F);
1609* both splitter outlet flows OR one of the splitter outlet flows and the splitter frac.
1610       
1611== Initial Conditions ==
1612* the TRAYS temperature (OutletLiquid.T);
1613* the TRAYS liquid level (Level) OR the TRAYS liquid flow (OutletLiquid.F);
1614* (NoComps - 1) OutletLiquid (OR OutletVapour) compositions for each tray;
1615       
1616* the condenser temperature (OutletLiquid.T);
1617* the condenser liquid level (Level);
1618* (NoComps - 1) OutletLiquid (OR OutletVapour) compositions;
1619";
1620
1621SET
1622        NumberOfFeeds = 1;
1623
1624VARIABLES
1625        CONDENSER       as condenser    (Brief="dymamic condenser without subcooling");
1626        SPLITTER        as splitter2    (Brief="splitter which separate reflux and distillate");
1627        PUMP            as pump                 (Brief="pump in reflux stream");
1628
1629        out     TI_cond         as control_signal       (Brief="Temperature Indicator of Condenser ", Protected = true, PosX=0.52, PosY=0);
1630        out     LI_cond         as control_signal       (Brief="Level Indicator of Condenser", Protected = true, PosX=1, PosY=0.084);
1631        out     PI_cond         as control_signal       (Brief="Pressure Indicator of Condenser", Protected = true, PosX=0.42, PosY=0);
1632       
1633        in      FeedTray        as stream               (Brief="Feed stream", PosX=0, PosY=0.55);
1634       
1635        out     VapourDistillate        as vapour_stream        (Brief="Vapour outlet stream From Top Condenser", PosX=0.66, PosY=0);
1636        out     LiquidDistillate        as liquid_stream        (Brief="Liquid outlet stream From Top Splitter", PosX=1, PosY=0.24);
1637
1638        in      Q_cond          as power (Brief="Heat supplied to Condenser",PosX=1, PosY=0.04, Protected = true);
1639
1640        in      VapourInlet             as stream                       (Brief="Vapour Inlet in the section", PosX=0.07, PosY=1);
1641        out     LiquidOutlet    as liquid_stream        (Brief="Liquid Outlet in the section", PosX=0.32, PosY=1);
1642
1643        in      ConnectorSplitterOut    as stream       (Brief="Connector for Liquid outlet stream From Top Splitter", Hidden=true);
1644        in      ConnectorCondenserVout  as stream       (Brief="Connector for Vapour outlet stream From Top Condenser", Hidden=true);
1645                VapourConnector                 as stream       (Brief="Vapour connection at the middle TRAYS", PosX=0.55, PosY=0,Hidden=true);
1646                ConnectorHeatCondenser  as power        (Brief="Connector for Heat supplied to Condenser", Hidden=true);
1647       
1648EQUATIONS
1649
1650        TI_cond = CONDENSER.TI;
1651        LI_cond = CONDENSER.LI;
1652        PI_cond = CONDENSER.PI;
1653       
1654for i in 1:NumberOfTrays do
1655
1656if i equal FeedTrayLocation(1) then   
1657
1658"FeedTrayTop Inlet Flow"       
1659        FeedTray.F= TRAYS(i).Inlet.F;
1660
1661"FeedTrayTop Inlet Temperature"
1662        FeedTray.T = TRAYS(i).Inlet.T;
1663
1664"FeedTrayTop Inlet Pressure"
1665        FeedTray.P = TRAYS(i).Inlet.P;
1666
1667"FeedTrayTop Inlet Composition"
1668        FeedTray.z = TRAYS(i).Inlet.z;
1669
1670"FeedTrayTop Inlet Vapour Fraction"
1671        FeedTray.v = TRAYS(i).Inlet.v;
1672
1673"FeedTrayTop Inlet Enthalpy"
1674        FeedTray.h = TRAYS(i).Inlet.h;
1675
1676else
1677
1678"Inlet Tray - Flow Sealed"
1679    0*'mol/h'= TRAYS(i).Inlet.F;
1680       
1681"Inlet Tray -  Temperature"
1682    300*'K' = TRAYS(i).Inlet.T;
1683       
1684"Inlet Tray -  Pressure"
1685    1*'atm' = TRAYS(i).Inlet.P;
1686       
1687"Inlet Tray -  Composition"
1688    0.1 = TRAYS(i).Inlet.z;
1689       
1690"Inlet Tray -  Vapour Fraction"
1691    0 = TRAYS(i).Inlet.v;
1692       
1693"Inlet Tray -  Enthalpy"
1694    0*'J/mol' = TRAYS(i).Inlet.h;
1695
1696end
1697
1698end
1699
1700        Q_cond = ConnectorHeatCondenser;
1701
1702# Condenser Connector Equations
1703        ConnectorCondenserVout.T = VapourDistillate.T;
1704        ConnectorCondenserVout.P = VapourDistillate.P;
1705        ConnectorCondenserVout.F = VapourDistillate.F;
1706        ConnectorCondenserVout.z = VapourDistillate.z;
1707       
1708# Splitter Connector Equations
1709        ConnectorSplitterOut.T = LiquidDistillate.T;
1710        ConnectorSplitterOut.P = LiquidDistillate.P;
1711        ConnectorSplitterOut.F = LiquidDistillate.F;
1712        ConnectorSplitterOut.z = LiquidDistillate.z;
1713       
1714        LiquidOutlet.F= TRAYS(NumberOfTrays).OutletLiquid.F;
1715        LiquidOutlet.T = TRAYS(NumberOfTrays).OutletLiquid.T;
1716        LiquidOutlet.P = TRAYS(NumberOfTrays).OutletLiquid.P;
1717        LiquidOutlet.z = TRAYS(NumberOfTrays).OutletLiquid.z;
1718
1719        VapourConnector.F= VapourInlet.F;
1720        VapourConnector.T = VapourInlet.T;
1721        VapourConnector.P = VapourInlet.P;
1722        VapourConnector.z = VapourInlet.z;
1723        VapourConnector.v = VapourInlet.v;
1724        VapourConnector.h = VapourInlet.h;
1725
1726CONNECTIONS
1727#vapor
1728        TRAYS(1).OutletVapour to CONDENSER.InletVapour;
1729
1730#liquid
1731        CONDENSER.OutletLiquid  to SPLITTER.Inlet;     
1732        SPLITTER.Outlet2        to PUMP.Inlet; 
1733        PUMP.Outlet             to TRAYS(1).InletLiquid;
1734
1735#Connectors
1736ConnectorHeatCondenser  to CONDENSER.InletQ;
1737VapourConnector                 to TRAYS(NumberOfTrays).InletVapour;
1738SPLITTER.Outlet1                to ConnectorSplitterOut;
1739CONDENSER.OutletVapour  to ConnectorCondenserVout;
1740
1741end
1742
1743
1744
1745Model Packed_Section_ColumnBasic
1746
1747ATTRIBUTES
1748        Pallete         = false;
1749        Icon            = "icon/PackedSectionColumn";
1750        Brief           = "Model of a packed column section.";
1751        Info            =
1752"== Model of a packed column section containing ==
1753* NStages theoretical stages.
1754       
1755== Specify ==
1756* the feed stream of each tray (Inlet);
1757* the InletLiquid stream of the top tray;
1758* the InletVapour stream of the bottom tray;
1759* the total pressure drop (dP) of the section.
1760       
1761== Initial Conditions ==
1762* the stages temperature (OutletLiquid.T);
1763* the stages liquid holdup;
1764* (NoComps - 1) OutletLiquid (OR OutletVapour) compositions for each tray.
1765";
1766       
1767PARAMETERS
1768
1769        outer PP                as Plugin       (Brief = "External Physical Properties", Type="PP");
1770        outer NComp     as Integer      (Brief="Number of components");
1771       
1772        low_flow                as flow_mol     (Brief ="Low Flow",Default = 1E-6, Hidden=true);
1773        low_pressure    as pressure     (Brief ="Low Pressure",Default = 1E-6, Hidden=true);
1774        zero_flow               as flow_mol     (Brief ="No Flow",Default = 0, Hidden=true);
1775       
1776        NumberOfFeeds                                           as Integer      (Brief="Number of Feed Stages",Default=3,Protected=true);
1777        NumberOfStages                                          as Integer      (Brief="Number of Stages", Default=3);
1778        FeedStageLocation(NumberOfFeeds)        as Integer      (Brief="Feed Stage Location",Default=2);
1779       
1780        PackingHeight           as length               (Brief="Height of packing");
1781        HeatSupply                      as heat_rate    (Brief="Rate of heat supply");
1782        ColumnDiameter          as length               (Brief="Column diameter");
1783        VoidFraction            as Real                 (Brief="Void fraction of packing, (m^3 void space/m^3 packed bed)");
1784        ResistanceCoeff         as positive     (Brief="Resistance coefficient on the liquid load", Default=1);
1785        AreaPerPackingVol       as Real                 (Brief="surface area per packing volume", Unit='m^2/m^3');
1786       
1787        V                               as volume                       (Brief="Total Volume of the tray",Protected=true);
1788        Pi                              as constant             (Brief="Pi Number",Default=3.14159265, Symbol = "\pi",Hidden=true);
1789        Gconst                  as acceleration         (Brief="Gravity Acceleration",Default=9.81,Hidden=true);
1790        HETP                    as length                       (Brief="the Height Equivalent to a Theoretical Plate",Protected=true);
1791        ColumnArea              as area                         (Brief="Column Sectional Cross Area",Protected=true);
1792       
1793        VapourFlow as Switcher(Valid = ["on", "off"], Default = "on",Hidden=true);
1794
1795
1796VARIABLES
1797
1798        INITIALIZATION  as InitializeStage      (Brief = "Column Model Initialization");
1799        CONTROL                 as ControlSection (Brief="Column Model Control");
1800       
1801        out     TCI as control_signal   (Brief="Temperature  Indicator", Protected = true, PosX=1, PosY=0.73);
1802        out     PCI as control_signal   (Brief="Pressure Indicator", Protected = true, PosX=0, PosY=0.24);
1803       
1804        in      LiquidInlet             as      stream                          (Brief="Liquid Inlet in the section", PosX=0.70, PosY=0);
1805        out     VapourOutlet            as vapour_stream        (Brief="Vapour Outlet in the section", PosX=0.30, PosY=0);
1806       
1807        in              VapourInlet             as stream                               (Brief="Vapour Inlet in the section", PosX=0.30, PosY=1);
1808        out     LiquidOutlet            as liquid_stream                (Brief="Liquid Outlet in the section", PosX=0.70, PosY=1);
1809       
1810        LiquidConnector as stream       (Brief="Liquid connection at the middle STAGES", PosX=0.75, PosY=1,Hidden=true);
1811        VapourConnector as stream       (Brief="Vapour connection at the middle STAGES", PosX=0.55, PosY=0,Hidden=true);
1812       
1813        STAGES(NumberOfStages) as packedStage;
1814        PressureDrop               as pressure (Brief="Column Pressure Drop", Protected=true);
1815       
1816SET
1817       
1818        ColumnArea = 0.25*Pi*ColumnDiameter^2;
1819        HETP =PackingHeight/NumberOfStages;     
1820        V = HETP * ColumnArea;
1821       
1822        low_pressure = 1E-4 * 'atm';
1823        low_flow = 1E-6 * 'kmol/h';
1824        zero_flow = 0 * 'kmol/h';
1825       
1826CONNECTIONS
1827
1828        STAGES([2:NumberOfStages]).OutletVapour         to STAGES([1:NumberOfStages-1]).InletVapour;
1829        STAGES([1:NumberOfStages-1]).OutletLiquid       to STAGES([2:NumberOfStages]).InletLiquid;
1830        LiquidConnector                                                         to STAGES(1).InletLiquid;
1831        VapourConnector                                                         to STAGES(NumberOfStages).InletVapour;
1832
1833EQUATIONS
1834
1835        LiquidConnector.F= LiquidInlet.F;
1836        LiquidConnector.T = LiquidInlet.T;
1837        LiquidConnector.P = LiquidInlet.P;
1838        LiquidConnector.z = LiquidInlet.z;
1839        LiquidConnector.v = LiquidInlet.v;
1840        LiquidConnector.h = LiquidInlet.h;
1841       
1842        VapourConnector.F= VapourInlet.F;
1843        VapourConnector.T = VapourInlet.T;
1844        VapourConnector.P = VapourInlet.P;
1845        VapourConnector.z = VapourInlet.z;
1846        VapourConnector.v = VapourInlet.v;
1847        VapourConnector.h = VapourInlet.h;
1848       
1849        LiquidOutlet.F= STAGES(NumberOfStages).OutletLiquid.F;
1850        LiquidOutlet.T = STAGES(NumberOfStages).OutletLiquid.T;
1851        LiquidOutlet.P = STAGES(NumberOfStages).OutletLiquid.P;
1852        LiquidOutlet.z = STAGES(NumberOfStages).OutletLiquid.z;
1853       
1854        VapourOutlet.F= STAGES(1).OutletVapour.F;
1855        VapourOutlet.T = STAGES(1).OutletVapour.T;
1856        VapourOutlet.P = STAGES(1).OutletVapour.P;
1857        VapourOutlet.z = STAGES(1).OutletVapour.z;
1858
1859"Tray Temperature Indicator"   
1860        #TCI*'K' = TRAYS(min([NumberOfTrays, CONTROL.Tindicator_TrayNumber])).OutletVapour.T;
1861        TCI*'K' = STAGES(CONTROL.Tindicator_TrayNumber).OutletVapour.T;
1862
1863"Tray Pressure Indicator"       
1864        #PCI*'atm' = TRAYS(min([NumberOfTrays, CONTROL.Pindicator_TrayNumber])).OutletVapour.P;
1865        PCI*'atm' = STAGES(CONTROL.Pindicator_TrayNumber).OutletVapour.P;
1866
1867"PressureDrop"
1868        PressureDrop = STAGES(NumberOfStages).OutletLiquid.P - STAGES(1).OutletLiquid.P;
1869
1870for i in [1:NumberOfStages] do
1871
1872switch VapourFlow
1873       
1874        case "on":
1875"Pressure drop and Vapor flow, Billet (4-58)"
1876        STAGES(i).deltaP/HETP  = ResistanceCoeff *( 0.5*AreaPerPackingVol + 2/ColumnDiameter) * 1/((VoidFraction-STAGES(i).hl)^3) * (STAGES(i).uV^2) * STAGES(i).rhoV;
1877       
1878        when STAGES(i).InletVapour.F < low_flow switchto "off";
1879       
1880        case "off":
1881"Vapour Flow"
1882        STAGES(i).InletVapour.F = zero_flow;
1883       
1884        when STAGES(i).deltaP > low_pressure switchto "on";
1885
1886end
1887
1888"Energy Balance"
1889        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
1890        - STAGES(i).OutletVapour.F*STAGES(i).OutletVapour.h + HeatSupply );
1891
1892"Energy Holdup"
1893        STAGES(i).E = STAGES(i).ML*STAGES(i).OutletLiquid.h + STAGES(i).MV*STAGES(i).OutletVapour.h - STAGES(i).OutletLiquid.P*V;
1894       
1895"Geometry Constraint"
1896        V*VoidFraction= STAGES(i).ML*STAGES(i).vL + STAGES(i).MV*STAGES(i).vV;
1897       
1898"Volume flow rate of vapor, m^3/m^2/s"
1899        STAGES(i).uV * (V*VoidFraction/HETP - STAGES(i).Al) = STAGES(i).InletVapour.F * STAGES(i).vV;
1900
1901"Liquid holdup"
1902        STAGES(i).hl*V*VoidFraction = STAGES(i).ML*STAGES(i).vL;
1903       
1904"Liquid velocity as a function of liquid holdup, Billet (4-27)"
1905        STAGES(i).hl^3 = (12/Gconst) * AreaPerPackingVol^2 * (STAGES(i).miL/STAGES(i).rhoL) * STAGES(i).uL;
1906        #STAGES(i).hl = (12*STAGES(i).miL*AreaPerPackingVol^2*STAGES(i).uL/STAGES(i).rhoL/Gconst)^1/3;
1907
1908"Area occupied by the liquid"
1909        STAGES(i).Al = STAGES(i).ML*STAGES(i).vL/HETP;
1910
1911end
1912
1913INITIAL
1914
1915for i in 1:NumberOfStages do
1916
1917"The initial temperature of the STAGES"
1918        STAGES(i).OutletLiquid.T = INITIALIZATION.TopStageTemperature+(INITIALIZATION.BottomStageTemperature-INITIALIZATION.TopStageTemperature)*((i-1)/(NumberOfStages-1));
1919
1920"The Column Holdup of the STAGES"
1921        STAGES(i).hl = INITIALIZATION.ColumnHoldup;
1922
1923end
1924
1925for i in 1:NComp-1 do
1926       
1927for j in 1:NumberOfStages do
1928
1929"The initial composition of the TRAYS"
1930        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));
1931
1932end
1933
1934end
1935
1936end
1937
1938Model Packed_Section_Column     as Packed_Section_ColumnBasic
1939
1940        ATTRIBUTES
1941        Pallete         = true;
1942        Icon            = "icon/PackedSectionColumn";
1943        Brief           = "Model of a packed column section.";
1944        Info            =
1945"== Model of a packed column section containing ==
1946* NStages theoretical stages.
1947       
1948== Specify ==
1949* the feed stream of each tray (Inlet);
1950* the InletLiquid stream of the top tray;
1951* the InletVapour stream of the bottom tray;
1952* the total pressure drop (dP) of the section.
1953       
1954== Initial Conditions ==
1955* the stages temperature (OutletLiquid.T);
1956* the stages liquid holdup;
1957* (NoComps - 1) OutletLiquid (OR OutletVapour) compositions for each tray.
1958";
1959
1960SET
1961        NumberOfFeeds = 1;
1962
1963VARIABLES
1964       
1965        in      FeedStage       as stream               (Brief="Feed stream", PosX=0, PosY=0.55);
1966
1967EQUATIONS
1968#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1969# Equating Feed Tray Variables to Trays Variables
1970#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1971for i in 1:NumberOfStages do
1972
1973if   i equal FeedStageLocation(1) then   
1974
1975"FeedTrayTop Inlet Flow"       
1976        FeedStage.F= STAGES(i).Inlet.F;
1977
1978"FeedTrayTop Inlet Temperature"
1979        FeedStage.T = STAGES(i).Inlet.T;
1980
1981"FeedTrayTop Inlet Pressure"
1982        FeedStage.P = STAGES(i).Inlet.P;
1983
1984"FeedTrayTop Inlet Composition"
1985        FeedStage.z = STAGES(i).Inlet.z;
1986
1987"FeedTrayTop Inlet Vapour Fraction"
1988        FeedStage.v = STAGES(i).Inlet.v;
1989
1990"FeedTrayTop Inlet Enthalpy"
1991        FeedStage.h = STAGES(i).Inlet.h;
1992
1993else
1994
1995"Inlet Tray - Flow Sealed"
1996    0*'mol/h'= STAGES(i).Inlet.F;
1997       
1998"Inlet Tray -  Temperature"
1999    300*'K' = STAGES(i).Inlet.T;
2000       
2001"Inlet Tray -  Pressure"
2002    1*'atm' = STAGES(i).Inlet.P;
2003       
2004"Inlet Tray -  Composition"
2005    0.1 = STAGES(i).Inlet.z;
2006       
2007"Inlet Tray -  Vapour Fraction"
2008    0 = STAGES(i).Inlet.v;
2009       
2010"Inlet Tray -  Enthalpy"
2011    0*'J/mol' = STAGES(i).Inlet.h;
2012
2013end
2014
2015end
2016
2017end
2018
2019Model Packed_Section_Column2    as Packed_Section_ColumnBasic
2020
2021        ATTRIBUTES
2022        Pallete         = true;
2023        Icon            = "icon/PackedSectionColumn";
2024        Brief           = "Model of a packed column section.";
2025        Info            =
2026"== Model of a packed column section containing ==
2027* NStages theoretical stages.
2028       
2029== Specify ==
2030* the feed stream of each tray (Inlet);
2031* the InletLiquid stream of the top tray;
2032* the InletVapour stream of the bottom tray;
2033* the total pressure drop (dP) of the section.
2034       
2035== Initial Conditions ==
2036* the stages temperature (OutletLiquid.T);
2037* the stages liquid holdup;
2038* (NoComps - 1) OutletLiquid (OR OutletVapour) compositions for each tray.
2039";
2040
2041SET
2042        NumberOfFeeds = 2;
2043
2044VARIABLES
2045       
2046        in      FeedStageOne    as stream               (Brief="Feed stream", PosX=0, PosY=0.45);
2047        in      FeedStageTwo    as stream               (Brief="Feed stream", PosX=0, PosY=0.65);
2048
2049EQUATIONS
2050#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2051# Equating Feed Stage Variables to Stages Variables
2052#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2053
2054for i in 1:NumberOfStages do
2055
2056if   i equal FeedStageLocation(1) then   
2057
2058"FeedTrayTop Inlet Flow"       
2059        FeedStageOne.F= STAGES(i).Inlet.F;
2060
2061"FeedTrayTop Inlet Temperature"
2062        FeedStageOne.T = STAGES(i).Inlet.T;
2063
2064"FeedTrayTop Inlet Pressure"
2065        FeedStageOne.P = STAGES(i).Inlet.P;
2066
2067"FeedTrayTop Inlet Composition"
2068        FeedStageOne.z = STAGES(i).Inlet.z;
2069
2070"FeedTrayTop Inlet Vapour Fraction"
2071        FeedStageOne.v = STAGES(i).Inlet.v;
2072
2073"FeedTrayTop Inlet Enthalpy"
2074        FeedStageOne.h = STAGES(i).Inlet.h;
2075
2076else if   i equal FeedStageLocation(2) then   
2077
2078"FeedTrayBottom Inlet Flow"     
2079        FeedStageTwo.F= STAGES(i).Inlet.F;
2080
2081"FeedTrayBottom Inlet Temperature"
2082        FeedStageTwo.T = STAGES(i).Inlet.T;
2083
2084"FeedTrayBottom Inlet Pressure"
2085        FeedStageTwo.P = STAGES(i).Inlet.P;
2086
2087"FeedTrayBottom Inlet Composition"
2088        FeedStageTwo.z = STAGES(i).Inlet.z;
2089
2090"FeedTrayBottom Inlet Vapour Fraction"
2091        FeedStageTwo.v = STAGES(i).Inlet.v;
2092
2093"FeedTrayBottom Inlet Enthalpy"
2094        FeedStageTwo.h = STAGES(i).Inlet.h;
2095
2096else
2097
2098"Inlet Tray - Flow Sealed"
2099    0*'mol/h'= STAGES(i).Inlet.F;
2100       
2101"Inlet Tray -  Temperature"
2102    300*'K' = STAGES(i).Inlet.T;
2103       
2104"Inlet Tray -  Pressure"
2105    1*'atm' = STAGES(i).Inlet.P;
2106       
2107"Inlet Tray -  Composition"
2108    0.1 = STAGES(i).Inlet.z;
2109       
2110"Inlet Tray -  Vapour Fraction"
2111    0 = STAGES(i).Inlet.v;
2112       
2113"Inlet Tray -  Enthalpy"
2114    0*'J/mol' = STAGES(i).Inlet.h;
2115
2116end
2117
2118end
2119
2120end
2121
2122end
2123
2124Model PackedDistillation_kettle_cond as Packed_Section_ColumnBasic
2125        ATTRIBUTES
2126        Pallete         = true;
2127        Icon            = "icon/PackedDistillationKettleCond";
2128        Brief           = "Model of a distillation column with dynamic condenser and dynamic reboiler.";
2129        Info            =
2130"== Specify ==
2131* the feed stream of each tray (Inlet);
2132* the pump pressure difference;
2133* the total pressure drop (dP) of the packing;
2134* the heat supllied in reboiler and condenser;
2135* the condenser vapor outlet flow (OutletVapour.F);
2136* the reboiler liquid outlet flow (OutletLiquid.F);
2137* both splitter outlet flows OR one of the splitter outlet flows and the splitter frac.
2138       
2139== Initial Conditions ==
2140* the stages temperature (OutletLiquid.T);
2141* the stages initial molar holdup;
2142* (NoComps - 1) OutletLiquid (OR OutletVapour) compositions for each stage;
2143       
2144* the condenser temperature (OutletLiquid.T);
2145* the condenser liquid level (Level);
2146* (NoComps - 1) OutletLiquid (OR OutletVapour) compositions;
2147       
2148* the reboiler temperature (OutletLiquid.T);
2149* the reboiler liquid level (Level);
2150* (NoComps - 1) OutletLiquid (OR OutletVapour) compositions.
2151";
2152       
2153PARAMETERS
2154
2155        #VapourFlow as Switcher (Valid = ["on", "off"], Hidden = true ,Default = "on");
2156       
2157VARIABLES
2158#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2159# Column Devices
2160#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++     
2161        CONDENSER       as condenser    (Brief="dymamic condenser");
2162        REBOILER        as reboiler             (Brief="kettle reboiler");
2163        SPLITTER        as splitter2            (Brief="splitter which separate reflux and distillate");
2164        PUMP            as pump                 (Brief="pump in reflux stream");
2165#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2166# Heat Ports
2167#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++     
2168        in      HeatToReboiler  as power (Brief="Heat supplied to Reboiler",Protected = true, PosX=1, PosY=0.885);
2169        in      HeatToCondenser as power (Brief="Heat supplied to Condenser", Protected = true, PosX=1, PosY=0.034);
2170#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2171# Column Products
2172#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++     
2173        out     VapourDistillate        as vapour_stream        (Brief="Vapour outlet stream From Top Condenser", PosX=0.66, PosY=0);
2174        out     LiquidDistillate        as liquid_stream        (Brief="Liquid outlet stream From Top Splitter", PosX=1, PosY=0.20);
2175        out     BottomProduct           as liquid_stream        (Brief="Liquid outlet stream From Reboiler", PosX=0.68, PosY=1);
2176#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2177# Column Connectors
2178#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++             
2179        in      ConnectorCondenserVout  as stream       (Brief="Connector for Vapour outlet stream From Top Condenser", Hidden=true);
2180        in      ConnectorSplitterOut    as stream       (Brief="Connector for Liquid outlet stream From Top Splitter", Hidden=true);
2181        in      ConnectorReboilerLout   as stream       (Brief="Connector for Liquid outlet stream From Reboiler", Hidden=true);
2182                ConnectorHeatReboiler   as power        (Brief="Heat supplied to Reboiler", Hidden=true);
2183                ConnectorHeatCondenser  as power        (Brief="Heat supplied to Condenser", Hidden=true);
2184
2185CONNECTIONS
2186
2187#vapor
2188        #REBOILER.OutletVapour          to STAGES(NumberOfStages).VapourConnector;
2189        STAGES(1).OutletVapour          to CONDENSER.InletVapour;
2190
2191#liquid
2192        CONDENSER.OutletLiquid                          to SPLITTER.Inlet;     
2193        SPLITTER.Outlet2                                to PUMP.Inlet;
2194        #PUMP.Outlet                                    to STAGES(1).InletLiquid;
2195        STAGES(NumberOfStages).OutletLiquid     to REBOILER.InletLiquid;
2196
2197#Connectors
2198ConnectorHeatReboiler   to REBOILER.InletQ;
2199ConnectorHeatCondenser  to CONDENSER.InletQ;
2200
2201CONDENSER.OutletVapour          to ConnectorCondenserVout;
2202SPLITTER.Outlet1                to ConnectorSplitterOut;
2203REBOILER.OutletLiquid           to ConnectorReboilerLout;
2204
2205EQUATIONS
2206        HeatToReboiler  = ConnectorHeatReboiler;
2207        HeatToCondenser = ConnectorHeatCondenser;
2208       
2209# Condenser Connector Equations
2210        ConnectorCondenserVout.T = VapourDistillate.T;
2211        ConnectorCondenserVout.P = VapourDistillate.P;
2212        ConnectorCondenserVout.F = VapourDistillate.F;
2213        ConnectorCondenserVout.z = VapourDistillate.z;
2214
2215# Splitter Connector Equations
2216        ConnectorSplitterOut.T = LiquidDistillate.T;
2217        ConnectorSplitterOut.P = LiquidDistillate.P;
2218        ConnectorSplitterOut.F = LiquidDistillate.F;
2219        ConnectorSplitterOut.z = LiquidDistillate.z;
2220
2221# Reboiler Connector Equations
2222        ConnectorReboilerLout.T = BottomProduct.T;
2223        ConnectorReboilerLout.P = BottomProduct.P;
2224        ConnectorReboilerLout.F = BottomProduct.F;
2225        ConnectorReboilerLout.z = BottomProduct.z;
2226
2227end
2228
2229#*
2230Model Rectifier_subcooling as Section_ColumnBasicX
2231
2232ATTRIBUTES
2233        Pallete         = true;
2234        Icon            = "icon/RefluxedSubcooling";
2235        Brief           = "Model of a rectifier column with steady condenser.";
2236        Info            =
2237"== Specify ==
2238* the feed stream of each tray (Inlet);
2239* the Murphree eficiency for each tray Emv;
2240* the InletVapour stream of the bottom tray unless its flow;
2241* the pump head;
2242* the condenser pressure drop;
2243* the heat supllied in  the top tank;
2244* the heat supllied in condenser;
2245* both  top splitter outlet flows OR one of the splitter outlet flows and the splitter frac.
2246       
2247== Initial Conditions ==
2248* the TRAYS temperature (OutletLiquid.T);
2249* the TRAYS liquid level (Level) OR the TRAYS liquid flow (OutletLiquid.F);
2250* (NoComps - 1) OutletLiquid (OR OutletVapour) compositions for each tray;
2251       
2252* the top tank temperature (OutletLiquid.T);
2253* the top tank liquid level (Level);
2254* (NoComps - 1) OutletLiquid (OR OutletVapour) compositions;
2255";
2256       
2257PARAMETERS
2258        CondenserVapourFlow             as Switcher     (Valid = ["on", "off"], Default = "on",Hidden=true);
2259
2260VARIABLES
2261#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2262# Column Vapour and Liquid Draw Sides
2263#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2264        out     VapourDrawOff   as vapour_stream        (Brief="Vapour Outlet in the section", PosX=1, PosY=0.485,Protected = true);
2265        out     LiquidDrawOff   as liquid_stream        (Brief="Liquid Outlet in the section", PosX=1, PosY=0.535,Protected = true);
2266#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2267# Column Devices
2268#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2269        CONDENSER               as condenserSteady      (Brief="steady state condenser with subcooling");
2270        ACCUMULATOR             as tank_cylindrical     (Brief="vessel drum (layed cilinder)");
2271        SPLITTER                as splitter2                    (Brief="plitter which separate reflux and distillate");
2272        PUMP                    as pump                         (Brief="pump in reflux stream");
2273        alfaTopo                as Real;
2274#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2275# Column Bottom outlets
2276#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2277        in      VapourInlet             as stream                       (Brief="Vapour Inlet in the section", PosX=0.07, PosY=1);
2278        out     LiquidOutlet    as liquid_stream        (Brief="Liquid Outlet in the section", PosX=0.32, PosY=1);
2279#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2280# Heat Ports
2281#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2282        in      HeatToCondenser         as power        (Brief="Heat supplied to Condenser", PosX=1, PosY=0.070, Protected=true);
2283        in      HeatToAccumulator       as power        (Brief="Heat supplied to Top Accumulator", PosX=1, PosY=0.23, Protected=true);
2284#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2285# Column Top Product
2286#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2287        out     LiquidDistillate                as liquid_stream        (Brief="Liquid outlet stream From Top Splitter", PosX=1, PosY=0.285);
2288#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2289# Column Connectors
2290#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2291in      ConnectorSplitterTop            as stream       (Brief="Connector for Liquid outlet stream From Top Splitter", Hidden=true);
2292        VapourConnector                         as stream       (Brief="Vapour connection at the middle TRAYS", PosX=0.55, PosY=0,Hidden=true);
2293        ConnectorHeatCondenser          as power        (Brief="Connector for Heat supplied to Condenser", Hidden=true);
2294        ConnectorHeatAccumulator        as power        (Brief="Connector for Heat supplied to Top Accumulator", Hidden=true);
2295
2296EQUATIONS
2297#Heat Connectors
2298        HeatToCondenser         = ConnectorHeatCondenser;
2299        HeatToAccumulator       = ConnectorHeatAccumulator;
2300       
2301        LiquidOutlet.F= TRAYS(NumberOfTrays).OutletLiquid.F;
2302        LiquidOutlet.T = TRAYS(NumberOfTrays).OutletLiquid.T;
2303        LiquidOutlet.P = TRAYS(NumberOfTrays).OutletLiquid.P;
2304        LiquidOutlet.z = TRAYS(NumberOfTrays).OutletLiquid.z;
2305
2306        VapourConnector.F= VapourInlet.F;
2307        VapourConnector.T = VapourInlet.T;
2308        VapourConnector.P = VapourInlet.P;
2309        VapourConnector.z = VapourInlet.z;
2310        VapourConnector.v = VapourInlet.v;
2311        VapourConnector.h = VapourInlet.h;
2312       
2313# Splitter Connector Equations
2314        ConnectorSplitterTop.T = LiquidDistillate.T;
2315        ConnectorSplitterTop.P = LiquidDistillate.P;
2316        ConnectorSplitterTop.F = LiquidDistillate.F;
2317        ConnectorSplitterTop.z = LiquidDistillate.z;
2318
2319        VapourDrawOff.F*VapSideTrayIndex= TRAYS.VapourSideStream.F;
2320        VapourDrawOff.T = TRAYS(VapourSideStreamLocation).VapourSideStream.T;
2321        VapourDrawOff.P = TRAYS(VapourSideStreamLocation).VapourSideStream.P;
2322        VapourDrawOff.z = TRAYS(VapourSideStreamLocation).VapourSideStream.z;
2323
2324        LiquidDrawOff.F*LiqSideTrayIndex= TRAYS.LiquidSideStream.F;
2325        LiquidDrawOff.T = TRAYS(LiquidSideStreamLocation).LiquidSideStream.T;
2326        LiquidDrawOff.P = TRAYS(LiquidSideStreamLocation).LiquidSideStream.P;
2327        LiquidDrawOff.z = TRAYS(LiquidSideStreamLocation).LiquidSideStream.z;
2328
2329        VapourDrawOffFlow = VapourDrawOff.F;
2330        LiquidDrawOffFlow = LiquidDrawOff.F;
2331       
2332switch CondenserVapourFlow
2333
2334        case "on":
2335                CONDENSER.InletVapour.F*TRAYS(1).vV = alfaTopo *Ah * sqrt(2*(TRAYS(1).OutletVapour.P -
2336                CONDENSER.OutletLiquid.P + 1e-8 * 'atm') / (alfa*TRAYS(1).rhoV));
2337        when CONDENSER.InletVapour.F < 1e-6 * 'kmol/h' switchto "off";
2338               
2339        case "off":
2340                CONDENSER.InletVapour.F = 0 * 'mol/s';
2341        when TRAYS(1).OutletVapour.P > CONDENSER.OutletLiquid.P + 1e-1 * 'atm' switchto "on";
2342
2343end     
2344
2345CONNECTIONS
2346#vapor
2347        TRAYS(1).OutletVapour to CONDENSER.InletVapour;
2348
2349#liquid
2350        CONDENSER.OutletLiquid          to ACCUMULATOR.Inlet;   
2351        ACCUMULATOR.Outlet                                      to SPLITTER.Inlet;
2352        SPLITTER.Outlet2                to PUMP.Inlet; 
2353        PUMP.Outlet                                             to TRAYS(1).InletLiquid;
2354
2355#Connectors
2356        VapourConnector                         to TRAYS(NumberOfTrays).InletVapour;
2357        ConnectorHeatCondenser                  to CONDENSER.InletQ;
2358        SPLITTER.Outlet1        to ConnectorSplitterTop;
2359        ConnectorHeatAccumulator                        to ACCUMULATOR.InletQ;
2360
2361end
2362
2363Model Reboiled_Stripping_kettle as Section_ColumnBasicX
2364       
2365ATTRIBUTES
2366        Pallete         = true;
2367        Icon            = "icon/ReboiledKettle";
2368        Brief           = "Model of a reboiled stripping column with dynamic reboiler.";
2369        Info            =
2370"== Specify ==
2371* the feed stream of each tray (Inlet);
2372* the Murphree eficiency for each tray Emv;
2373* the vapour flow leaving the top of the column;
2374* the InletLiquidiquid stream of the top tray;
2375* the heat supllied in the reboiler;
2376* the reboiler liquid outlet flow (OutletLiquid.F);
2377       
2378== Initial Conditions ==
2379* the TRAYS temperature (OutletLiquid.T);
2380* the TRAYS liquid level (Level) OR the TRAYS liquid flow (OutletLiquid.F);
2381* (NoComps - 1) OutletLiquid (OR OutletVapour) compositions for each tray;
2382       
2383* the reboiler temperature (OutletLiquid.T);
2384* the reboiler liquid level (Level);
2385* (NoComps - 1) OutletLiquid (OR OutletVapour) compositions.
2386";
2387
2388VARIABLES
2389#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2390# Column Vapour and Liquid Draw Sides
2391#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2392        out     VapourDrawOff   as vapour_stream        (Brief="Vapour Outlet in the section", PosX=1, PosY=0.28,Protected = true);
2393        out     LiquidDrawOff   as liquid_stream        (Brief="Liquid Outlet in the section", PosX=1, PosY=0.33,Protected = true);
2394#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2395# Column Devices
2396#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 
2397        REBOILER as reboiler (Brief="Kettle Reboiler");
2398#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2399# Heat Port
2400#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++     
2401        in      HeatToReboiler  as power        (Brief="Heat supplied to Reboiler",PosX=1, PosY=0.865,Protected=true);
2402#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2403# Column Top Outlets
2404#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++             
2405        in      LiquidInlet             as      stream                  (Brief="Liquid Inlet in the section", PosX=0.30, PosY=0);
2406        out     VapourOutlet    as vapour_stream        (Brief="Vapour Outlet in the section", PosX=0.07, PosY=0);
2407#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2408# Column Bottom Product
2409#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++     
2410        out     BottomProduct   as liquid_stream        (Brief="Liquid outlet stream From Reboiler", PosX=0.68, PosY=1);
2411#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2412# Column Connectors
2413#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2414        in      ConnectorReboilerLout   as stream       (Brief="Connector for Liquid outlet stream From Reboiler", Hidden=true);
2415                LiquidConnector                 as stream       (Brief="Liquid connection at the middle TRAYS", PosX=0.75, PosY=1,Hidden=true);
2416                ConnectorHeatReboiler   as power        (Brief="Connector for Heat supplied to Reboiler", Hidden=true);
2417
2418CONNECTIONS
2419#vapor
2420        REBOILER.OutletVapour to TRAYS(NumberOfTrays).InletVapour;
2421       
2422#liquid
2423        TRAYS(NumberOfTrays).OutletLiquid to REBOILER.InletLiquid;
2424
2425#Connectors
2426REBOILER.OutletLiquid           to ConnectorReboilerLout;
2427LiquidConnector                 to TRAYS(1).InletLiquid;
2428ConnectorHeatReboiler   to REBOILER.InletQ;
2429
2430EQUATIONS
2431#Heat Connectors
2432        HeatToReboiler = ConnectorHeatReboiler;
2433       
2434        LiquidConnector.F= LiquidInlet.F;
2435        LiquidConnector.T = LiquidInlet.T;
2436        LiquidConnector.P = LiquidInlet.P;
2437        LiquidConnector.z = LiquidInlet.z;
2438        LiquidConnector.v = LiquidInlet.v;
2439        LiquidConnector.h = LiquidInlet.h;
2440       
2441        VapourOutlet.F= TRAYS(1).OutletVapour.F;
2442        VapourOutlet.T = TRAYS(1).OutletVapour.T;
2443        VapourOutlet.P = TRAYS(1).OutletVapour.P;
2444        VapourOutlet.z = TRAYS(1).OutletVapour.z;
2445       
2446# Reboiler Connector Equations
2447        ConnectorReboilerLout.T = BottomProduct.T;
2448        ConnectorReboilerLout.P = BottomProduct.P;
2449        ConnectorReboilerLout.F = BottomProduct.F;
2450        ConnectorReboilerLout.z = BottomProduct.z;
2451       
2452        VapourDrawOff.F*VapSideTrayIndex= TRAYS.VapourSideStream.F;
2453        VapourDrawOff.T = TRAYS(VapourSideStreamLocation).VapourSideStream.T;
2454        VapourDrawOff.P = TRAYS(VapourSideStreamLocation).VapourSideStream.P;
2455        VapourDrawOff.z = TRAYS(VapourSideStreamLocation).VapourSideStream.z;
2456
2457        LiquidDrawOff.F*LiqSideTrayIndex= TRAYS.LiquidSideStream.F;
2458        LiquidDrawOff.T = TRAYS(LiquidSideStreamLocation).LiquidSideStream.T;
2459        LiquidDrawOff.P = TRAYS(LiquidSideStreamLocation).LiquidSideStream.P;
2460        LiquidDrawOff.z = TRAYS(LiquidSideStreamLocation).LiquidSideStream.z;
2461
2462        VapourDrawOffFlow = VapourDrawOff.F;
2463        LiquidDrawOffFlow = LiquidDrawOff.F;
2464
2465end
2466
2467Model Reboiled_Stripping_thermosyphon as Section_ColumnBasicX
2468
2469ATTRIBUTES
2470        Pallete         = true;
2471        Icon            = "icon/ReboiledThermosyphon";
2472        Brief           = "Model of a reboiled stripping column with steady reboiler.";
2473        Info            =
2474"== Specify ==
2475* the feed stream of each tray (Inlet);
2476* the Murphree eficiency for each tray (Emv);
2477* the vapour flow leaving the top of the column;
2478* the InletLiquidiquid stream of the top tray;
2479* the heat supllied in bottom tank;
2480* the heat supllied in the reboiler;
2481* the Outlet1 flow in the bottom splitter (spbottom.Outlet1.F) that corresponds to the bottom product;
2482       
2483== Initial Conditions ==
2484* the TRAYS temperature (OutletLiquid.T);
2485* the TRAYS liquid level (Level) OR the TRAYS liquid flow (OutletLiquid.F);
2486* (NoComps - 1) OutletLiquid (OR OutletVapour) compositions for each tray;
2487
2488* the bottom tank temperature (OutletLiquid.T);
2489* the bottom tank liquid level (Level);
2490* (NoComps - 1) OutletLiquid (OR OutletVapour) compositions.
2491";
2492
2493VARIABLES
2494#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2495# Column Vapour and Liquid Draw Sides
2496#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2497        out     VapourDrawOff   as vapour_stream        (Brief="Vapour Outlet in the section", PosX=1, PosY=0.28,Protected = true);
2498        out     LiquidDrawOff   as liquid_stream        (Brief="Liquid Outlet in the section", PosX=1, PosY=0.33,Protected = true);
2499#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2500# Column Devices
2501#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++     
2502        REBOILER                as reboilerSteady       (Brief="steady state reboiler (thermosyphon)");
2503        SPLITTER                as splitter2            (Brief="splitter which separate the bottom product and the stream to reboiler");
2504        ACCUMULATOR     as tank                         (Brief="vessel in the bottom of column");
2505#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2506# Heat Ports
2507#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++     
2508        in      HeatToReboiler          as power        (Brief="Heat supplied to Reboiler",PosX=1, PosY=0.84,Protected=true);
2509        in      HeatToAccumulator       as power        (Brief="Heat supplied to Bottom Vessel",PosX=0, PosY=0.91,Protected=true);
2510#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2511# Column Top Outlets
2512#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++     
2513        in      LiquidInlet             as      stream                  (Brief="Liquid Inlet in the section", PosX=0.32, PosY=0);
2514        out     VapourOutlet    as vapour_stream        (Brief="Vapour Outlet in the section", PosX=0.07, PosY=0);
2515#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2516# Column Bottom Product
2517#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++     
2518        out     BottomProduct   as liquid_stream        (Brief="Liquid outlet stream From Reboiler", PosX=0.19, PosY=1);
2519        LiquidConnector         as stream                       (Brief="Liquid connection at the middle TRAYS", PosX=0.75, PosY=1,Hidden=true);
2520#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2521# Column Connectors
2522#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2523        in      ConnectorSplitterBottom         as stream       (Brief="Connector for Liquid outlet stream From Reboiler", Hidden=true);
2524        ConnectorHeatReboiler                   as power        (Brief="Connector for Heat supplied to Reboiler", Hidden=true);
2525        ConnectorHeatAccumulator                as power        (Brief="Connector for Heat supplied to Bottom Accumulator", Hidden=true);
2526
2527CONNECTIONS
2528#vapor
2529        REBOILER.OutletVapour to TRAYS(NumberOfTrays).InletVapour;
2530       
2531#liquid
2532        TRAYS(NumberOfTrays).OutletLiquid       to ACCUMULATOR.Inlet;
2533        ACCUMULATOR.Outlet                              to SPLITTER.Inlet;
2534        SPLITTER.Outlet2                                to REBOILER.InletLiquid;
2535
2536#Connectors
2537LiquidConnector                         to TRAYS(1).InletLiquid;
2538ConnectorHeatReboiler           to REBOILER.InletQ;
2539ConnectorHeatAccumulator        to ACCUMULATOR.InletQ;
2540SPLITTER.Outlet1                        to ConnectorSplitterBottom;
2541
2542EQUATIONS
2543#Heat Connectors
2544        HeatToReboiler  = ConnectorHeatReboiler;
2545        HeatToAccumulator       = ConnectorHeatAccumulator;
2546       
2547        ConnectorSplitterBottom.T = BottomProduct.T;
2548        ConnectorSplitterBottom.P = BottomProduct.P;
2549        ConnectorSplitterBottom.F = BottomProduct.F;
2550        ConnectorSplitterBottom.z = BottomProduct.z;
2551       
2552        LiquidConnector.F= LiquidInlet.F;
2553        LiquidConnector.T = LiquidInlet.T;
2554        LiquidConnector.P = LiquidInlet.P;
2555        LiquidConnector.z = LiquidInlet.z;
2556        LiquidConnector.v = LiquidInlet.v;
2557        LiquidConnector.h = LiquidInlet.h;
2558       
2559        VapourOutlet.F= TRAYS(1).OutletVapour.F;
2560        VapourOutlet.T = TRAYS(1).OutletVapour.T;
2561        VapourOutlet.P = TRAYS(1).OutletVapour.P;
2562        VapourOutlet.z = TRAYS(1).OutletVapour.z;
2563       
2564        VapourDrawOff.F*VapSideTrayIndex= TRAYS.VapourSideStream.F;
2565        VapourDrawOff.T = TRAYS(VapourSideStreamLocation).VapourSideStream.T;
2566        VapourDrawOff.P = TRAYS(VapourSideStreamLocation).VapourSideStream.P;
2567        VapourDrawOff.z = TRAYS(VapourSideStreamLocation).VapourSideStream.z;
2568
2569        LiquidDrawOff.F*LiqSideTrayIndex= TRAYS.LiquidSideStream.F;
2570        LiquidDrawOff.T = TRAYS(LiquidSideStreamLocation).LiquidSideStream.T;
2571        LiquidDrawOff.P = TRAYS(LiquidSideStreamLocation).LiquidSideStream.P;
2572        LiquidDrawOff.z = TRAYS(LiquidSideStreamLocation).LiquidSideStream.z;
2573
2574        VapourDrawOffFlow = VapourDrawOff.F;
2575        LiquidDrawOffFlow = LiquidDrawOff.F;
2576
2577end
2578
2579Model ReactiveDistillation
2580       
2581ATTRIBUTES
2582        Pallete         = true;
2583        Icon            = "icon/DistillationReac";
2584        Brief           = "Model of a reactive distillation column with dynamic condenser and reboiler.";
2585        Info            =
2586"== Specify ==
2587* the reaction related variables for each tray, condenser and reboiler;
2588* the feed stream of each tray (Inlet);
2589* the Murphree eficiency for each tray Emv;
2590* the pump pressure difference;
2591* the heat supllied in reboiler and condenser;
2592* the condenser vapor outlet flow (OutletVapour.F);
2593* the reboiler liquid outlet flow (OutletLiquid.F);
2594* both splitter outlet flows OR one of the splitter outlet flows and the splitter frac.
2595       
2596== Initial Conditions ==
2597* the TRAYS temperature (OutletLiquid.T);
2598* the TRAYS liquid level (Level) OR the TRAYS liquid flow (OutletLiquid.F);
2599* (NoComps - 1) OutletLiquid (OR OutletVapour) compositions for each tray;
2600       
2601* the condenser temperature (OutletLiquid.T);
2602* the condenser liquid level (Level);
2603* (NoComps - 1) OutletLiquid (OR OutletVapour) compositions;
2604       
2605* the reboiler temperature (OutletLiquid.T);
2606* the reboiler liquid level (Level);
2607* (NoComps - 1) OutletLiquid (OR OutletVapour) compositions.
2608";
2609       
2610PARAMETERS
2611        outer PP        as Plugin       (Type="PP");
2612        outer NComp as Integer  (Brief="Number of Components");
2613#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2614# Section Column Feed Tray - Side Streams  Location and Numbering
2615#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2616        NumberOfTrays                                           as Integer      (Brief="Number of TRAYS", Default=2);
2617        FeedTrayIndex(NumberOfTrays)            as Integer      (Brief="Feed Tray Index", Default=0,Hidden=true);
2618        LiqSideTrayIndex(NumberOfTrays)         as Integer      (Brief="Liquid Side Tray Index", Default=0,Hidden=true);
2619        VapSideTrayIndex(NumberOfTrays)         as Integer      (Brief="Vapour Side Tray Index", Default=0,Hidden=true);
2620        FeedTrayLocation                                        as Integer      (Brief="Feed tray Location", Default=2);
2621        LiquidSideStreamLocation                        as Integer      (Brief="Liquid Side Stream Location", Default=2);
2622        VapourSideStreamLocation                        as Integer      (Brief="Vapour Side Stream Location", Default=2);
2623#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2624# Section Column Flow Model for Liquid and Vapour
2625#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2626        VapourFlow              as Switcher     (Valid = ["on", "off"], Default = "off",Hidden=true);
2627        TrayVapourFlow  as Switcher     (Valid = ["on", "off"], Default = "off",Hidden=true);
2628        TrayLiquidFlow  as Switcher     (Valid = ["on", "off"], Default = "off",Hidden=true);
2629        alfacond                as Real;
2630#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2631# Section Column Tray Geometry and Auxiliar Parameters
2632#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2633        V               as volume               (Brief="Total Volume of the tray",Hidden=true);
2634        Q               as power                (Brief="Rate of heat supply",Hidden=true);
2635        Ap              as area                 (Brief="Plate area = Atray - Adowncomer",Hidden=true);
2636        Ah              as area                 (Brief="Total holes area",Hidden=true);
2637        lw              as length               (Brief="Weir length",Hidden=true);
2638        g               as acceleration (Brief="Gravity Acceleration",Default=9.81,Hidden=true);
2639        hw              as length               (Brief="Weir height",Hidden=true);
2640        beta    as fraction     (Brief="Aeration fraction");
2641        alfa    as fraction     (Brief="Dry pressure drop coefficient");
2642
2643        VolumeOfTray            as volume               (Brief="Total Volume of the tray");
2644        HeatSupply                      as heat_rate    (Brief="Rate of heat supply");
2645        PlateArea                       as area                 (Brief="Plate area = Atray - Adowncomer");
2646        HolesArea                       as area                 (Brief="Total holes area");
2647        WeirLength                      as length               (Brief="Weir length");
2648        WeirHeight                      as length               (Brief="Weir height");
2649
2650        stoic(NComp)    as Real(Brief="Stoichiometric matrix");
2651        Hr                                              as energy_mol;
2652       
2653SET
2654
2655        FeedTrayIndex(FeedTrayLocation)         =1;
2656        VapSideTrayIndex(FeedTrayLocation)      =1;
2657        LiqSideTrayIndex(FeedTrayLocation)      =1;
2658
2659        V=VolumeOfTray;
2660        Q=HeatSupply;
2661        Ap=PlateArea;
2662        Ah=HolesArea;
2663        lw=WeirLength;
2664        hw=WeirHeight ;
2665       
2666VARIABLES
2667#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2668# Tray Initialization For the Whole Column Section
2669#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2670        INITIALIZATION          as InitializeSection    (Brief = "Column Model Initialization");
2671#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2672# Column Feed - Side Stream Flow and Murphree Efficiency
2673#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++     
2674        in      FeedTray                        as stream       (Brief="Feed stream", PosX=0, PosY=0.55);
2675                VapourDrawOffFlow       as flow_mol (Brief = "Stream Molar Flow Rate");
2676                LiquidDrawOffFlow   as flow_mol (Brief = "Stream Molar Flow Rate");
2677                MurphreeEff             as Real         (Brief = "Murphree efficiency");
2678#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2679# Column Vapour and Liquid Draw Sides
2680#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2681        out     VapourDrawOff   as vapour_stream        (Brief="Vapour Outlet in the section", PosX=1, PosY=0.395,Protected = true);
2682        out     LiquidDrawOff   as liquid_stream        (Brief="Liquid Outlet in the section", PosX=1, PosY=0.44,Protected = true);
2683#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2684# Heat Ports
2685#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2686        in      HeatToReboiler  as power (Brief="Heat supplied to Reboiler", PosX=1, PosY=0.89);
2687        in      HeatToCondenser as power (Brief="Heat supplied to Condenser", PosX=1, PosY=0.07);
2688#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2689# Column Devices
2690#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2691        TRAYS(NumberOfTrays)    as trayReac;
2692        CONDENSER                               as condenserReact;
2693        REBOILER                                as reboilerReact;
2694        SPLITTER                                as splitter2;
2695        PUMP                                    as pump;
2696#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2697# Column Outlets
2698#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2699        out     VapourDistillate        as vapour_stream        (Brief="Vapour outlet stream From Condenser", PosX=0.59, PosY=0);
2700        out     LiquidDistillate        as liquid_stream        (Brief="Liquid outlet stream From Splitter", PosX=1, PosY=0.23);
2701        out     BottomProduct           as liquid_stream        (Brief="Liquid outlet stream From Reboiler", PosX=0.67, PosY=1);
2702#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2703# Column Connectors
2704#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2705in      ConnectorCondenserVout  as stream       (Brief="Connector for Vapour outlet stream From Top Condenser", Hidden=true);
2706in      ConnectorSplitterOut    as stream       (Brief="Connector for Liquid outlet stream From Top Splitter", Hidden=true);
2707in      ConnectorReboilerLout   as stream       (Brief="Connector for Liquid outlet stream From Reboiler", Hidden=true);
2708#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2709# Column Control Ports
2710#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2711        out     TRI as control_signal   (Brief="Temperature of Reboiler Indicator", PosX=1, PosY=0.83);
2712        out     LRI as control_signal   (Brief="Level of Reboiler Indicator", PosX=1, PosY=0.855);
2713        out     TCI as control_signal   (Brief="Temperature of Condenser Indicator", PosX=1, PosY=0.01);
2714        out     LCI as control_signal   (Brief="Level of Condenser Indicator", PosX=1, PosY=0.04);
2715
2716CONNECTIONS
2717#vapor
2718        REBOILER.OutletVapour                                   to TRAYS(NumberOfTrays).InletVapour;
2719        TRAYS(1).OutletVapour                                   to CONDENSER.InletVapour;
2720        TRAYS([2:NumberOfTrays]).OutletVapour   to TRAYS([1:NumberOfTrays-1]).InletVapour;
2721
2722#liquid
2723        CONDENSER.OutletLiquid                                  to SPLITTER.Inlet;     
2724        SPLITTER.Outlet2                                        to PUMP.Inlet;
2725        PUMP.Outlet                                             to TRAYS(1).InletLiquid;
2726        TRAYS([1:NumberOfTrays-1]).OutletLiquid         to TRAYS([2:NumberOfTrays]).InletLiquid;
2727        TRAYS(NumberOfTrays).OutletLiquid               to REBOILER.InletLiquid;
2728
2729#Connectors
2730        CONDENSER.OutletVapour  to ConnectorCondenserVout;
2731        SPLITTER.Outlet1        to ConnectorSplitterOut;
2732        REBOILER.OutletLiquid   to ConnectorReboilerLout;
2733
2734INITIAL
2735#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2736# Tray Initialization
2737#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2738for i in 1:NumberOfTrays do
2739
2740"The initial temperature of the TRAYS"
2741        TRAYS(i).OutletLiquid.T = INITIALIZATION.TopTemperature+(INITIALIZATION.BottomTemperature-INITIALIZATION.TopTemperature)*((i-1)/(NumberOfTrays-1));
2742
2743"The initial Level of the TRAYS"
2744        TRAYS(i).Level = INITIALIZATION.LevelFraction*hw;
2745end
2746
2747for i in 1:NComp-1 do
2748
2749for j in 1:NumberOfTrays do
2750
2751"The initial composition of the TRAYS - Normalized"
2752        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));
2753end
2754
2755end
2756
2757EQUATIONS
2758
2759for i in [1:NumberOfTrays] do
2760
2761"Murphree Efficiency"
2762        TRAYS(i).OutletVapour.z =  MurphreeEff * (TRAYS(i).yideal - TRAYS(i).InletVapour.z) + TRAYS(i).InletVapour.z;
2763       
2764"Energy Holdup"
2765        TRAYS(i).E = TRAYS(i).ML*TRAYS(i).OutletLiquid.h + TRAYS(i).MV*TRAYS(i).OutletVapour.h - TRAYS(i).OutletLiquid.P*V;
2766
2767"Component Molar Balance"
2768        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-
2769        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;
2770       
2771"Energy Balance"
2772        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
2773        -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;
2774
2775"Level of clear liquid over the weir"
2776        TRAYS(i).Level = TRAYS(i).ML*TRAYS(i).vL/Ap;
2777
2778"Geometry Constraint"
2779        V = TRAYS(i).ML* TRAYS(i).vL + TRAYS(i).MV*TRAYS(i).vV;
2780
2781end
2782
2783switch VapourFlow
2784                case "on":
2785                "Pressure Drop through the condenser"
2786                CONDENSER.InletVapour.F*TRAYS(1).vV / 'm^2' =
2787                        sqrt((TRAYS(1).OutletVapour.P - CONDENSER.OutletLiquid.P + 1e-8 * 'atm')/(TRAYS(1).rhoV*alfacond));
2788                when TRAYS(1).OutletVapour.P < CONDENSER.OutletLiquid.P switchto "off";
2789               
2790                case "off":
2791                "Prato selado"
2792                CONDENSER.InletVapour.F = 0.0 * 'mol/s';
2793                when TRAYS(1).OutletVapour.P > CONDENSER.OutletLiquid.P + 1e-3 * 'atm' switchto "on";
2794        end
2795
2796for i in [1:NumberOfTrays] do
2797
2798        switch TrayLiquidFlow
2799                case "on":
2800                "Francis Equation"
2801                TRAYS(i).OutletLiquid.F*TRAYS(i).vL = 1.84*'1/s'*lw*((TRAYS(i).Level-(beta*hw)+1e-6*'m')/(beta))^2;
2802                when TRAYS(i).Level < (beta * hw) switchto "off";
2803               
2804                case "off":
2805                "Low level"
2806                TRAYS(i).OutletLiquid.F = 0 * 'mol/h';
2807                when TRAYS(i).Level > (beta * hw) + 1e-6*'m' switchto "on";
2808        end
2809
2810        switch TrayVapourFlow
2811                case "on":
2812                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;
2813                when TRAYS(i).InletVapour.P < TRAYS(i).OutletVapour.P + TRAYS(i).Level*g*TRAYS(i).rhoL switchto "off";
2814               
2815                case "off":
2816                TRAYS(i).InletVapour.F = 0 * 'mol/s';
2817                when TRAYS(i).InletVapour.P > TRAYS(i).OutletVapour.P + TRAYS(i).Level*g*TRAYS(i).rhoL + 3e-2 * 'atm' switchto "on";
2818        end
2819
2820end
2821
2822# Connecting Trays
2823        FeedTray.F*FeedTrayIndex= TRAYS.Inlet.F;
2824        FeedTray.T = TRAYS.Inlet.T;
2825        FeedTray.P = TRAYS.Inlet.P;
2826        FeedTray.z = TRAYS.Inlet.z;
2827        FeedTray.v = TRAYS.Inlet.v;
2828        FeedTray.h = TRAYS.Inlet.h;
2829
2830        HeatToReboiler  = REBOILER.InletQ;
2831        HeatToCondenser = CONDENSER.InletQ;
2832
2833"Reboiler Temperature indicator"
2834        TRI * 'K' = REBOILER.OutletLiquid.T;
2835
2836"Reboiler Level indicator"
2837        LRI*REBOILER.V = REBOILER.Level*REBOILER.Across;
2838
2839"Condenser Temperature indicator"
2840        TCI * 'K' = CONDENSER.OutletLiquid.T;
2841
2842"Condenser Level indicator"
2843        LCI*CONDENSER.V = CONDENSER.Level*CONDENSER.Across;
2844
2845# Condenser Connector Equations
2846        ConnectorCondenserVout.T = VapourDistillate.T;
2847        ConnectorCondenserVout.P = VapourDistillate.P;
2848        ConnectorCondenserVout.F = VapourDistillate.F;
2849        ConnectorCondenserVout.z = VapourDistillate.z;
2850
2851# Splitter Connector Equations
2852        ConnectorSplitterOut.T = LiquidDistillate.T;
2853        ConnectorSplitterOut.P = LiquidDistillate.P;
2854        ConnectorSplitterOut.F = LiquidDistillate.F;
2855        ConnectorSplitterOut.z = LiquidDistillate.z;
2856
2857# Reboiler Connector Equations
2858        ConnectorReboilerLout.T = BottomProduct.T;
2859        ConnectorReboilerLout.P = BottomProduct.P;
2860        ConnectorReboilerLout.F = BottomProduct.F;
2861        ConnectorReboilerLout.z = BottomProduct.z;
2862
2863        VapourDrawOff.F*VapSideTrayIndex= TRAYS.VapourSideStream.F;
2864        VapourDrawOff.T = TRAYS(VapourSideStreamLocation).VapourSideStream.T;
2865        VapourDrawOff.P = TRAYS(VapourSideStreamLocation).VapourSideStream.P;
2866        VapourDrawOff.z = TRAYS(VapourSideStreamLocation).VapourSideStream.z;
2867
2868        LiquidDrawOff.F*LiqSideTrayIndex= TRAYS.LiquidSideStream.F;
2869        LiquidDrawOff.T = TRAYS(LiquidSideStreamLocation).LiquidSideStream.T;
2870        LiquidDrawOff.P = TRAYS(LiquidSideStreamLocation).LiquidSideStream.P;
2871        LiquidDrawOff.z = TRAYS(LiquidSideStreamLocation).LiquidSideStream.z;
2872
2873        VapourDrawOffFlow = VapourDrawOff.F;
2874        LiquidDrawOffFlow = LiquidDrawOff.F;
2875
2876end
2877
2878*#
Note: See TracBrowser for help on using the repository browser.