distillation_shortcut_unit/
lib.rs

1//! # Distillation shortcut unit operation
2//!
3//! This is an example unit operation implementation
4//! featuring a shortcut distillation unit operation
5//! using the Fenske-Underwood-Gilliland-Kirkbride
6//! approach.
7//!
8//! ## Fenske
9//!
10//! The Fenske equation (Fenske, "Fractionation of Straight-Run Pennsylvania Gasoline",
11//! Industrial and Engineering Chemistry, Vol. 24: 482, 1932) is used
12//! to estimate distillate and bottoms composition and the minimum number
13//! of stages.
14//! 
15//! From the slate of components, two components are
16//! selected that are called the Light Key (LK)
17//! component, and Heavy Key (HK) component. The
18//! desired recovery is specified for the LK:
19//!
20//! <math>
21//!     <msub><ms>r</ms><mtext>LK</mtext></msub>
22//!     <mo>=</mo>
23//!     <mfrac>
24//!     <msub><ms>f</ms><mrow><mtext>LK</mtext><mo>,</mo><mtext>dist</mtext></mrow></msub>
25//!     <msub><ms>f</ms><mrow><mtext>LK</mtext><mo>,</mo><mtext>feed</mtext></mrow></msub>
26//!     </mfrac>
27//! </math>
28//!
29//! and for the heavy component recovery
30//!
31//! <math>
32//!     <msub><ms>r</ms><mtext>HK</mtext></msub>
33//!     <mo>=</mo>
34//!     <mfrac>
35//!     <msub><ms>f</ms><mrow><mtext>HK</mtext><mo>,</mo><mtext>bot</mtext></mrow></msub>
36//!     <msub><ms>f</ms><mrow><mtext>HK</mtext><mo>,</mo><mtext>feed</mtext></mrow></msub>
37//!     </mfrac>
38//! </math>
39//!
40//! Initial distillate and bottom compositions are estimated.
41//! 
42//! The separation is based on calculation of the 
43//! relative volatility for each component:
44//!
45//!  <math>
46//!     <msub><ms>&alpha;</ms><mtext>i</mtext></msub>
47//!     <mo>=</mo>
48//!     <mfrac>
49//!         <msub><ms>K</ms><mtext>i</mtext></msub>
50//!         <msub><ms>K</ms><mtext>HK</mtext></msub>
51//!     </mfrac>
52//! </math>
53//!
54//! where the K value for each compound is calculated for the dew point (DP) at
55//! distillate conditions, and bubble point (BP) at bottoms conditions, and the 
56//! average K value is given by 
57//!
58//! <math>
59//!     <msub><ms>K</ms><mtext>i</mtext></msub>
60//!     <mo>=</mo>
61//!     <msqrt>
62//!         <msub><ms>K</ms><mrow><mtext>i</mtext><mo>,</mo><mtext>DP</mtext><mo>,</mo><mtext>dist</mtext></mrow></msub>
63//!         <msub><ms>K</ms><mrow><mtext>i</mtext><mo>,</mo><mtext>BP</mtext><mo>,</mo><mtext>bot</mtext></mrow></msub>
64//!     </msqrt>
65//! </math>
66//!
67//! The minimum number of stages follows from:
68//! 
69//!  <math>
70//!     <msub><ms>N</ms><mtext>min</mtext></msub>
71//!     <mo>=</mo>
72//!     <mfrac>
73//!     <mrow><mtext>ln</mtext><mo>(</mo>
74//!       <mfrac>
75//!        <mrow>
76//!        <msub><ms>f</ms><mrow><mtext>LK</mtext><mo>,</mo><mtext>dist</mtext></mrow></msub>
77//!        <msub><ms>f</ms><mrow><mtext>HK</mtext><mo>,</mo><mtext>bot</mtext></mrow></msub>
78//!        </mrow>
79//!        <mrow>
80//!        <msub><ms>f</ms><mrow><mtext>HK</mtext><mo>,</mo><mtext>dist</mtext></mrow></msub>
81//!        <msub><ms>f</ms><mrow><mtext>LK</mtext><mo>,</mo><mtext>bot</mtext></mrow></msub>
82//!        </mrow>
83//!       </mfrac>
84//!       <mo>)</mo></mrow>
85//!     <mrow><mtext>ln</mtext><mo>(</mo><msub><ms>&alpha;</ms><mtext>LK</mtext></msub><mo>)</mo></mrow>
86//!     </mfrac>
87//! </math>
88//!
89//! The bottom component flow rates are:
90//!
91//!  <math>
92//!     <msub><ms>f</ms><mrow><mtext>i</mtext><mo>,</mo><mtext>bot</mtext></mrow></msub>
93//!     <mo>=</mo>
94//!       <mfrac>
95//!        <msub><ms>f</ms><mrow><mtext>i</mtext><mo>,</mo><mtext>feed</mtext></mrow></msub>
96//!        <mrow><mn>1</mn><mo>+</mo>
97//!        <mo>(</mo><mfrac>
98//!            <msub><ms>f</ms><mrow><mtext>HK</mtext><mo>,</mo><mtext>dist</mtext></mrow></msub>
99//!            <msub><ms>f</ms><mrow><mtext>HK</mtext><mo>,</mo><mtext>bot</mtext></mrow></msub>
100//!        </mfrac><mo>)</mo>
101//!        <mmultiscripts><ms>&alpha;</ms><mtext>i</mtext><msub><ms>N</ms><mtext>min</mtext></msub></mmultiscripts>
102//!        </mrow>
103//!       </mfrac>
104//! </math>
105//!
106//! and the distillate component flow rates are:
107//!
108//! <math>
109//!   <msub><ms>f</ms><mrow><mtext>i</mtext><mo>,</mo><mtext>dist</mtext></mrow></msub>
110//!   <mo>=</mo><msub><ms>f</ms><mrow><mtext>i</mtext><mo>,</mo><mtext>feed</mtext></mrow></msub>
111//!   <mo>-</mo><msub><ms>f</ms><mrow><mtext>i</mtext><mo>,</mo><mtext>bot</mtext></mrow></msub>
112//! </math>
113//!
114//! The unit operation operates isobarically, so product pressure equals feed pressure. The distillate 
115//! product is at the dew point temperature for the distillate composition, and the bottoms
116//! product it at the bubble point temperature for the distillate composition. 
117//!
118//! Given the new distillate temperature and composition, and the new bottoms temperature
119//! and composition, the K values and relative volatilities are updated, and the above 
120//! calculation is repeated until converged values are obtained.
121//!
122//! ## Underwood
123//!
124//! The Underwood equation (Underwood, "Fractional distillation of
125//! multi-component mixtures. Calculation of minimum reflux ratio", J. Inst. 
126//! Petrol., 32, 614, 1946) is used to estimate the minimum reflux ratio.
127//! 
128//! The minimum reflux ratio is determined from
129//! 
130//! <math>
131//!     <msub><ms>R</ms><mtext>min</mtext></msub>
132//!     <mo>=</mo>
133//!     <mo>&sum;</mo>
134//!       <mfrac>
135//!        <mrow>
136//!            <msub><ms>&alpha;</ms><mtext>i</mtext></msub>
137//!            <msub><ms>x</ms><mrow><mtext>i</mtext><mo>,</mo><mtext>dist</mtext></mrow></msub>
138//!        </mrow>
139//!        <mrow>
140//!            <msub><ms>&alpha;</ms><mtext>i</mtext></msub>
141//!            <mo>-</mo>
142//!            <ms>&theta;</ms>
143//!        </mrow>
144//!       </mfrac>
145//!       <mo>-</mo>
146//!       <mn>1</mn>
147//! </math>
148//!
149//! where Underwood parameter <math>&theta;</math> is the root of equation
150//! 
151//! <math>
152//!     <mn>1</mn>
153//!		<mo>-</mo>
154//!     <ms>q</ms>
155//!     <mo>=</mo>
156//!     <mo>&sum;</mo>
157//!     <mfrac>
158//!      <mrow>
159//!          <msub><ms>&alpha;</ms><mtext>i</mtext></msub>
160//!          <msub><ms>x</ms><mrow><mtext>i</mtext><mo>,</mo><mtext>feed</mtext></mrow></msub>
161//!      </mrow>
162//!      <mrow>
163//!          <msub><ms>&alpha;</ms><mtext>i</mtext></msub>
164//!          <mo>-</mo>
165//!          <ms>&theta;</ms>
166//!      </mrow>
167//!     </mfrac>
168//! </math>
169//!
170//! where q is the feed quality, defined as 
171//! 
172//! <math>
173//!     <ms>q</ms>
174//!     <mo>=</mo>
175//!     <mfrac>
176//!      <mrow>
177//!          <msub><ms>h</ms><mtext>feed,DP</mtext></msub>
178//!			<mo>-</mo>
179//!          <msub><ms>h</ms><mtext>feed</mtext></msub>
180//!      </mrow>
181//!      <mrow>
182//!          <msub><ms>h</ms><mtext>feed,DP</mtext></msub>
183//!			<mo>-</mo>
184//!          <msub><ms>h</ms><mtext>feed,BP</mtext></msub>
185//!      </mrow>
186//!     </mfrac>
187//! </math>
188//!
189//! where <math><msub><ms>h</ms><mtext>feed,DP</mtext></msub></math>
190//! is the enthalpy of the vapor phase at the dew point temperature
191//! of the feed, and <math><msub><ms>h</ms><mtext>feed,BP</mtext></msub></math>
192//! is the enthalpy of the liquid phase at the bubble point temperature
193//! of the feed.
194//!
195//! There are multiple roots for <math><ms>&theta;</ms></math>, and the
196//! root that is used is between 1 and <math><msub><ms>&alpha;</ms><mtext>LK</mtext></msub></math>.
197//! In case there are &alpha; values that are in between 1 and
198//! <math><msub><ms>&alpha;</ms><mtext>LK</mtext></msub></math>, a
199//! warning is issued and the root that is closest to 1 is used.
200//!
201//! The unit does not check whether for retrograde flash results, 
202//! which is outside the scope of this example.
203//!
204//! ## Gilliland
205//!
206//! The Gilliland equation (Gilliland, "Estimate the 
207//! number of theoretical plates as a function of reflux ratio", 
208//! Ind. Eng. Chem. 32(9): 1220-1223, 1940, doi 10.1021/ie50369a035)
209//! is used to estimate the number of stages:
210//! 
211//! <math>
212//!     <ms>Y</ms>
213//!     <mo>=</mo>
214//!     <mn>1</mn>
215//!     <mo>-</mo>
216//!     <mtext>exp</mtext>
217//!        <mo>(</mo>
218//!        <mo>(</mo>
219//!        <mfrac>
220//!            <mrow><mn>1</mn><mo>+</mo><mn>54.4</mn><ms>X</ms></mrow>
221//!            <mrow><mn>11</mn><mo>+</mo><mn>117.2</mn><ms>X</ms></mrow>
222//!        </mfrac>
223//!        <mo>)</mo>
224//!        <mo>(</mo>
225//!        <mfrac>
226//!            <mrow><ms>X</ms><mo>-</mo><mn>1</mn></mrow>
227//!            <msqrt><ms>X</ms></msqrt>
228//!        </mfrac>
229//!        <mo>)</mo>
230//!        <mo>)</mo>
231//! </math>
232//!
233//! where
234//!
235//! <math>
236//!     <ms>Y</ms>
237//!     <mo>=</mo>
238//!     <mfrac>
239//!        <mrow><ms>N</ms><mo>-</mo><msub><ms>N</ms><mtext>min</mtext></msub></mrow>
240//!        <mrow><ms>N</ms><mo>+</mo><mn>1</mn></mrow>
241//!     </mfrac>
242//! </math>
243//! 
244//! and
245//! 
246//! <math>
247//!     <ms>X</ms>
248//!     <mo>=</mo>
249//!     <mfrac>
250//!        <mrow><ms>R</ms><mo>-</mo><msub><ms>R</ms><mtext>min</mtext></msub></mrow>
251//!        <mrow><ms>R</ms><mo>+</mo><mn>1</mn></mrow>
252//!     </mfrac>
253//! </math>
254//! 
255//! The reflux ratio <math>R</math> is determined from the minimum reflux ratio 
256//! using an adjustable parameter:
257//!
258//! 
259//! <math>
260//!     <ms>R</ms>
261//!     <mo>=</mo>
262//!     <ms>k</ms>
263//!     <msub><ms>R</ms><mtext>min</mtext></msub>
264//! </math>
265//!
266//! where <math>k</math> must exceed 1. The default value for <math>k</math> is 1.15.
267//!
268//! ## Kirkbride
269//!
270//! The location of the feed stage is estimated from the Kirkbride correlation
271//! (Kirkbride,  "Process Design Procedure for Multicomponent Fractionators",
272//! Petr. Ref. 23(9), 321, 1944):
273//! 
274//! <math>
275//!    <mfrac>
276//!        <msub><ms>N</ms><mtext>top</mtext></msub>
277//!        <msub><ms>N</ms><mtext>bot</mtext></msub>
278//!    </mfrac>
279//!     <mo>=</mo>
280//!     <msup>
281//!        <mrow>
282//!            <mo>[</mo>
283//!            <mfrac>
284//!                <msub><ms>f</ms><mtext>bot</mtext></msub>
285//!                <msub><ms>f</ms><mtext>dist</mtext></msub>
286//!            </mfrac>
287//!            <mfrac>
288//!                <msub><ms>x</ms><mrow><mtext>HK</mtext><mo>,</mo><mtext>feed</mtext></mrow></msub>
289//!                <msub><ms>x</ms><mrow><mtext>LK</mtext><mo>,</mo><mtext>feed</mtext></mrow></msub>
290//!            </mfrac>
291//!            <msup>
292//!                <mrow>
293//!                <mo>(</mo>
294//!                <mfrac>
295//!                    <msub><ms>x</ms><mrow><mtext>LK</mtext><mo>,</mo><mtext>bot</mtext></mrow></msub>
296//!                    <msub><ms>x</ms><mrow><mtext>HK</mtext><mo>,</mo><mtext>dist</mtext></mrow></msub>
297//!                </mfrac>
298//!                <mo>)</mo>
299//!                </mrow>
300//!            <mn>2</mn>
301//!            </msup>
302//!            <mo>]</mo>
303//!        </mrow>
304//!        <mn>0.206</mn>
305//!     </msup>
306//! </math>
307//! 
308//! where
309//! <math><ms>f</ms></math>
310//! are molar flow rates, 
311//! <math><ms>x</ms></math>
312//! are mole fractions, and the number of trays above the feed 
313//! <math><msub><ms>N</ms><mtext>top</mtext></msub></math>
314//! and the number of trays below the feed 
315//! <math><msub><ms>N</ms><mtext>bot</mtext></msub></math>
316//! sum up to the number of trays <math><ms>N</ms></math>.
317//!
318//! # Parameters
319//!
320//! The unit operation has the following input parameters:
321//! 
322//! * HK: selection of the heavy key component,
323//! * LK: selection of the light key component,
324//! * <math><msub><ms>r</ms><mtext>LK</mtext></msub></math>, light component recovery, mol/mol,
325//! * <math><msub><ms>r</ms><mtext>HK</mtext></msub></math>, heavy component recovery, mol/mol,
326//! * <math><ms>k</ms></math>, factor of reflux ratio <math><ms>R</ms></math> above minimum reflux ratio <math><msub><ms>R</ms><mtext>min</mtext></msub></math>.
327//! * the maximum number of iterations
328//! * the convergence tolerance for the component flow rates relative to the total feed rate; also used for convergence of the Underwood equation
329//!
330//! The unit has the following output parameters:
331//! 
332//! * <math><ms>N</ms></math>, number of stages
333//! * <math><ms>R</ms></math>, reflux ratio, mol/mol
334//! * <math><msub><ms>N</ms><mtext>feed</mtext></msub></math>, feed stage location.
335//!
336//! # Installation and usage
337//!
338//! `cobiaRegister.exe distillation_shortcut_unit.dll`
339//!
340//! An installer for Windows is made available through the AmsterCHEM web site.
341//!
342//! After installation, the unit operation can be used in any CAPE-OPEN compliant flowsheeting environment.
343
344//To build documentation: 
345//  cargo doc --no-deps --document-private-items --package distillation_shortcut_unit --open
346
347use cobia;
348mod shared_unit_data;
349mod distillation_shortcut_unit;
350mod port_collection;
351mod material_port;
352mod parameter_collection;
353mod real_parameter;
354mod string_parameter;
355mod integer_parameter;
356mod gui;
357
358/// This function is called by functions generated by the `pmc_entry_points`
359/// macro to check if the unit operation is registered for all users.
360///
361/// Registering a PMC for all users requires administrative privileges.
362///
363/// # Returns
364/// * `false`
365fn register_pmcs_for_all_users() -> bool {
366	false
367}
368
369///A list of all the PMCs that need to be registered
370static PMCS: &[cobia::PMCInfo] = &[cobia::pmc_info::<distillation_shortcut_unit::DistillationShortcutUnit>()];
371
372cobia::pmc_entry_points!(PMCS, register_pmcs_for_all_users());