This repository has been archived by the owner on Nov 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathSMB.m
1792 lines (1386 loc) · 85.4 KB
/
SMB.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
classdef SMB < handle
% ========================================================================================
% This is the class of the functions for simulated moving bed.
% ========================================================================================
methods (Static = true, Access = 'public')
function [outletProfile, lastState] = secColumn(inletProfile, params, lastState, ParSwarm)
% ----------------------------------------------------------------------------------------
% Simulation of the single column
%
% Parameters:
% - inletProfile. Inlet time and corresponding concentration profile
% - params. Get parameters for simulation
% - lastState. The last STATE from previous simulation of next simulation
% - ParSwarm. In the optimization situations, this is the vector which contains
% the optimized decision variables
%
% Returns:
% - outletProfile. outlet time and corresponding concentration profile
% - lastState. Record the last STATE which is used as the boundary condition
% ----------------------------------------------------------------------------------------
if nargin < 4
ParSwarm = [];
if nargin < 3
lastState = cell(1,2);
if nargin < 2
error('SMB.secColumn: There are no enough inputs for carrying out Simulator in CADET \n');
end
end
end
if isempty(params.initialBulk) && isempty(params.initialSolid) && isempty(lastState{1})
error('SMB.secColumn: There are no Initial / Boundary Conditions for the Simulator \n');
end
% Read operating parameters of the SMB unit
[opt, ~, ~] = getParameters(ParSwarm);
% Prepare the inlet profile to the CADET model
inlet = PiecewiseCubicPolyProfile.fromUniformData(...
inletProfile.time, inletProfile.concentration);
% Nonnegative limitation
inlet.constant(inlet.constant < 0) = 0;
inlet.linear(inlet.linear < 0) = 0;
inlet.quadratic(inlet.quadratic < 0) = 0;
inlet.cubic(inlet.cubic < 0) = 0;
% General rate model
mGrm = SingleGRM();
% Discretization
mGrm.nComponents = opt.nComponents;
% if SMA isotherm, salt component is regarded as a component
if strcmp('StericMassActionBinding', opt.BindingModel)
mGrm.nComponents = opt.nComponents + 1;
opt.nComponents = opt.nComponents + 1;
end
mGrm.nCellsColumn = opt.nCellsColumn;
mGrm.nCellsParticle = opt.nCellsParticle;
mGrm.nBoundStates = ones(mGrm.nComponents, 1);
% Initial conditions
mGrm.initialBulk = params.initialBulk;
mGrm.initialSolid = params.initialSolid;
if nargin >= 3 && ~isempty(lastState{1})
mGrm.initStateY = lastState{1};
mGrm.initStateYdot = lastState{2};
end
% Transport
mGrm.dispersionColumn = params.dispersionColumn;
mGrm.interstitialVelocity = params.interstitialVelocity;
mGrm.filmDiffusion = opt.filmDiffusion;
mGrm.diffusionParticle = opt.diffusionParticle;
mGrm.diffusionParticleSurface = opt.diffusionParticleSurface;
% Geometry
mGrm.columnLength = opt.columnLength;
mGrm.particleRadius = opt.particleRadius;
mGrm.porosityColumn = opt.porosityColumn;
mGrm.porosityParticle = opt.porosityParticle;
% Adsorption
if strcmp(opt.BindingModel, 'LinearBinding')
mLinear = LinearBinding();
mLinear.kineticBinding = false;
% Adsorption parameters
mLinear.kA = opt.KA;
mLinear.kD = opt.KD;
mGrm.bindingModel = mLinear;
elseif strcmp(opt.BindingModel, 'MultiComponentLangmuirBinding')
mLangmuir = LangmuirBinding();
mLangmuir.kineticBinding = false;
mLangmuir.kA = opt.KA;
mLangmuir.kD = opt.KD;
mLangmuir.qMax = opt.QMAX;
mGrm.bindingModel = mLangmuir;
elseif strcmp(opt.BindingModel, 'MultiComponentBiLangmuirBinding')
mBiLangmuir = BiLangmuirBinding();
mBiLangmuir.kineticBinding = false;
mBiLangmuir.kA1 = opt.KA(1);
mBiLangmuir.kD1 = opt.KD(1);
mBiLangmuir.qMax1 = opt.QMAX(1);
mBiLangmuir.kA2 = opt.KA(2);
mBiLangmuir.kD2 = opt.KD(2);
mBiLangmuir.qMax2 = opt.QMAX(2);
mGrm.bindingModel = mBiLangmuir;
elseif strcmp(opt.BindingModel, 'StericMassActionBinding')
mSma = StericMassActionBinding();
mSma.kineticBinding = false;
mSma.lambda = opt.LAMBDA;
mSma.kA = opt.KA;
mSma.kD = opt.KD;
mSma.nu = opt.NU;
mSma.sigma = opt.SIGMA;
mGrm.bindingModel = mSma;
else
error('%s: it is not available yet \n', opt.BindingModel);
end
mGrm.inlet = inlet;
mGrm.returnSolutionBulk = true;
% Create and configure simulator
sim = Simulator.create();
sim.solutionTimes = inletProfile.time;
sim.sectionTimes = inlet.breaks;
sim.sectionContinuity = inlet.continuity;
sim.model = mGrm;
sim.nThreads = opt.nThreads;
sim.returnLastState = true;
sim.returnLastStateSens = false;
sim.absTol = opt.ABSTOL;
sim.initStepSize = opt.INIT_STEP_SIZE;
sim.maxSteps = opt.MAX_STEPS;
% Run the simulation
try
result = sim.run();
catch e
% Something went wrong
error('CADET:simulationFailed', 'Check your settings and try again. \n%s',e.message);
end
% Extract the outletProfile
outletProfile.outlet.time = result.solution.time;
outletProfile.outlet.concentration = result.solution.outlet{1};
outletProfile.column = SMB.extractColumnMatrix(result.solution.bulk{1}, opt);
lastState{1} = result.solution.lastState;
lastState{2} = result.solution.lastStateDot;
end % secColumn
function column = massConservation(currentData, interstVelocity, Feed, Desorbent, opt, sequence, alphabet)
% ----------------------------------------------------------------------------------------
% This is the function to calculate the concentration changes on each node.
%
% Parameters:
% - currentData. Which includes each column's outlet concentration
% (time-dependent), and the last state (which records every component's concentration
% in bulk phase and stationary phase, and used as the initial state for the next simulation).
% - interstVelocity. The interstitial velocity of each column
% - Feed. The initialied injection
% - opt. Options
% - sequence. During switching, the structure used for storing the sequence of columns
% - alphabet. It is a character. It tells this subroutine to calculate the specified column
%
% Returns:
% Preparation for next column simulation
% - column.inlet. The new inlet concentration of each column, which is
% obtained from mass conservation on each node.
% - column.lastState.
% - column.params. Set the initial Mobile and Solid concentration to the
% Simulator (if there is no lastState given), and also store the interstitial velocity.
% ----------------------------------------------------------------------------------------
global stringSet dummyProfile startingPointIndex Feed2;
if nargin < 7
error('SMB.massConservation: There are no enough arguments \n');
end
% Time points
column.inlet.time = linspace(0, opt.switch, opt.timePoints);
% Interpret current alphabet to node position of the SMB unit
index = SMB.nodeIndexing(opt, alphabet);
% Specify previous column to obtain inlet concentration
if ~strcmp(alphabet, 'a')
pre_alphabet = char(alphabet - 1);
else
pre_alphabet = char(stringSet(opt.nColumn));
end
idx_i = sequence.(alphabet); % the number of current column
idx_j = sequence.(pre_alphabet); % the number of the column before
% Get the interstitial velocity and boundary conditions
params = SMB.getParams(sequence, interstVelocity, opt, index, alphabet, pre_alphabet);
% Update the intersitial velocity, boundary conditions
column.params = params{idx_i};
column.initialState = currentData{idx_i}.lastState;
% If DPFRs were implemented, transfer the boundary conditions between switches
if opt.enable_DPFR
column.initialState_DPFR = currentData{idx_i}.lastState_DPFR;
end
% Calculate concentration of the column due to its position in the SMB unit
switch index
case 'D' % node DESORBENT
% C_i^in = Q_{i-1} * C_{i-1}^out / Q_i
if ~strcmp(startingPointIndex, index)
column.inlet.concentration = (currentData{idx_j}.outlet.concentration .* ...
params{idx_j}.interstitialVelocity + Desorbent.concentration .* interstVelocity.desorbent) ...
./ params{idx_i}.interstitialVelocity;
else
column.inlet.concentration = (dummyProfile.concentration .* ...
params{idx_j}.interstitialVelocity + Desorbent.concentration .* interstVelocity.desorbent) ...
./ params{idx_i}.interstitialVelocity;
end
case 'D1' % node DESORBENT1
% C_i^in = Q_{i-1} * C_{i-1}^out / Q_i
if ~strcmp(startingPointIndex, index)
column.inlet.concentration = (currentData{idx_j}.outlet.concentration .* ...
params{idx_j}.interstitialVelocity + Desorbent{1}.concentration .* interstVelocity.desorbent1) ...
./ params{idx_i}.interstitialVelocity;
else
column.inlet.concentration = (dummyProfile.concentration .* ...
params{idx_j}.interstitialVelocity + Desorbent{1}.concentration .* interstVelocity.desorbent1) ...
./ params{idx_i}.interstitialVelocity;
end
case 'D2' % node DESORBENT2
% C_i^in = Q_{i-1} * C_{i-1}^out / Q_i
if ~strcmp(startingPointIndex, index)
column.inlet.concentration = (currentData{idx_j}.outlet.concentration .* ...
params{idx_j}.interstitialVelocity + Desorbent{2}.concentration .* interstVelocity.desorbent2) ...
./ params{idx_i}.interstitialVelocity;
else
column.inlet.concentration = (dummyProfile.concentration .* ...
params{idx_j}.interstitialVelocity + Desorbent{2}.concentration .* interstVelocity.desorbent2) ...
./ params{idx_i}.interstitialVelocity;
end
case 'F' % node FEED in four-zone and five-zone
% C_i^in = (Q_{i-1} * C_{i-1}^out + Q_F * C_F) / Q_i
if ~strcmp(startingPointIndex, index)
column.inlet.concentration = (currentData{idx_j}.outlet.concentration .* ...
params{idx_j}.interstitialVelocity + Feed.concentration .* interstVelocity.feed) ...
./ params{idx_i}.interstitialVelocity;
else
column.inlet.concentration = (dummyProfile.concentration .* ...
params{idx_j}.interstitialVelocity + Feed.concentration .* interstVelocity.feed) ...
./ params{idx_i}.interstitialVelocity;
end
case 'F1' % node FEED1 in eight-zone
% C_i^in = (Q_{i-1} * C_{i-1}^out + Q_F * C_F) / Q_i
if ~strcmp(startingPointIndex, index)
column.inlet.concentration = (currentData{idx_j}.outlet.concentration .* ...
params{idx_j}.interstitialVelocity + Feed.concentration .* interstVelocity.feed1) ...
./ params{idx_i}.interstitialVelocity;
else
column.inlet.concentration = (dummyProfile.concentration .* ...
params{idx_j}.interstitialVelocity + Feed.concentration .* interstVelocity.feed1) ...
./ params{idx_i}.interstitialVelocity;
end
case 'F2' % node FEED2 in eight-zone
% C_i^in = (Q_{i-1} * C_{i-1}^out + Q_F * C_F) / Q_i
if ~strcmp(startingPointIndex, index)
column.inlet.concentration = (currentData{idx_j}.outlet.concentration .* ...
params{idx_j}.interstitialVelocity + Feed2.concentration .* interstVelocity.feed2) ...
./ params{idx_i}.interstitialVelocity;
else
column.inlet.concentration = (dummyProfile.concentration .* ...
params{idx_j}.interstitialVelocity + Feed2.concentration .* interstVelocity.feed2) ...
./ params{idx_i}.interstitialVelocity;
end
otherwise % node EXTRACT; RAFFINATE; MIDDLE
% C_i^in = C_{i-1}^out
if ~strcmp(startingPointIndex, index)
column.inlet.concentration = currentData{idx_j}.outlet.concentration;
else
column.inlet.concentration = dummyProfile.concentration;
end
end
end % massConservation
function [outletProfile, lastState, currentData] = colSolver(currentData, interstVelocity, Feed, Desorbent, opt, sequence, k, varargin)
% ----------------------------------------------------------------------------------------
% Preparation of simulation of each column, which might combined with CSTR and DPFR
%
% Parameters:
% - currentData. Structure data of outlet chromatography and last column state
% - interstVelocity. Interstitial velocity
% - Feed. Components composition at Feed node
% - Desorbent. The component composition at Desorbent node
% - opt. Options
% - sequence. During switching, the structure used for storing the sequence of columns
%
% Returns:
% - outletProfile. Chromatogram over time
% - lastState. Last column STATE that is used as initial condition
% ----------------------------------------------------------------------------------------
% The node balance: transmission of concentration, column state, velocity and so on
column = SMB.massConservation(currentData, interstVelocity, Feed, Desorbent, opt, sequence, k);
if opt.enable_CSTR
% The CSTR before the current column
column.inlet = SMB.CSTR(column.inlet, column, opt);
[outletProfile, lastState] = SMB.secColumn(column.inlet, column.params, column.initialState, varargin{:});
% The CSTR after the current column
outletProfile.outlet = SMB.CSTR(outletProfile.outlet, column, opt);
elseif opt.enable_DPFR
% The DPFR before the current column
[column.inlet, lastState_DPFR_pre] = SMB.DPFR(column.inlet, column.initialState_DPFR{1}, opt);
[outletProfile, lastState] = SMB.secColumn(column.inlet, column.params, column.initialState, varargin{:});
% The DPFR after the current column
[outletProfile.outlet, lastState_DPFR_pos] = SMB.DPFR(outletProfile.outlet, column.initialState_DPFR{2}, opt);
currentData{sequence.(k)}.lastState_DPFR = [{lastState_DPFR_pre}, {lastState_DPFR_pos}];
else
% The simulation of a single column with the CADET solver
[outletProfile, lastState] = SMB.secColumn(column.inlet, column.params, column.initialState, varargin{:});
end
end % colSolver
function [currentData, sequence, convergIndx, convergPrevious, dummyProfile, dyncData, plotData] = preallocation(Feed, opt)
% ----------------------------------------------------------------------------------------
% Preallocation of necessary data
%
% Parameters:
% - Feed. Components composition at Feed node
% - opt. Options
%
% Returns:
% - currentData. Structure data of outlet chromatography and last column state
% - sequence. During switching, the structure used for storing the sequence of columns
% - convergIndx. Index of the column that used for check of stopping criterion
% - convergPrevious. Previous state of the column that used for check of stopping criterion
% - dummyProfile. Profile of the last column in terms of string
% - dyncData. Structure data used for generating trajectories of withdrawn ports
% - plotData. (columnNumber x switches), instant profile of each column in one iteration
% ----------------------------------------------------------------------------------------
global string stringSet startingPointIndex
% Generate an initial alphabet string set to identify positions of SMB unit.
% The position after desorbent node is, by default, marked as "a" (first one)
string = char(stringSet(1:opt.nColumn));
% Simulations follow the string sequence (starting from desorbent node)
% To change starting simulation position, shift num to corresponding value
string = circshift(string, 0);
% Be aware, in eight-zone case, simulations cannot begain after feed2 node
startingPointIndex = SMB.nodeIndexing(opt, string(1));
% pre-allocate memory to currentData matrix, which is the profile matrix of columns
currentData = cell(1, opt.nColumn);
for k = 1:opt.nColumn
currentData{k}.outlet.time = linspace(0, opt.switch, opt.timePoints);
currentData{k}.outlet.concentration = zeros(length(Feed.time), opt.nComponents);
currentData{k}.lastState = cell(1,2);
if opt.enable_DPFR
currentData{k}.lastState_DPFR = cell(1,2);
currentData{k}.lastState_DPFR{1} = zeros(opt.nComponents, opt.DPFR_nCells); % DPFR before
currentData{k}.lastState_DPFR{2} = zeros(opt.nComponents, opt.DPFR_nCells); % DPFR after
end
end
% Generate arabic numbers to identify columns
columnNumber = cell(1, opt.nColumn);
for k = 1:opt.nColumn
if k == 1, columnNumber{1} = opt.nColumn; else columnNumber{k} = k-1; end
end
% Combine alphabet string with arabic numbers for switching sake
sequence = cell2struct( columnNumber, stringSet(1:opt.nColumn), 2 );
% Specify the column for the convergence checking. The column after the Feed is usually adopted
if opt.nZone == 4
convergIndx = sum(opt.structID(1:2));
elseif opt.nZone == 5
convergIndx = sum(opt.structID(1:3));
elseif opt.nZone == 8
convergIndx = sum(opt.structID(1:3));
else
error('Please choose the correct zone configuration \n');
end
% convergPrevious is used for stopping criterion
convergPrevious = currentData{convergIndx}.outlet.concentration;
% The profile of last column in terms of sequence is stored as dummyProfile
dummyProfile = currentData{sequence.(string(end))}.outlet;
% plotData (columnNumber x switches), monitoring instant profile of each column in one iteration
plotData = cell(opt.nColumn,opt.nColumn);
% dyncData is used for generating trajectories of withdrawn ports
if opt.enableDebug
if opt.nZone == 4
dyncData = cell(2, opt.nMaxIter);
elseif opt.nZone == 5
dyncData = cell(3, opt.nMaxIter);
elseif opt.nZone == 8
dyncData = cell(3, opt.nMaxIter);
end
else
dyncData = [];
end
end % preallocation
function dyncData = dyncDataUpdate(dyncData, currentData, sequence, stringSet, opt, i)
% ----------------------------------------------------------------------------------------
% A script to update dyncData
%
% Parameters:
% - currentData. Structure data of outlet chromatography and last column state
% - sequence. During switching, the structure used for storing the sequence of columns
% - stringSet.
%
% Returns:
% - dyncData. Structure data used for generating trajectories of withdrawn ports
% ----------------------------------------------------------------------------------------
if opt.nZone == 4
dyncData{1, i} = currentData{sequence.(char(stringSet(sum(opt.structID(1:3)))))}.outlet.concentration;
dyncData{2, i} = currentData{sequence.(char(stringSet(opt.structID(1))))}.outlet.concentration;
elseif opt.nZone == 5
dyncData{1, i} = currentData{sequence.(char(stringSet(sum(opt.structID(1:4)))))}.outlet.concentration;
if strcmp('extract', opt.intermediate) % two extract ports
dyncData{2, i} = currentData{sequence.(char(stringSet(sum(opt.structID(1:2)))))}.outlet.concentration;
elseif strcmp('raffinate', opt.intermediate) % two raffinate ports
dyncData{2, i} = currentData{sequence.(char(stringSet(sum(opt.structID(1:3)))))}.outlet.concentration;
end
dyncData{3, i} = currentData{sequence.(char(stringSet(opt.structID(1))))}.outlet.concentration;
elseif opt.nZone == 8
dyncData{1, i} = currentData{sequence.(char(stringSet(sum(opt.structID(1:7)))))}.outlet.concentration;
dyncData{2, i} = currentData{sequence.(char(stringSet(sum(opt.structID(1:5)))))}.outlet.concentration;
if strcmp('extract', opt.intermediate_feed) % two extract ports
dyncData{3, i} = currentData{sequence.(char(stringSet(sum(opt.structID(1:3)))))}.outlet.concentration;
elseif strcmp('raffinate', opt.intermediate_feed) % two raffinate ports
dyncData{3, i} = currentData{sequence.(char(stringSet(opt.structID(1))))}.outlet.concentration;
end
end
end % dyncDataUpdate
function Feed2Connect(outletProfile, Feed, interstVelocity, stringSet, opt, k)
% ----------------------------------------------------------------------------------------
% Get composition of Feed2 inlet from the first sub-unit
%
% Parameters:
% - outletProfile. Chromatogram over time
% - Feed. Components composition at Feed node
% - opt. Options
% ----------------------------------------------------------------------------------------
global Feed2
if opt.nZone == 8
if ( strcmp('raffinate', opt.intermediate_feed) && strcmp(k, stringSet(sum(opt.structID(1:3)))) ) ...
|| ( strcmp('extract', opt.intermediate_feed) && strcmp(k, stringSet(opt.structID(1))) )
Feed2 = outletProfile.outlet;
if strcmp('StericMassActionBinding', opt.BindingModel)
Feed2.concentration = Feed2.concentration .* interstVelocity.raffinate1 ./ interstVelocity.feed2;
end
end
end
end % Feed2Connect
function [convergPrevious, flag] = stoppingCriterion(convergPrevious, currentData, convergIndx, opt, i)
% ----------------------------------------------------------------------------------------
% Check the stopping criterion once a while
%
% Parameters:
% - convergPrevious. Previous state of the column that used for check of stopping criterion
% - currentData. Structure data of outlet chromatography and last column state
% - convergIndx. Index of the column that used for check of stopping criterion
% - opt. option of parameters
%
% Returns:
% - flag. If stopping criterion is satisfied, flag is true.
% ----------------------------------------------------------------------------------------
flag = 0;
% Convergence criterion adopted in each nColumn switches
% ||( C(z, t) - C(z, t + nColumn * t_s) ) / C(z, t)|| < tol, for a specific column
if mod(i, opt.nColumn) == 0
diffNorm = 0; stateNorm = 0;
for k = 1:opt.nComponents
diffNorm = diffNorm + norm( convergPrevious(:,k) - currentData{convergIndx}.outlet.concentration(:,k) );
stateNorm = stateNorm + norm( currentData{convergIndx}.outlet.concentration(:,k) );
end
relativeDelta = diffNorm / stateNorm;
% Interactive plotting when debug mode is active
SMB.UIplot('cycle', opt, i, relativeDelta);
if relativeDelta <= opt.tolIter
flag = 1;
else
convergPrevious = currentData{convergIndx}.outlet.concentration;
end
end
end % stoppingCriterion
function params = getParams(sequence, interstVelocity, opt, index, alphabet, pre_alphabet)
% ----------------------------------------------------------------------------------------
% After each swtiching, the value of velocities and initial conditions are changed
%
% Parameters:
% - sequence. The alphabet of each zone and their column number
% - interstVelocity. The interstitial velocity of each zone
% - opt. option of parameterss
% - index. The capital letter used to indicate which zone current column situated in
% - alphabet. The letter of current calculated column, i.
% - pre_alphabet. The letter of column before the current calculated one, i-1.
%
% Returns:
% - params. interstitial velocity, axial dispersion and boundary conditions
% ----------------------------------------------------------------------------------------
if nargin < 6
error('SMB.getParams: There are no enough arguments \n');
end
if length(opt.dispersionColumn) ~= opt.nZone
error('SMB.getParams: The dimension of dispersionColumn in getParameters routine is not correct \n');
end
params = cell(1, opt.nColumn);
% Set the initial conditions to the solver, but when lastState is used, this setup will be ignored
params{sequence.(alphabet)} = struct('initialBulk', zeros(1,opt.nComponents), 'initialSolid',...
zeros(1,opt.nComponents), 'interstitialVelocity', [], 'dispersionColumn', []);
params{sequence.(pre_alphabet)} = struct('initialBulk', zeros(1,opt.nComponents), 'initialSolid',...
zeros(1,opt.nComponents), 'interstitialVelocity', [], 'dispersionColumn', []);
% For steric mass action isotherm, as salt concentration is considered
if strcmp('StericMassActionBinding', opt.BindingModel)
params{sequence.(alphabet)}.initialSolid = [opt.LAMBDA, zeros(1, opt.nComponents-1)];
% step-wise salt concentration in ion-exchange SMB
switch index
case {'F' 'M_F' 'R' 'M_R' 'F1' 'M_F1' 'R1' 'M_R1'}
params{sequence.(alphabet)}.initialBulk = [opt.concentrationSalt(1,1), zeros(1,opt.nComponents-1)];
case {'D' 'M_D' 'E' 'M_E' 'D1' 'M_D1' 'E1' 'M_E1'}
params{sequence.(alphabet)}.initialBulk = [opt.concentrationSalt(1,2), zeros(1,opt.nComponents-1)];
case {'F2' 'M_F2' 'R2' 'M_R2'}
params{sequence.(alphabet)}.initialBulk = [opt.concentrationSalt(2,1), zeros(1,opt.nComponents-1)];
case {'D2' 'M_D2' 'E2' 'M_E2'}
params{sequence.(alphabet)}.initialBulk = [opt.concentrationSalt(2,2), zeros(1,opt.nComponents-1)];
end
end
if opt.nZone == 4
switch index
case {'D' 'M_D'}
params{sequence.(alphabet)}.interstitialVelocity = interstVelocity.recycle;
params{sequence.(pre_alphabet)}.interstitialVelocity = interstVelocity.recycle - interstVelocity.desorbent;
params{sequence.(alphabet)}.dispersionColumn = opt.dispersionColumn(1);
case {'E' 'M_E'}
params{sequence.(alphabet)}.interstitialVelocity = interstVelocity.recycle - interstVelocity.extract;
params{sequence.(pre_alphabet)}.interstitialVelocity = interstVelocity.recycle;
params{sequence.(alphabet)}.dispersionColumn = opt.dispersionColumn(2);
case {'F' 'M_F'}
params{sequence.(alphabet)}.interstitialVelocity = interstVelocity.recycle ...
- interstVelocity.extract + interstVelocity.feed;
params{sequence.(pre_alphabet)}.interstitialVelocity = interstVelocity.recycle - interstVelocity.extract;
params{sequence.(alphabet)}.dispersionColumn = opt.dispersionColumn(3);
case {'R' 'M_R'}
params{sequence.(alphabet)}.interstitialVelocity = interstVelocity.recycle - interstVelocity.desorbent;
params{sequence.(pre_alphabet)}.interstitialVelocity = interstVelocity.recycle ...
- interstVelocity.extract + interstVelocity.feed;
params{sequence.(alphabet)}.dispersionColumn = opt.dispersionColumn(4);
end
elseif opt.nZone == 5
if strcmp('extract', opt.intermediate)
switch index
case {'D' 'M_D'}
params{sequence.(alphabet)}.interstitialVelocity = interstVelocity.recycle;
params{sequence.(pre_alphabet)}.interstitialVelocity = interstVelocity.recycle - interstVelocity.desorbent;
params{sequence.(alphabet)}.dispersionColumn = opt.dispersionColumn(1);
case {'E1' 'M_E1'}
params{sequence.(alphabet)}.interstitialVelocity = interstVelocity.recycle - interstVelocity.extract1;
params{sequence.(pre_alphabet)}.interstitialVelocity = interstVelocity.recycle;
params{sequence.(alphabet)}.dispersionColumn = opt.dispersionColumn(2);
case {'E2' 'M_E2'}
params{sequence.(alphabet)}.interstitialVelocity = interstVelocity.recycle ...
- interstVelocity.extract1 - interstVelocity.extract2;
params{sequence.(pre_alphabet)}.interstitialVelocity = interstVelocity.recycle - interstVelocity.extract1;
params{sequence.(alphabet)}.dispersionColumn = opt.dispersionColumn(3);
case {'F' 'M_F'}
params{sequence.(alphabet)}.interstitialVelocity = interstVelocity.recycle ...
- interstVelocity.desorbent + interstVelocity.raffinate;
params{sequence.(pre_alphabet)}.interstitialVelocity = interstVelocity.recycle ...
- interstVelocity.extract1 - interstVelocity.extract2;
params{sequence.(alphabet)}.dispersionColumn = opt.dispersionColumn(4);
case {'R' 'M_R'}
params{sequence.(alphabet)}.interstitialVelocity = interstVelocity.recycle - interstVelocity.desorbent;
params{sequence.(pre_alphabet)}.interstitialVelocity = interstVelocity.recycle ...
- interstVelocity.desorbent + interstVelocity.raffinate;
params{sequence.(alphabet)}.dispersionColumn = opt.dispersionColumn(5);
end
elseif strcmp('raffinate', opt.intermediate)
switch index
case {'D' 'M_D'}
params{sequence.(alphabet)}.interstitialVelocity = interstVelocity.recycle;
params{sequence.(pre_alphabet)}.interstitialVelocity = interstVelocity.recycle - interstVelocity.desorbent;
params{sequence.(alphabet)}.dispersionColumn = opt.dispersionColumn(1);
case {'E' 'M_E'}
params{sequence.(alphabet)}.interstitialVelocity = interstVelocity.recycle - interstVelocity.extract;
params{sequence.(pre_alphabet)}.interstitialVelocity = interstVelocity.recycle;
params{sequence.(alphabet)}.dispersionColumn = opt.dispersionColumn(2);
case {'F' 'M_F'}
params{sequence.(alphabet)}.interstitialVelocity = interstVelocity.recycle ...
- interstVelocity.extract + interstVelocity.feed;
params{sequence.(pre_alphabet)}.interstitialVelocity = interstVelocity.recycle - interstVelocity.extract;
params{sequence.(alphabet)}.dispersionColumn = opt.dispersionColumn(3);
case {'R1' 'M_R1'}
params{sequence.(alphabet)}.interstitialVelocity = interstVelocity.recycle ...
- interstVelocity.desorbent + interstVelocity.raffinate2;
params{sequence.(pre_alphabet)}.interstitialVelocity = interstVelocity.recycle ...
- interstVelocity.extract + interstVelocity.feed;
params{sequence.(alphabet)}.dispersionColumn = opt.dispersionColumn(4);
case {'R2' 'M_R2'}
params{sequence.(alphabet)}.interstitialVelocity = interstVelocity.recycle - interstVelocity.desorbent;
params{sequence.(pre_alphabet)}.interstitialVelocity = interstVelocity.recycle ...
- interstVelocity.desorbent + interstVelocity.raffinate2;
params{sequence.(alphabet)}.dispersionColumn = opt.dispersionColumn(5);
end
end
elseif opt.nZone == 8
switch index
case {'D1' 'M_D1'}
params{sequence.(alphabet)}.interstitialVelocity = interstVelocity.recycle;
params{sequence.(pre_alphabet)}.interstitialVelocity = interstVelocity.recycle - interstVelocity.desorbent1;
params{sequence.(alphabet)}.dispersionColumn = opt.dispersionColumn(1);
case {'E1' 'M_E1'}
params{sequence.(alphabet)}.interstitialVelocity = interstVelocity.recycle - interstVelocity.extract1;
params{sequence.(pre_alphabet)}.interstitialVelocity = interstVelocity.recycle;
params{sequence.(alphabet)}.dispersionColumn = opt.dispersionColumn(2);
case {'F1' 'M_F1'}
params{sequence.(alphabet)}.interstitialVelocity = interstVelocity.recycle ...
- interstVelocity.extract1 + interstVelocity.feed1;
params{sequence.(pre_alphabet)}.interstitialVelocity = interstVelocity.recycle - interstVelocity.extract1;
params{sequence.(alphabet)}.dispersionColumn = opt.dispersionColumn(3);
case {'R1' 'M_R1'}
params{sequence.(alphabet)}.interstitialVelocity = interstVelocity.recycle ...
- interstVelocity.extract1 + interstVelocity.feed1 - interstVelocity.raffinate1;
params{sequence.(pre_alphabet)}.interstitialVelocity = interstVelocity.recycle ...
- interstVelocity.extract1 + interstVelocity.feed1;
params{sequence.(alphabet)}.dispersionColumn = opt.dispersionColumn(4);
case {'D2' 'M_D2'}
params{sequence.(alphabet)}.interstitialVelocity = interstVelocity.recycle ...
- interstVelocity.extract1 + interstVelocity.feed1 - interstVelocity.raffinate1 + interstVelocity.desorbent2;
params{sequence.(pre_alphabet)}.interstitialVelocity = interstVelocity.recycle ...
- interstVelocity.extract1 + interstVelocity.feed1 - interstVelocity.raffinate1;
params{sequence.(alphabet)}.dispersionColumn = opt.dispersionColumn(5);
case {'E2' 'M_E2'}
params{sequence.(alphabet)}.interstitialVelocity = interstVelocity.recycle ...
- interstVelocity.desorbent1 + interstVelocity.raffinate2 - interstVelocity.feed2;
params{sequence.(pre_alphabet)}.interstitialVelocity = interstVelocity.recycle ...
- interstVelocity.extract1 + interstVelocity.feed1 - interstVelocity.raffinate1 + interstVelocity.desorbent2;
params{sequence.(alphabet)}.dispersionColumn = opt.dispersionColumn(6);
case {'F2' 'M_F2'}
params{sequence.(alphabet)}.interstitialVelocity = interstVelocity.recycle ...
- interstVelocity.desorbent1 + interstVelocity.raffinate2;
params{sequence.(pre_alphabet)}.interstitialVelocity = interstVelocity.recycle ...
- interstVelocity.desorbent1 + interstVelocity.raffinate2 - interstVelocity.feed2;
params{sequence.(alphabet)}.dispersionColumn = opt.dispersionColumn(7);
case {'R2' 'M_R2'}
params{sequence.(alphabet)}.interstitialVelocity = interstVelocity.recycle - interstVelocity.desorbent1;
params{sequence.(pre_alphabet)}.interstitialVelocity = interstVelocity.recycle ...
- interstVelocity.desorbent1 + interstVelocity.raffinate2;
params{sequence.(alphabet)}.dispersionColumn = opt.dispersionColumn(8);
end
end
end % getParams
function stringSet = stringGeneration()
% ----------------------------------------------------------------------------------------
% Generate strings to mark columns in SMB system
% ----------------------------------------------------------------------------------------
stringSet = {'a' 'b' 'c' 'd' 'e' 'f' 'g' 'h' 'i' 'j' 'k' 'l' 'm'...
'n' 'o' 'p' 'q' 'r' 's' 't' 'u' 'v' 'w' 'x' 'y' 'z'...
'aa' 'bb' 'cc' 'dd' 'ee' 'ff' 'gg' 'hh' 'ii' 'jj' 'kk' 'll' 'mm'...
'nn' 'oo' 'pp' 'qq' 'rr' 'ss' 'tt' 'uu' 'vv' 'ww' 'xx' 'yy' 'zz'};
% 'a1' 'b1' 'c1' 'd1' 'e1' 'f1' 'g1' 'h1' 'i1' 'j1' 'k1' 'l1' 'm1'...
% 'n1' 'o1' 'p1' 'q1' 'r1' 's1' 't1' 'u1' 'v1' 'w1' 'x1' 'y1' 'z1'...
% 'a2' 'b2' 'c2' 'd2' 'e2' 'f2' 'g2' 'h2' 'i2' 'j2' 'k2' 'l2' 'm2'...
% 'n2' 'o2' 'p2' 'q2' 'r2' 's2' 't2' 'u2' 'v2' 'w2' 'x2' 'y2' 'z2'...
% 'a3' 'b3' 'c3' 'd3' 'e3' 'f3' 'g3' 'h3' 'i3' 'j3' 'k3' 'l3' 'm3'...
% 'n3' 'o3' 'p3' 'q3' 'r3' 's3' 't3' 'u3' 'v3' 'w3' 'x3' 'y3' 'z3'...
% 'a4' 'b4' 'c4' 'd4' 'e4' 'f4' 'g4' 'h4' 'i4' 'j4' 'k4' 'l4' 'm4'...
% 'n4' 'o4' 'p4' 'q4' 'r4' 's4' 't4' 'u4' 'v4' 'w4' 'x4' 'y4' 'z4' ...
% 'a5' 'b5' 'c5' 'd5' 'e5' 'f5' 'g5' 'h5' 'i5' 'j5' 'k5' 'l5' 'm5'...
% 'n5' 'o5' 'p5' 'q5' 'r5' 's5' 't5' 'u5' 'v5' 'w5' 'x5' 'y5' 'z5' ...
% 'a6' 'b6' 'c6' 'd6' 'e6' 'f6' 'g6' 'h6' 'i6' 'j6' 'k6' 'l6' 'm6'...
% 'n6' 'o6' 'p6' 'q6' 'r6' 's6' 't6' 'u6' 'v6' 'w6' 'x6' 'y6' 'z6' ...
% 'a7' 'b7' 'c7' 'd7' 'e7' 'f7' 'g7' 'h7' 'i7' 'j7' 'k7' 'l7' 'm7'...
% 'n7' 'o7' 'p7' 'q7' 'r7' 's7' 't7' 'u7' 'v7' 'w7' 'x7' 'y7' 'z7' ...
% 'a8' 'b8' 'c8' 'd8' 'e8' 'f8' 'g8' 'h8' 'i8' 'j8' 'k8' 'l8' 'm8'...
% 'n8' 'o8' 'p8' 'q8' 'r8' 's8' 't8' 'u8' 'v8' 'w8' 'x8' 'y8' 'z8' ...
% 'a9' 'b9' 'c9' 'd9' 'e9' 'f9' 'g9' 'h9' 'i9' 'j9' 'k9' 'l9' 'm9'...
% 'n9' 'o9' 'p9' 'q9' 'r9' 's9' 't9' 'u9' 'v9' 'w9' 'x9' 'y9' 'z9' ...
end % stringGeneration
function index = nodeIndexing(opt, alphabet)
% ----------------------------------------------------------------------------------------
% This function interprets the alphabet of columns into the position of SMB unit
%
% Parameters:
% - opt. options involving the parameters for models
% - alphabet. The letter is used for switching
%
% Returns:
% - index. The indexing letter used for calculation of the mass conservation
% ----------------------------------------------------------------------------------------
global stringSet;
if nargin < 2
error('SMB.nodeIndexing: There are no enough arguments \n');
end
string = stringSet(1:opt.nColumn);
% Preallocation
% stringBlock is used for storing the alphabet in each zone
stringBlock = cell(1, opt.nZone);
% Separate the string into nZone cells
stringBlock{1} = string(1:opt.structID(1));
for k = 2:opt.nZone
stringBlock{k} = string( sum(opt.structID(1:k-1))+1 : sum(opt.structID(1:k)) );
end
% Assign each alphabet with the node indexing letter
if opt.nZone == 4
if any( strcmp(alphabet, stringBlock{1}) )
if strcmp(alphabet, stringBlock{1}(1)), index = 'D'; else index = 'M_D'; end
elseif any( strcmp(alphabet, stringBlock{2}) )
if strcmp(alphabet, stringBlock{2}(1)), index = 'E'; else index = 'M_E'; end
elseif any( strcmp(alphabet, stringBlock{3}) )
if strcmp(alphabet, stringBlock{3}(1)), index = 'F'; else index = 'M_F'; end
elseif any( strcmp(alphabet, stringBlock{4}) )
if strcmp(alphabet, stringBlock{4}(1)), index = 'R'; else index = 'M_R'; end
end
elseif opt.nZone == 5
if strcmp('extract', opt.intermediate)
% For two extract scheme
if any( strcmp(alphabet, stringBlock{1}) )
if strcmp(alphabet, stringBlock{1}(1)), index = 'D'; else index = 'M_D'; end
elseif any( strcmp(alphabet, stringBlock{2}) )
if strcmp(alphabet, stringBlock{2}(1)), index = 'E1'; else index = 'M_E1'; end
elseif any( strcmp(alphabet, stringBlock{3}) )
if strcmp(alphabet, stringBlock{3}(1)), index = 'E2'; else index = 'M_E2'; end
elseif any( strcmp(alphabet, stringBlock{4}) )
if strcmp(alphabet, stringBlock{4}(1)), index = 'F'; else index = 'M_F'; end
elseif any( strcmp(alphabet, stringBlock{5}) )
if strcmp(alphabet, stringBlock{5}(1)), index = 'R'; else index = 'M_R'; end
end
elseif strcmp('raffinate', opt.intermediate)
% For two raffinate scheme
if any( strcmp(alphabet, stringBlock{1}) )
if strcmp(alphabet, stringBlock{1}(1)), index = 'D'; else index = 'M_D'; end
elseif any( strcmp(alphabet, stringBlock{2}) )
if strcmp(alphabet, stringBlock{2}(1)), index = 'E'; else index = 'M_E'; end
elseif any( strcmp(alphabet, stringBlock{3}) )
if strcmp(alphabet, stringBlock{3}(1)), index = 'F'; else index = 'M_F'; end
elseif any( strcmp(alphabet, stringBlock{4}) )
if strcmp(alphabet, stringBlock{4}(1)), index = 'R1'; else index = 'M_R1'; end
elseif any( strcmp(alphabet, stringBlock{5}) )
if strcmp(alphabet, stringBlock{5}(1)), index = 'R2'; else index = 'M_R2'; end
end
end
elseif opt.nZone == 8
if any( strcmp(alphabet, stringBlock{1}) )
if strcmp(alphabet, stringBlock{1}(1)), index = 'D1'; else index = 'M_D1'; end
elseif any( strcmp(alphabet, stringBlock{2}) )
if strcmp(alphabet, stringBlock{2}(1)), index = 'E1'; else index = 'M_E1'; end
elseif any( strcmp(alphabet, stringBlock{3}) )
if strcmp(alphabet, stringBlock{3}(1)), index = 'F1'; else index = 'M_F1'; end
elseif any( strcmp(alphabet, stringBlock{4}) )
if strcmp(alphabet, stringBlock{4}(1)), index = 'R1'; else index = 'M_R1'; end
elseif any( strcmp(alphabet, stringBlock{5}) )
if strcmp(alphabet, stringBlock{5}(1)), index = 'D2'; else index = 'M_D2'; end
elseif any( strcmp(alphabet, stringBlock{6}) )
if strcmp(alphabet, stringBlock{6}(1)), index = 'E2'; else index = 'M_E2'; end
elseif any( strcmp(alphabet, stringBlock{7}) )
if strcmp(alphabet, stringBlock{7}(1)), index = 'F2'; else index = 'M_F2'; end
elseif any( strcmp(alphabet, stringBlock{8}) )
if strcmp(alphabet, stringBlock{8}(1)), index = 'R2'; else index = 'M_R2'; end
end
end % opt.nZone
end % nodeIndexing
function obj = positionIndexing(opt)
% ----------------------------------------------------------------------------------------
% This is the function that tells the Purity_Productivity which column is used for
% calculation of purity and productivity. It is vital in arbitrary column
% configurations and it also depends on the plotData and the referred column.
%
% Parameters:
% - opt. options
%
% Returns:
% - obj. A struct data which contains the numbers for indicating the EXTRACT and
% RAFFINATE ports those are used for calculation of purity and productivity
% ----------------------------------------------------------------------------------------
Number = circshift( (fliplr(1:opt.nColumn))', 1 );
% numberBlock is used for storing the column number in each zone
numberBlock = cell(1, opt.nZone);
% Separate the number string into nZone cells
numberBlock{1} = Number(1:opt.structID(1));
for k = 2:opt.nZone
numberBlock{k} = Number( sum(opt.structID(1:k-1))+1 : sum(opt.structID(1:k)) );
end
if opt.nZone == 4
obj.position = [numberBlock{1}(end), numberBlock{3}(end)]; % [Desorbent, Feed] node
elseif opt.nZone == 5
if strcmp('extract', opt.intermediate)
obj.position = [numberBlock{1}(end), numberBlock{2}(end), numberBlock{4}(end)]; % [Desorbent, Extract1, Feed] node
elseif strcmp('raffinate', opt.intermediate)
obj.position = [numberBlock{1}(end), numberBlock{3}(end), numberBlock{4}(end)]; % [Desorbent, Feed, Raffinate1] node
end
elseif opt.nZone == 8
if strcmp('raffinate', opt.intermediate_feed)
obj.position = [numberBlock{1}(end), numberBlock{5}(end), numberBlock{7}(end)]; % [Desorbent1, Desorbent2, Feed2] node
elseif strcmp('extract', opt.intermediate_feed)
obj.position = [numberBlock{3}(end), numberBlock{5}(end), numberBlock{7}(end)]; % [Feed1, Desorbent2, Feed2] node
end
end
end % positionIndexing
function flag = interstVelocityCheck(interstVelocity, opt)
% ----------------------------------------------------------------------------------------
% This function checks the existance of the negative velocity and returns false to flag
%
% Parameters:
% - opt. options
% - interstVelocity. The interstitial velocity in the SMB unit
%
% Returns:
% - flag. flag = 1, there is negative velocity in the struct of interstVelocity
% ----------------------------------------------------------------------------------------
if nargin < 2
error('SMB.interstVelocity: There are no enough arguments \n');
end
if opt.nZone == 4
velocity = [interstVelocity.recycle, interstVelocity.feed ...
interstVelocity.raffinate, interstVelocity.desorbent, interstVelocity.extract];
flag = any(velocity <= 0);
flag = flag || (interstVelocity.recycle - interstVelocity.desorbent) < 0;
flag = flag || (interstVelocity.recycle - interstVelocity.extract) < 0;
elseif opt.nZone == 5
if strcmp('extract', opt.intermediate)
velocity = [interstVelocity.recycle, interstVelocity.feed ...
interstVelocity.raffinate, interstVelocity.desorbent ...
interstVelocity.extract1, interstVelocity.extract2];
flag = any(velocity <= 0);
flag = flag || (interstVelocity.recycle - interstVelocity.desorbent) < 0;
flag = flag || (interstVelocity.recycle - interstVelocity.extract1) < 0;
flag = flag || (interstVelocity.recycle - interstVelocity.extract1 - interstVelocity.extract2) < 0;
elseif strcmp('raffinate', opt.intermediate)
velocity = [interstVelocity.recycle, interstVelocity.feed ...
interstVelocity.raffinate1, interstVelocity.raffinate2 ...
interstVelocity.desorbent, interstVelocity.extract];
flag = any(velocity <= 0);
flag = flag || (interstVelocity.recycle - interstVelocity.desorbent) < 0;
flag = flag || (interstVelocity.recycle - interstVelocity.extract) < 0;
flag = flag || (interstVelocity.recycle - interstVelocity.extract + interstVelocity.feed - interstVelocity.raffinate1) < 0;