-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgradientcheck.js
3009 lines (2491 loc) · 147 KB
/
gradientcheck.js
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
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
/// GradientCheck
/// Written by John Degenstein, Purdue University
/// Version 0.96
/// Date: February X, 2016
/// Mears Axial Dispersion formula corrected
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
//
//Copyright © 2016 Purdue University All rights reserved.
//
//Developed by: Purdue Catalysis Center, School of Chemical Engineering, Purdue University
//https://engineering.purdue.edu/~catalyst/
//
//Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal with the Software without restriction, including without limitation the rights to use, copy, modify, //merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
//Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimers.
//Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimers in the documentation and/or other materials provided with the distribution.
//Neither the names of ??, nor the names of its contributors may be used to endorse or promote products derived from this Software without specific prior written permission.
//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE CONTRIBUTORS OR COPYRIGHT HOLDERS //BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE.
//
//////////////////////////////////////////////////////////////////////
//this code is for hiding sections of calculated properties with the red "+" signs
$(document).ready(function(){
$('#hide_mixing').on('click', function(){
$('#mixing').toggle('fast');
});
$('#hide_ndims').on('click', function(){
$('#ndims').toggle('fast');
});
$('#hide_catprops').on('click', function(){
$('#catprops').toggle('fast');
});
$('#hide_intgrad').on('click', function(){
$('#intgrad').toggle('fast');
});
$('#hide_calculated').on('click', function(){
$('#calculated').toggle('fast');
});
$('#hide_bedscalegrads').on('click', function(){
$('#bedscalegrads').toggle('fast');
});
$('#hide_valtests').on('click', function(){
$('#valtests').toggle('fast');
});
$('#hide_mears_disp').on('click', function(){
$('#tbody_mears_disp').toggle('fast');
});
$('#hide_gierman_disp').on('click', function(){
$('#tbody_gierman_disp').toggle('fast');
});
$('#hide_sie_walleffect').on('click', function(){
$('#tbody_sie_walleffect').toggle('fast');
});
$('#hide_mears_radialintp').on('click', function(){
$('#tbody_mears_radialintp').toggle('fast');
});
});
//////////////////////////////////////////////////////////////////////
//used for math.format calls later to reformat number output
var val_out = {notation: 'auto', precision: 3}; // see http://mathjs.org/docs/reference/functions/format.html for further info
//////////////////////////////////////////////////////////////////////
//the below function triggers change for all input IDs in the document, in order to manually update the calculations
$(document).ready(function(){
$("#calculate_all_fields").on('click', function (){
var ids = $('input[id]').map(function() {
return this.id;
}).get();
ids = ids.map(function(currentItem){
return "#" + currentItem //make list of IDs prepended with a "#"
});
var idsJoined = ids.join(","); //make into a single long string
$(idsJoined).trigger("change"); //triggers change to update later calculations
});
});
//preinitialize myFile object, later used for logic check
var myFile = $('#form_data_json').prop('files');
////////////////////////////////////////////////////////////////////////////
// reads in an input JSON from user file
$(document).ready(function(){
$("#form_data_json").on('change', function(){
var myFile = $('#form_data_json').prop('files');
var reader = new FileReader();
reader.onload = function(event) { //wait for asynchronous load event to take place
var myData = event.target.result;
window.myData = myData;
};
if (myFile.length == 0) {
var JSONdata = {}
} else {
var JSONdata = reader.readAsText(myFile.item(0));
}
});
});
////////////////////////////////////////////////////////////////////////////
//populates above input JSON file into the form itself
$(document).ready(function(){
$("#populate_inputs").on('click', function(){
$(".initialize").trigger("change");
////////////////////////
var parsedJSON = $.parseJSON(window.myData);
// next line looks for all input sections in html
var $inputs = $('input'); //get inputs in HTML
var $textarea = $('textarea'); //get textareas in HTML
var $dropdowns = $('select'); //get dropdowns (aka select) in HTML
$.each(parsedJSON, function(i, pair) {
if (pair.name == "notes_section") { //hardcoded to id of the only textarea
$textarea.filter(function() { //populates text area (currently only one) with text
return pair.name == this.id;
}).val(pair.value);
} else if (/^dr_/i.test(pair.name)) { //looks for id that starts with dr_ to indicate dropdown
$dropdowns.filter(function() { //populates dropdown (aka select) with text
return pair.name == this.id;
}).val(pair.value);
$("#dr_cat_shape,#dr_num_reactants,#dr_num_products").trigger("change");//necessary to force HTML to trigger additional particle dimensions, and reactant/products
} else if (/^ck_/i.test(pair.name)) { //looks for id that starts with ck_ to indicate checkbox
$inputs.filter(function() {
if (this.value == "on") { //if the value is on then send pair.name to parent
return pair.name == this.id
} else { //if the value is NULL then dont do anything, and the checkbox will KEEP its current state <-- not fixing this issue for now
//do nothing
}
}).prop('checked',true);
} else { //for everything else not included above
$inputs.filter(function() { //populates input areas that match "id" with the JSON input
return pair.name == this.id;
}).val(pair.value);
}
});
});
});
////////////////////////////////////////////////////////////////////////////
//function for hiding/showing additional particle dimensions for Spheres/Cylinders/Rings
$(document).ready(function(){
$('#dr_cat_shape,#populate_inputs').on('change click', function(){
if ($('#dr_cat_shape').val() == "Spheres"){$('#tbody_cat_shape_L').hide('fast');$('#tbody_cat_shape_Rin').hide('fast');} //hide both additional particle dimensions
if ($('#dr_cat_shape').val() == "Cylinders"){$('#tbody_cat_shape_L').show('fast');$('#tbody_cat_shape_Rin').hide('fast');} //show L particle dimensions
if ($('#dr_cat_shape').val() == "Rings"){$('#tbody_cat_shape_L').show('fast');$('#tbody_cat_shape_Rin').show('fast');} //show both additional particle dimensions
});
});
////////////////////////////////////////////////////////////////////////////
//function for hiding/showing additional reactants and products and their property inputs and limiting reactant
$(document).ready(function(){
$('#dr_num_reactants,#dr_num_products,#populate_inputs').on('keyup keydown change click', function(){
if ($('#dr_num_reactants').val() == "One" && $('#dr_num_products').val() == "One"){ //OPTION A -- hide 2 and 4, header reads A, B, C
$('#tr_reactants_products_diluent_header').html('<td></td><td class="MainReact">Main<br>Reactant A</td><td>Product B</td><td>Diluent C</td><td></td>') //header reads A, B, C
$('#tr_reactants_products_diluent_header_igdens').html('<td></td><td>Reactant A</td><td>Product B</td><td>Diluent C</td><td></td>') //header reads A, B, C
$('#tr_reactants_products_diluent_header_fuller').html('<td></td><td>Reactant A</td><td>Product B</td><td>Diluent C</td><td></td>') //header reads A, B, C
$('#tr_reactants_products_diluent_header_lebas').html('<td></td><td>Reactant A</td><td>Product B</td><td>Diluent C</td><td></td>') //header reads A, B, C
$('input.nar').css('max-width','110px'); //change width of input cells
//hide BOTH 2 and 4
$('#hide_molweight2,#hide_molweight4,#hide_fluidvisc2,#hide_fluidvisc4,#hide_heatcapacity2,#hide_heatcapacity4,#hide_thermalcond2,#hide_thermalcond4,#hide_molfrac2,#hide_molfrac4,#hide_res_gasdens2,#hide_res_gasdens4,#hide_difvol2,#hide_difvol4,#hide_column_dvol2,#hide_column_dvol4,#hide_column_vb2,#hide_column_vb4,#hide_molar_boil_vol2,#hide_molar_boil_vol4,#hide_liq_density2,#hide_liq_density4,#hide_wilke_assoc_phi2,#hide_wilke_assoc_phi4,#tbody_limitingreactant').hide('fast');
} else if ($('#dr_num_reactants').val() == "Two" && $('#dr_num_products').val() == "One"){ //OPTION B -- hide 4, header reads A, B, C, D
$('#tr_reactants_products_diluent_header').html('<td></td><td class="MainReact">Main<br>Reactant A</td><td>Reactant B</td><td>Product C</td><td>Diluent D</td><td></td>') //header reads A, B, C, D
$('#tr_reactants_products_diluent_header_igdens').html('<td></td><td>Reactant A</td><td>Reactant B</td><td>Product C</td><td>Diluent D</td><td></td>') //header reads A, B, C, D
$('#tr_reactants_products_diluent_header_fuller').html('<td></td><td>Reactant A</td><td>Reactant B</td><td>Product C</td><td>Diluent D</td><td></td>') //header reads A, B, C, D
$('#tr_reactants_products_diluent_header_lebas').html('<td></td><td>Reactant A</td><td>Reactant B</td><td>Product C</td><td>Diluent D</td><td></td>') //header reads A, B, C, D
$('input.nar').css('max-width','100px'); //change width of input cells
$('#hide_molweight2,#hide_fluidvisc2,#hide_heatcapacity2,#hide_thermalcond2,#hide_molfrac2,#hide_res_gasdens2,#hide_difvol2,#hide_column_dvol2,#hide_column_vb2,#hide_molar_boil_vol2,#hide_liq_density2,#hide_wilke_assoc_phi2,#tbody_limitingreactant').show('fast'); //show 2
$('#hide_molweight4,#hide_fluidvisc4,#hide_heatcapacity4,#hide_thermalcond4,#hide_molfrac4,#hide_res_gasdens4,#hide_difvol4,#hide_column_dvol4,#hide_column_vb4,#hide_molar_boil_vol4,#hide_liq_density4,#hide_wilke_assoc_phi4').hide('fast'); //hide 4
} else if ($('#dr_num_reactants').val() == "One" && $('#dr_num_products').val() == "Two"){ //OPTION C -- hide 2, header reads A, B, C, D
$('#tr_reactants_products_diluent_header').html('<td></td><td class="MainReact">Main<br>Reactant A</td><td>Product B</td><td>Product C</td><td>Diluent D</td><td></td>') //header reads A, B, C, D
$('#tr_reactants_products_diluent_header_igdens').html('<td></td><td>Reactant A</td><td>Product B</td><td>Product C</td><td>Diluent D</td><td></td>') //header reads A, B, C, D
$('#tr_reactants_products_diluent_header_fuller').html('<td></td><td>Reactant A</td><td>Product B</td><td>Product C</td><td>Diluent D</td><td></td>') //header reads A, B, C, D
$('#tr_reactants_products_diluent_header_lebas').html('<td></td><td>Reactant A</td><td>Product B</td><td>Product C</td><td>Diluent D</td><td></td>') //header reads A, B, C, D
$('input.nar').css('max-width','100px'); //change width of input cells
$('#hide_molweight2,#hide_fluidvisc2,#hide_heatcapacity2,#hide_thermalcond2,#hide_molfrac2,#hide_res_gasdens2,#hide_difvol2,#hide_column_dvol2,#hide_column_vb2,#hide_molar_boil_vol2,#hide_liq_density2,#hide_wilke_assoc_phi2,#tbody_limitingreactant').hide('fast'); //hide 2
$('#hide_molweight4,#hide_fluidvisc4,#hide_heatcapacity4,#hide_thermalcond4,#hide_molfrac4,#hide_res_gasdens4,#hide_difvol4,#hide_column_dvol4,#hide_column_vb4,#hide_molar_boil_vol4,#hide_liq_density4,#hide_wilke_assoc_phi4').show('fast'); //show 4
} else if ($('#dr_num_reactants').val() == "Two" && $('#dr_num_products').val() == "Two"){ //OPTION D -- hide NONE, header reads A, B, C, D, E
$('#tr_reactants_products_diluent_header').html('<td></td><td class="MainReact">Main<br>Reactant A</td><td>Reactant B</td><td>Product C</td><td>Product D</td><td>Diluent E</td><td></td>') //header reads A, B, C, D, E
$('#tr_reactants_products_diluent_header_igdens').html('<td></td><td>Reactant A</td><td>Reactant B</td><td>Product C</td><td>Product D</td><td>Diluent E</td><td></td>') //header reads A, B, C, D, E
$('#tr_reactants_products_diluent_header_fuller').html('<td></td><td>Reactant A</td><td>Reactant B</td><td>Product C</td><td>Product D</td><td>Diluent E</td><td></td>') //header reads A, B, C, D, E
$('#tr_reactants_products_diluent_header_lebas').html('<td></td><td>Reactant A</td><td>Reactant B</td><td>Product C</td><td>Product D</td><td>Diluent E</td><td></td>') //header reads A, B, C, D, E
$('input.nar').css('max-width','90px'); //change width of input cells
//show BOTH 2 and 4
$('#hide_molweight2,#hide_molweight4,#hide_fluidvisc2,#hide_fluidvisc4,#hide_heatcapacity2,#hide_heatcapacity4,#hide_thermalcond2,#hide_thermalcond4,#hide_molfrac2,#hide_molfrac4,#hide_res_gasdens2,#hide_res_gasdens4,#hide_difvol2,#hide_difvol4,#hide_column_dvol2,#hide_column_dvol4,#hide_column_vb2,#hide_column_vb4,#hide_molar_boil_vol2,#hide_molar_boil_vol4,#hide_liq_density2,#hide_liq_density4,#hide_wilke_assoc_phi2,#hide_wilke_assoc_phi4,#tbody_limitingreactant').show('fast');
}
});
});
////////////////////////////////////////////////////////////////////////////
//function for hiding/showing liquid vs. gas relevant cells
$(document).ready(function(){
$('#dr_reaction_phase,#populate_inputs').on('change click', function(){
if ($('#dr_reaction_phase').val() == "Gas Phase"){
$('#tbody_gas_dvol').show('fast');
$('#tbody_liquid_vb').hide('fast');
$('#tbody_ideal_gas_dens').show('fast');
$('#tbody_gas_prandtl_test').show('fast');
} else if ($('#dr_reaction_phase').val() == "Liquid Phase"){
$('#tbody_gas_dvol').hide('fast');
$('#tbody_liquid_vb').show('fast');
$('#tbody_ideal_gas_dens').hide('fast');
$('#tbody_gas_prandtl_test').hide('fast');
}
});
});
////////////////////////////////////////////////////////////////////////////
//function for hiding/showing the advanced options section & setting checkbox=unchecked by default
$(document).ready(function(){
$('#ck_override_diffusivity').prop('checked', false); //set checkbox to unchecked by default when the document loads
$('#hide_advanced_input').on('click', function(){
if ($('#ck_override_diffusivity').is(':checked') == true){ //if override is checked do NOT allow the section to be hidden!!
if ($('#tbody_advanced_input').is(':visible') == true) {
//do nothing
} else {
$('#tbody_advanced_input').show();
}
} else if ($('#ck_override_diffusivity').is(':checked') == false){ //if override is UNchecked then it is OK to allow the section to be hidden
if ($('#tbody_advanced_input').is(':hidden') == false) {
$('#tbody_advanced_input').toggle('fast');
} else {
$('#tbody_advanced_input').toggle('fast');
}
}
});
});
////////////////////////////////////////////////////////////////////////////
//manually set name to be the same as id for inputs/textarea/select
$(document).ready(function(){
var $inputs = $('form.insec').find('input'); //get inputs in form
var $inputs2 = $('form.insec2').find('input'); //get inputs in second part of form
var $textarea = $('form.insec').find('textarea'); //get textareas in form
var $dropdowns = $('form.insec').find('select'); //get dropdown/select in form
///////////////////////////////////////
//NOTE: VERY IMPORTANT!, if one wants to save inputs to the JSON file
//the name attribute MUST be set for anything to be captured by the
//later command 'serializeArray', the following code in this block is
//a hack to set the name to the id tag
///////////////////////////////////////
$inputs.each(function (){ //set the name to id for inputs
this.name = this.id;
});
$inputs2.each(function (){
this.name = this.id;
});
$textarea.each(function (){
this.name = this.id;
});
$dropdowns.each(function (){
this.name = this.id;
});
});
////////////////////////////////////////////////////////////////////////////
//function for saving current input values to a JSON file for later use
$(document).ready(function(){
$("#save_inputs_section_as_JSON").on('click', function (){
var str = $('form.insec').serializeArray(); //find inputs within class=insec form
var str2 = $('form.insec2').serializeArrayWithCheckboxes(); //find inputs within class=insec2 form INCLUDING CHECKBOXES w/ custom function
var strCombined = str.concat(str2); //append insec2 to insec serialized form
var strjson = JSON.stringify(strCombined, null, '\t'); //convert to string JSON format for saving
var filename = $("#JSON_filename").val(); //get user input for filename, defaulted to 'catalysis'
var suffix = ".json"; //add json suffix
var output = document.querySelector('a#save_inputs_section_as_JSON'); //NOT compatible with IE11
output.href = 'data:text/plain;charset=utf-8,' + encodeURIComponent(strjson);
output.download = filename + suffix;
});
});
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////// Begin section for actually inputting and calculating things ////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
//define scope object that will be used to store unrounded values
var catscope = {};
$(document).ready(function(){
$(document).ready(function(){
$(".initialize").trigger("change");
});
//////////////////////////////////////////////////////////////////////////////////
// Function to add all of the inputs section into the "catscope" object for later use
$("#temp,.initialize,#button_fuller_dvol_calculate").on('keyup keydown change click', function (){
//inputs
var dr_reaction_phase = $("#dr_reaction_phase").val();
var temp = $("#temp").val().toNum(); //kelvin
var pressure = $("#pressure").val().toNum();//bar
var R_rctr = $("#R_rctr").val().toNum();
var L_bed = $("#L_bed").val().toNum();
var R_p = $("#R_p").val().toNum();
var R_p_inner = $("#R_p_inner").val().toNum();
var L_p = $("#L_p").val().toNum();
var rxn_rate = $("#rxn_rate").val().toNum();
var rxn_enthalpy = $("#rxn_enthalpy").val().toNum();
var dr_rxn_order = $("#dr_rxn_order").val().toNum(); //toNum for reaction order
var rxn_activation_energy = $("#rxn_activation_energy").val().toNum();
var rxn_conversion1 = $("#rxn_conversion1").val().toNum();
var cat_rho_bulk = $("#cat_rho_bulk").val().toNum();
var cat_void_frac = $("#cat_void_frac").val().toNum();
var cat_thermal_cond = $("#cat_thermal_cond").val().toNum();
var cat_surf_area = $("#cat_surf_area").val().toNum();
var cat_pore_volume = $("#cat_pore_volume").val().toNum();
var cat_pore_tortuosity = $("#cat_pore_tortuosity").val().toNum();
var dr_cat_shape = $("#dr_cat_shape").val();
var molfrac1 = $("#molfrac1").val().toNum();
var molfrac2 = $("#molfrac2").val().toNum();
var molfrac3 = $("#molfrac3").val().toNum();
var molfrac4 = $("#molfrac4").val().toNum();
var molfrac5 = $("#molfrac5").val().toNum();
var fluidvisc1 = $("#fluidvisc1").val().toNum();
var fluidvisc2 = $("#fluidvisc2").val().toNum();
var fluidvisc3 = $("#fluidvisc3").val().toNum();
var fluidvisc4 = $("#fluidvisc4").val().toNum();
var fluidvisc5 = $("#fluidvisc5").val().toNum();
var heatcapacity1 = $("#heatcapacity1").val().toNum();
var heatcapacity2 = $("#heatcapacity2").val().toNum();
var heatcapacity3 = $("#heatcapacity3").val().toNum();
var heatcapacity4 = $("#heatcapacity4").val().toNum();
var heatcapacity5 = $("#heatcapacity5").val().toNum();
var thermalcond1 = $("#thermalcond1").val().toNum();
var thermalcond2 = $("#thermalcond2").val().toNum();
var thermalcond3 = $("#thermalcond3").val().toNum();
var thermalcond4 = $("#thermalcond4").val().toNum();
var thermalcond5 = $("#thermalcond5").val().toNum();
var molweight1 = $("#molweight1").val().toNum();
var molweight2 = $("#molweight2").val().toNum();
var molweight3 = $("#molweight3").val().toNum();
var molweight4 = $("#molweight4").val().toNum();
var molweight5 = $("#molweight5").val().toNum();
//GAS specific
var difvol1 = $("#difvol1").val().toNum();
var difvol2 = $("#difvol2").val().toNum();
var difvol3 = $("#difvol3").val().toNum();
var difvol4 = $("#difvol4").val().toNum();
var difvol5 = $("#difvol5").val().toNum();
//LIQUID specific
var liq_density1 = $("#liq_density1").val().toNum();
var liq_density2 = $("#liq_density2").val().toNum();
var liq_density3 = $("#liq_density3").val().toNum();
var liq_density4 = $("#liq_density4").val().toNum();
var liq_density5 = $("#liq_density5").val().toNum();
var molar_boil_vol1 = $("#molar_boil_vol1").val().toNum();
var molar_boil_vol2 = $("#molar_boil_vol2").val().toNum();
var molar_boil_vol3 = $("#molar_boil_vol3").val().toNum();
var molar_boil_vol4 = $("#molar_boil_vol4").val().toNum();
var molar_boil_vol5 = $("#molar_boil_vol5").val().toNum();
var wilke_assoc_phi2 = $("#wilke_assoc_phi2").val().toNum();
var wilke_assoc_phi3 = $("#wilke_assoc_phi3").val().toNum();
var wilke_assoc_phi4 = $("#wilke_assoc_phi4").val().toNum();
var wilke_assoc_phi5 = $("#wilke_assoc_phi5").val().toNum();
//effective diffusivity checkbox & override value
var ck_override_diffusivity = $("#ck_override_diffusivity").is(':checked');
var diff_effective_override = $("#diff_effective_override").val().toNum();
//look for lack of entries and replace with zero if empty
if ($('#molfrac1').val().length == 0){molfrac1 = 0;} //if there is no molfrac entry assume it is zero
if ($('#molfrac2').val().length == 0){molfrac2 = 0;}
if ($('#molfrac3').val().length == 0){molfrac3 = 0;}
if ($('#molfrac4').val().length == 0){molfrac4 = 0;}
if ($('#molfrac5').val().length == 0){molfrac5 = 0;}
if ($('#fluidvisc1').val().length == 0){fluidvisc1 = 0;}
if ($('#fluidvisc2').val().length == 0){fluidvisc2 = 0;}
if ($('#fluidvisc3').val().length == 0){fluidvisc3 = 0;}
if ($('#fluidvisc4').val().length == 0){fluidvisc4 = 0;}
if ($('#fluidvisc5').val().length == 0){fluidvisc5 = 0;}
if ($('#heatcapacity1').val().length == 0){heatcapacity1 = 0;}
if ($('#heatcapacity2').val().length == 0){heatcapacity2 = 0;}
if ($('#heatcapacity3').val().length == 0){heatcapacity3 = 0;}
if ($('#heatcapacity4').val().length == 0){heatcapacity4 = 0;}
if ($('#heatcapacity5').val().length == 0){heatcapacity5 = 0;}
if ($('#thermalcond1').val().length == 0){thermalcond1 = 0;}
if ($('#thermalcond2').val().length == 0){thermalcond2 = 0;}
if ($('#thermalcond3').val().length == 0){thermalcond3 = 0;}
if ($('#thermalcond4').val().length == 0){thermalcond4 = 0;}
if ($('#thermalcond5').val().length == 0){thermalcond5 = 0;}
if ($('#molweight1').val().length == 0){molweight1 = 0;} //if there is no molweight entry assume it is zero
if ($('#molweight2').val().length == 0){molweight2 = 0;}
if ($('#molweight3').val().length == 0){molweight3 = 0;}
if ($('#molweight4').val().length == 0){molweight4 = 0;}
if ($('#molweight5').val().length == 0){molweight5 = 0;}
//add variables to the catscope
catscope.dr_reaction_phase = dr_reaction_phase;
catscope.temp = temp;
catscope.pressure = pressure;
catscope.R_rctr = R_rctr;
catscope.L_bed = L_bed;
catscope.R_p = R_p; //particle length
catscope.R_p_inner = R_p_inner; //inner particle radius (for rings)
catscope.L_p = L_p; //particle length for rings and cylinders
catscope.rxn_rate = rxn_rate;
catscope.rxn_enthalpy = rxn_enthalpy;
catscope.dr_rxn_order = dr_rxn_order;
catscope.rxn_activation_energy = rxn_activation_energy;
catscope.rxn_conversion1 = rxn_conversion1;
catscope.cat_rho_bulk = cat_rho_bulk;
catscope.cat_void_frac = cat_void_frac;
catscope.cat_thermal_cond = cat_thermal_cond;
catscope.cat_surf_area = cat_surf_area;
catscope.cat_pore_volume = cat_pore_volume;
catscope.cat_pore_tortuosity = cat_pore_tortuosity;
catscope.dr_cat_shape = dr_cat_shape;
catscope.molfrac1 = molfrac1;
catscope.molfrac2 = molfrac2;
catscope.molfrac3 = molfrac3;
catscope.molfrac4 = molfrac4;
catscope.molfrac5 = molfrac5;
catscope.fluidvisc1 = fluidvisc1;
catscope.fluidvisc2 = fluidvisc2;
catscope.fluidvisc3 = fluidvisc3;
catscope.fluidvisc4 = fluidvisc4;
catscope.fluidvisc5 = fluidvisc5;
catscope.heatcapacity1 = heatcapacity1;
catscope.heatcapacity2 = heatcapacity2;
catscope.heatcapacity3 = heatcapacity3;
catscope.heatcapacity4 = heatcapacity4;
catscope.heatcapacity5 = heatcapacity5;
catscope.thermalcond1 = thermalcond1;
catscope.thermalcond2 = thermalcond2;
catscope.thermalcond3 = thermalcond3;
catscope.thermalcond4 = thermalcond4;
catscope.thermalcond5 = thermalcond5;
catscope.molweight1 = molweight1;
catscope.molweight2 = molweight2;
catscope.molweight3 = molweight3;
catscope.molweight4 = molweight4;
catscope.molweight5 = molweight5;
//GAS specific
catscope.difvol1 = difvol1;
catscope.difvol2 = difvol2;
catscope.difvol3 = difvol3;
catscope.difvol4 = difvol4;
catscope.difvol5 = difvol5;
//LIQUID specific
catscope.liq_density1 = liq_density1;
catscope.liq_density2 = liq_density2;
catscope.liq_density3 = liq_density3;
catscope.liq_density4 = liq_density4;
catscope.liq_density5 = liq_density5;
catscope.molar_boil_vol1 = molar_boil_vol1;
catscope.molar_boil_vol2 = molar_boil_vol2;
catscope.molar_boil_vol3 = molar_boil_vol3;
catscope.molar_boil_vol4 = molar_boil_vol4;
catscope.molar_boil_vol5 = molar_boil_vol5;
catscope.wilke_assoc_phi2 = wilke_assoc_phi2; //no value for A=1
catscope.wilke_assoc_phi3 = wilke_assoc_phi3;
catscope.wilke_assoc_phi4 = wilke_assoc_phi4;
catscope.wilke_assoc_phi5 = wilke_assoc_phi5;
//effective diffusivity checkbox & override value
catscope.ck_override_diffusivity = ck_override_diffusivity; //checkbox for override diffusivity
catscope.diff_effective_override = diff_effective_override; //actual value to be used later as effective diffusivity via user input
//do some conversion to SI for non-SI inputs
catscope.cat_pore_volume_SI = math.eval('cat_pore_volume*1000',catscope);
//predefine some catscope arrays
catscope.molWeightArray = [catscope.molweight1, catscope.molweight2, catscope.molweight3, catscope.molweight4, catscope.molweight5]; //g per mol
catscope.molFracArray = [catscope.molfrac1, catscope.molfrac2, catscope.molfrac3, catscope.molfrac4, catscope.molfrac5];
catscope.diffusion_volume_Array = [catscope.difvol1,catscope.difvol2,catscope.difvol3,catscope.difvol4,catscope.difvol5];
catscope.liqDensityArray = [catscope.liq_density1,catscope.liq_density2,catscope.liq_density3,catscope.liq_density4,catscope.liq_density5]; //kg per m^3
});
//////////////////////////////////////////////////////////////////////////////////
// Function to add all of the outputs section into the "catscope" object for later use
$(".initialize,#temp").on('keyup keydown change', function (){
catscope.res_gasdens1 = 0;
catscope.res_gasdens2 = 0;
catscope.res_gasdens3 = 0;
catscope.res_gasdens4 = 0;
catscope.res_gasdens5 = 0;
catscope.res_bulkconc1 = 0;
catscope.limiting_reactant_check = 0;
catscope.rxn_avg_bulk_concentration1 = 0;//not an output
catscope.mass_flowrate = 0;
catscope.molar_flowrate1 = 0; //not an output
catscope.volumetric_flowrate = 0; //not an output
catscope.mass_catalyst = 0;
catscope.bed_volume = 0;
catscope.cat_porosity = 0;
catscope.cat_rho_particle = 0;
catscope.cat_pore_radius = 0;
catscope.cat_particle_vol = 0;
catscope.cat_ext_area = 0;
catscope.cat_interfacial_area = 0;
catscope.avg_mw = 0;
catscope.avg_cp = 0;
catscope.avg_k_conduct = 0;
catscope.avg_viscosity = 0;
catscope.avg_density = 0;
catscope.diff_mixture = 0;
catscope.superf_mass_flux = 0;
catscope.ndim_reynolds = 0;
catscope.ndim_prandtl = 0;
catscope.ndim_schmidt = 0;
catscope.ndim_colburn = 0;
catscope.ndim_massXfer_coeff = 0;
catscope.ndim_sherwood = 0;
catscope.ndim_heatXfer_coeff = 0;
catscope.ndim_nusselt = 0;
catscope.diff_knudsen = 0;
catscope.diff_effective = 0;
catscope.rxn_weisz_prater = 0;
catscope.rxn_weisz_prater_inlet = 0;
catscope.rxn_weisz_prater_outlet = 0;
catscope.rxn_thiele = 0;
catscope.rxn_thiele_inlet = 0;
catscope.rxn_thiele_outlet = 0;
catscope.rxn_eff_factor = 0;
catscope.rxn_eff_factor_inlet = 0;
catscope.rxn_eff_factor_outlet = 0;
catscope.rxn_externalconc_grad = 0;
catscope.rxn_externaltemp_grad = 0;
catscope.rxn_internaltemp_grad = 0;
catscope.ndim_prater = 0;
catscope.rxn_intrinsic_rconst = 0;
catscope.rxn_maxlimitingrate = 0;
catscope.rxn_surfconcentration = 0;
catscope.rxn_surftemperature = 0;
catscope.axial_disp_coeff = 0;
catscope.ndim_peclet = 0;
catscope.ndim_bodenstein = 0;
catscope.bed_pressure_drop = 0;
catscope.ndim_BL_thickness = 0;
catscope.cat_effective_radius_volequiv = 0; //not an output
catscope.cat_effective_radius_ergun = 0; //not an output
catscope.cat_effective_radius = 0; //not an output
catscope.ndim_biot_solid = 0;//not an output
});
//////////////////////////////////////////////////////////////////////////////////
// Function to get the inputs to the Fuller method popup into catscope
$(".initialize,#temp,#pressure").on('keyup keydown change click', function (){
var fuller_C1 = $("#fuller_C1").val().toNum();
var fuller_H1 = $("#fuller_H1").val().toNum();
var fuller_O1 = $("#fuller_O1").val().toNum();
var fuller_N1 = $("#fuller_N1").val().toNum();
var fuller_S1 = $("#fuller_S1").val().toNum();
var fuller_F1 = $("#fuller_F1").val().toNum();
var fuller_Cl1 = $("#fuller_Cl1").val().toNum();
var fuller_Br1 = $("#fuller_Br1").val().toNum();
var fuller_I1 = $("#fuller_I1").val().toNum();
var fuller_ar1 = $("#fuller_ar1").val().toNum();
var fuller_het1 = $("#fuller_het1").val().toNum();
var fuller_C2 = $("#fuller_C2").val().toNum();
var fuller_H2 = $("#fuller_H2").val().toNum();
var fuller_O2 = $("#fuller_O2").val().toNum();
var fuller_N2 = $("#fuller_N2").val().toNum();
var fuller_S2 = $("#fuller_S2").val().toNum();
var fuller_F2 = $("#fuller_F2").val().toNum();
var fuller_Cl2 = $("#fuller_Cl2").val().toNum();
var fuller_Br2 = $("#fuller_Br2").val().toNum();
var fuller_I2 = $("#fuller_I2").val().toNum();
var fuller_ar2 = $("#fuller_ar2").val().toNum();
var fuller_het2 = $("#fuller_het2").val().toNum();
var fuller_C3 = $("#fuller_C3").val().toNum();
var fuller_H3 = $("#fuller_H3").val().toNum();
var fuller_O3 = $("#fuller_O3").val().toNum();
var fuller_N3 = $("#fuller_N3").val().toNum();
var fuller_S3 = $("#fuller_S3").val().toNum();
var fuller_F3 = $("#fuller_F3").val().toNum();
var fuller_Cl3 = $("#fuller_Cl3").val().toNum();
var fuller_Br3 = $("#fuller_Br3").val().toNum();
var fuller_I3 = $("#fuller_I3").val().toNum();
var fuller_ar3 = $("#fuller_ar3").val().toNum();
var fuller_het3 = $("#fuller_het3").val().toNum();
var fuller_C4 = $("#fuller_C4").val().toNum();
var fuller_H4 = $("#fuller_H4").val().toNum();
var fuller_O4 = $("#fuller_O4").val().toNum();
var fuller_N4 = $("#fuller_N4").val().toNum();
var fuller_S4 = $("#fuller_S4").val().toNum();
var fuller_F4 = $("#fuller_F4").val().toNum();
var fuller_Cl4 = $("#fuller_Cl4").val().toNum();
var fuller_Br4 = $("#fuller_Br4").val().toNum();
var fuller_I4 = $("#fuller_I4").val().toNum();
var fuller_ar4 = $("#fuller_ar4").val().toNum();
var fuller_het4 = $("#fuller_het4").val().toNum();
var fuller_C5 = $("#fuller_C5").val().toNum();
var fuller_H5 = $("#fuller_H5").val().toNum();
var fuller_O5 = $("#fuller_O5").val().toNum();
var fuller_N5 = $("#fuller_N5").val().toNum();
var fuller_S5 = $("#fuller_S5").val().toNum();
var fuller_F5 = $("#fuller_F5").val().toNum();
var fuller_Cl5 = $("#fuller_Cl5").val().toNum();
var fuller_Br5 = $("#fuller_Br5").val().toNum();
var fuller_I5 = $("#fuller_I5").val().toNum();
var fuller_ar5 = $("#fuller_ar5").val().toNum();
var fuller_het5 = $("#fuller_het5").val().toNum();
var dr_molname_dvol1 = $("#dr_molname_dvol1 option:selected").attr("name");
var dr_molname_dvol2 = $("#dr_molname_dvol2 option:selected").attr("name");
var dr_molname_dvol3 = $("#dr_molname_dvol3 option:selected").attr("name");
var dr_molname_dvol4 = $("#dr_molname_dvol4 option:selected").attr("name");
var dr_molname_dvol5 = $("#dr_molname_dvol5 option:selected").attr("name");
var fuller_Array1 = [fuller_C1,fuller_H1,fuller_O1,fuller_N1,fuller_S1,fuller_F1,fuller_Cl1,fuller_Br1,fuller_I1,fuller_ar1,fuller_het1];
var fuller_Array2 = [fuller_C2,fuller_H2,fuller_O2,fuller_N2,fuller_S2,fuller_F2,fuller_Cl2,fuller_Br2,fuller_I2,fuller_ar2,fuller_het2];
var fuller_Array3 = [fuller_C3,fuller_H3,fuller_O3,fuller_N3,fuller_S3,fuller_F3,fuller_Cl3,fuller_Br3,fuller_I3,fuller_ar3,fuller_het3];
var fuller_Array4 = [fuller_C4,fuller_H4,fuller_O4,fuller_N4,fuller_S4,fuller_F4,fuller_Cl4,fuller_Br4,fuller_I4,fuller_ar4,fuller_het4];
var fuller_Array5 = [fuller_C5,fuller_H5,fuller_O5,fuller_N5,fuller_S5,fuller_F5,fuller_Cl5,fuller_Br5,fuller_I5,fuller_ar5,fuller_het5];
var dr_molname_Array = [dr_molname_dvol1,dr_molname_dvol2,dr_molname_dvol3,dr_molname_dvol4,dr_molname_dvol5];
fuller_Array1 = replaceNaN(fuller_Array1);
fuller_Array2 = replaceNaN(fuller_Array2);
fuller_Array3 = replaceNaN(fuller_Array3);
fuller_Array4 = replaceNaN(fuller_Array4);
fuller_Array5 = replaceNaN(fuller_Array5);
var fuller_Array1_mw = fuller_Array1.slice(0,-2);
var fuller_Array2_mw = fuller_Array2.slice(0,-2);
var fuller_Array3_mw = fuller_Array3.slice(0,-2);
var fuller_Array4_mw = fuller_Array4.slice(0,-2);
var fuller_Array5_mw = fuller_Array5.slice(0,-2);
//add newly created arrays into the catscope object for later use
catscope.fuller_Array1 = fuller_Array1;
catscope.fuller_Array2 = fuller_Array2;
catscope.fuller_Array3 = fuller_Array3;
catscope.fuller_Array4 = fuller_Array4;
catscope.fuller_Array5 = fuller_Array5;
catscope.fuller_Array1_mw = fuller_Array1_mw;
catscope.fuller_Array2_mw = fuller_Array2_mw;
catscope.fuller_Array3_mw = fuller_Array3_mw;
catscope.fuller_Array4_mw = fuller_Array4_mw;
catscope.fuller_Array5_mw = fuller_Array5_mw;
catscope.dr_molname_dvol1 = dr_molname_dvol1;
catscope.dr_molname_dvol2 = dr_molname_dvol2;
catscope.dr_molname_dvol3 = dr_molname_dvol3;
catscope.dr_molname_dvol4 = dr_molname_dvol4;
catscope.dr_molname_dvol5 = dr_molname_dvol5;
catscope.dr_molname_Array = dr_molname_Array;
});
//////////////////////////////////////////////////////////////////////////////////
//fuller diffusion volumes, MW, and molecular formulas for all five possible components
$("#temp,#pressure").on('keyup keydown change click', function (){
//first check if the gas field is selected
if (catscope.dr_reaction_phase == "Gas Phase") {
//id string of output field
var outputdvolNames = ["#difvol1","#difvol2","#difvol3","#difvol4","#difvol5"];
var outputdvolNames_popup = ["#fuller_dvol1","#fuller_dvol2","#fuller_dvol3","#fuller_dvol4","#fuller_dvol5"];
var outputMWNames = ["#molweight1","#molweight2","#molweight3","#molweight4","#molweight5"];
var outputMWNames_popup = ["#fuller_molweight1","#fuller_molweight2","#fuller_molweight3","#fuller_molweight4","#fuller_molweight5"];
var outputformulaNames= ["#fuller_molformula1","#fuller_molformula2","#fuller_molformula3","#fuller_molformula4","#fuller_molformula5"];
var MW_array = [12.011, 1.008, 15.999, 14.007, 32.066, 18.998, 35.453, 79.904, 126.905];
var dvol_array = [15.9, 2.3, 6.1, 4.5, 22.9, 14.7, 21.0, 21.9, 29.8, -18.3, -18.3];
catscope.MW_array = MW_array;
catscope.dvol_array = dvol_array;
// in the first section various properties are calculated for all components
// REGARDLESS of "Custom" vs. non-Custom selection in dr_molname_ selection
//perform calculation
var fuller_molweight1 = math.eval('fuller_Array1_mw*transpose(MW_array)',catscope); //calculate molecular weight of "1" by multiplying against MW_array^T
var fuller_molweight2 = math.eval('fuller_Array2_mw*transpose(MW_array)',catscope);
var fuller_molweight3 = math.eval('fuller_Array3_mw*transpose(MW_array)',catscope);
var fuller_molweight4 = math.eval('fuller_Array4_mw*transpose(MW_array)',catscope);
var fuller_molweight5 = math.eval('fuller_Array5_mw*transpose(MW_array)',catscope);
var fuller_molformula1 = fullerArrayToFormula(catscope.fuller_Array1_mw); //convert array of numbers into formula string
var fuller_molformula2 = fullerArrayToFormula(catscope.fuller_Array2_mw);
var fuller_molformula3 = fullerArrayToFormula(catscope.fuller_Array3_mw);
var fuller_molformula4 = fullerArrayToFormula(catscope.fuller_Array4_mw);
var fuller_molformula5 = fullerArrayToFormula(catscope.fuller_Array5_mw);
var fuller_dvol1 = math.eval('fuller_Array1*transpose(dvol_array)',catscope);
var fuller_dvol2 = math.eval('fuller_Array2*transpose(dvol_array)',catscope);
var fuller_dvol3 = math.eval('fuller_Array3*transpose(dvol_array)',catscope);
var fuller_dvol4 = math.eval('fuller_Array4*transpose(dvol_array)',catscope);
var fuller_dvol5 = math.eval('fuller_Array5*transpose(dvol_array)',catscope);
var fuller_molweight_Array = [fuller_molweight1,fuller_molweight2,fuller_molweight3,fuller_molweight4,fuller_molweight5];
var fuller_dvol_Array = [fuller_dvol1,fuller_dvol2,fuller_dvol3,fuller_dvol4,fuller_dvol5];
var fuller_molformula_Array = [fuller_molformula1,fuller_molformula2,fuller_molformula3,fuller_molformula4,fuller_molformula5];
//add result to scope
catscope.fuller_molweight1 = fuller_molweight1;
catscope.fuller_molweight2 = fuller_molweight2;
catscope.fuller_molweight3 = fuller_molweight3;
catscope.fuller_molweight4 = fuller_molweight4;
catscope.fuller_molweight5 = fuller_molweight5;
catscope.fuller_molweight_Array = fuller_molweight_Array;
catscope.fuller_dvol_Array = fuller_dvol_Array;
catscope.fuller_molformula_Array = fuller_molformula_Array;
//define some arrays
var predefdvolArray = [18.5,16.3,19.7,13.1,18.0,26.9,6.1,2.7,16.2,35.9,20.7,38.4,69.0,41.8];
var predefdvolNamesArray = ["N2","O2","Air","H2O","CO","CO2","H2","He","Ar","N2O","NH3","Cl2","Br2","SO2"];
var predefdvolMWArray = [28.014,31.998,28.966,18.016,28.01,44.009,2.016,4.0026,39.948,44.013,17.031,70.906,159.808,64.064];
//use alternate method for dr_molname
$.each(catscope.dr_molname_Array, function(index,value){
var j = predefdvolNamesArray.indexOf(value);
if (!predefdvolNamesArray[j]) { //check if the value is NOT in the Array, specifically for "Custom" molecules
writeOut(outputformulaNames[index],fuller_molformula_Array[index])
if (fuller_molweight_Array[index] != 0 && fuller_dvol_Array[index] != 0) { //ONLY write the values if they are NOT zero
writeOut(outputMWNames[index],fuller_molweight_Array[index])
writeOut(outputMWNames_popup[index],fuller_molweight_Array[index])
writeOut(outputdvolNames[index],fuller_dvol_Array[index])
writeOut(outputdvolNames_popup[index],fuller_dvol_Array[index])
}
} else { //else the value is in the array, then use predefined mol weights / formulas / and diffusion volumes
writeOut(outputformulaNames[index],predefdvolNamesArray[j])
writeOut(outputMWNames[index],predefdvolMWArray[j])
writeOut(outputMWNames_popup[index],predefdvolMWArray[j])
writeOut(outputdvolNames[index],predefdvolArray[j])
writeOut(outputdvolNames_popup[index],predefdvolArray[j])
catscope.fuller_molweight_Array[index] = predefdvolMWArray[j];
catscope.fuller_dvol_Array[index] = predefdvolArray[j];
}
});
// at this point the relevant mol weights / formulas / and diffusion volumes have actually been written to the user interface cell
// since we need to use the actual values later -- it would be best to read them back into the catscope object for later use
for (i in catscope.molWeightArray) {
if (catscope.fuller_molweight_Array[i] > 0) {
catscope.molWeightArray[i] = catscope.fuller_molweight_Array[i];
} else {
//do nothing
}
}
for (i in catscope.diffusion_volume_Array) {
if (catscope.fuller_dvol_Array[i] > 0) {
catscope.diffusion_volume_Array[i] = catscope.fuller_dvol_Array[i];//there can be zeros here, which is checked and corrected for later
} else {
//do nothing
}
}
}
});
//////////////////////////////////////////////////////////////////////////////////
//calculate binary diffusivities for all 4 possible A dominant pairs (1-2,1-3,1-4,1-5) and mixture diffusivity for GAS and LIQUID
$("#temp,#pressure").on('keyup keydown change click', function (){
var molTest = doesItSumToOne(catscope.molFracArray); //currently uses >= 0.995 = 1
catscope.molTest = molTest;
//then check if the gas field is selected
if (catscope.dr_reaction_phase == "Gas Phase") {
//id string of output field
var diff_mixture_out = "#diff_mixture"; //output in m^2/s
catscope.binary_diff_Array = [];
for (var i = 1; i <= 4; i++) {
var j = i - 1;
catscope.binary_diff_Array[j] = fullerBinaryDiff(catscope.molWeightArray[0],catscope.molWeightArray[i],catscope.temp,catscope.pressure,catscope.diffusion_volume_Array[0],catscope.diffusion_volume_Array[i]);
}
catscope.binary_diff_Array_noInf = $.extend( true, [], catscope.binary_diff_Array);
var removeInfIndices = findInfIndices(catscope.binary_diff_Array_noInf);
catscope.molFracArray_no_A_no_Inf = $.extend( true, [], catscope.molFracArray); //first duplicate array -- special syntax breaks inheritance problems
catscope.molFracArray_no_A_no_Inf.shift(); // then delete first element by using shift
for (i in removeInfIndices) {
var j = removeInfIndices[i] - i;
catscope.binary_diff_Array_noInf.splice(j,1); //remove elements with diffusion of Infinity -- indicating no input for molecule information
catscope.molFracArray_no_A_no_Inf.splice(j,1); //remove corresponding elements of molFracArray
}
catscope.self_diff_coeffA = fullerBinaryDiff(catscope.molWeightArray[0],catscope.molWeightArray[0],catscope.temp,catscope.pressure,catscope.diffusion_volume_Array[0],catscope.diffusion_volume_Array[0]);
if (catscope.molTest == true) { //logical test for if mol fractions add to one
var numerator = math.eval('1-molfrac1',catscope);
var denominator = math.eval('sum(molFracArray_no_A_no_Inf./binary_diff_Array_noInf)',catscope); //perform elementwise division, then sum elements of array
var diff_mixture = math.divide(numerator,denominator);
if (catscope.molfrac1 == 1) {
catscope.diff_mixture = catscope.self_diff_coeffA;
writeOut(diff_mixture_out,catscope.self_diff_coeffA); //using a self diffusion coefficient
} else {
catscope.diff_mixture = diff_mixture;
writeOut(diff_mixture_out,diff_mixture);
}
} else {
writeOut(diff_mixture_out,'Sum of Mol Frac. not 1');
}
}
//separate code for liquid phase mixture diffusivity is later
});
//////////////////////////////////////////////////////////////////////////////////
//get Le Bas parameters to calculate molar volumes / mol. weight / formula for liquids
$("#button_lebas_vb_calculate,#temp").on('keyup keydown change click', function (){
if(catscope.dr_reaction_phase == "Liquid Phase") { //check if the selected phase is correct to perform these calculations
var lebas_C1 = $("#lebas_C1").val().toNum(); //get Le Bas method values for liquid molar volume calculation
var lebas_H1 = $("#lebas_H1").val().toNum();
var lebas_O1 = $("#lebas_O1").val().toNum();
var lebas_MeEs_O1 = $("#lebas_MeEs_O1").val().toNum();
var lebas_EtEs_O1 = $("#lebas_EtEs_O1").val().toNum();
var lebas_HiEs_O1 = $("#lebas_HiEs_O1").val().toNum();
var lebas_Ac_O1 = $("#lebas_Ac_O1").val().toNum();
var lebas_tospn_O1 = $("#lebas_tospn_O1").val().toNum();
var lebas_dbl_N1 = $("#lebas_dbl_N1").val().toNum();
var lebas_pri_N1 = $("#lebas_pri_N1").val().toNum();
var lebas_sec_N1 = $("#lebas_sec_N1").val().toNum();
var lebas_Br1 = $("#lebas_Br1").val().toNum();
var lebas_Cl1 = $("#lebas_Cl1").val().toNum();
var lebas_F1 = $("#lebas_F1").val().toNum();
var lebas_I1 = $("#lebas_I1").val().toNum();
var lebas_S1 = $("#lebas_S1").val().toNum();
var lebas_ringThr1 = $("#lebas_ringThr1").val().toNum();
var lebas_ringFo1 = $("#lebas_ringFo1").val().toNum();
var lebas_ringFi1 = $("#lebas_ringFi1").val().toNum();
var lebas_ringSi1 = $("#lebas_ringSi1").val().toNum();
var lebas_nphth1 = $("#lebas_nphth1").val().toNum();
var lebas_anthr1 = $("#lebas_anthr1").val().toNum();
var lebas_C2 = $("#lebas_C2").val().toNum(); //molecule 2
var lebas_H2 = $("#lebas_H2").val().toNum();
var lebas_O2 = $("#lebas_O2").val().toNum();
var lebas_MeEs_O2 = $("#lebas_MeEs_O2").val().toNum();
var lebas_EtEs_O2 = $("#lebas_EtEs_O2").val().toNum();
var lebas_HiEs_O2 = $("#lebas_HiEs_O2").val().toNum();
var lebas_Ac_O2 = $("#lebas_Ac_O2").val().toNum();
var lebas_tospn_O2 = $("#lebas_tospn_O2").val().toNum();
var lebas_dbl_N2 = $("#lebas_dbl_N2").val().toNum();
var lebas_pri_N2 = $("#lebas_pri_N2").val().toNum();
var lebas_sec_N2 = $("#lebas_sec_N2").val().toNum();
var lebas_Br2 = $("#lebas_Br2").val().toNum();
var lebas_Cl2 = $("#lebas_Cl2").val().toNum();
var lebas_F2 = $("#lebas_F2").val().toNum();
var lebas_I2 = $("#lebas_I2").val().toNum();
var lebas_S2 = $("#lebas_S2").val().toNum();
var lebas_ringThr2 = $("#lebas_ringThr2").val().toNum();
var lebas_ringFo2 = $("#lebas_ringFo2").val().toNum();
var lebas_ringFi2 = $("#lebas_ringFi2").val().toNum();
var lebas_ringSi2 = $("#lebas_ringSi2").val().toNum();
var lebas_nphth2 = $("#lebas_nphth2").val().toNum();
var lebas_anthr2 = $("#lebas_anthr2").val().toNum();
var lebas_C3 = $("#lebas_C3").val().toNum(); //molecule 3
var lebas_H3 = $("#lebas_H3").val().toNum();
var lebas_O3 = $("#lebas_O3").val().toNum();
var lebas_MeEs_O3 = $("#lebas_MeEs_O3").val().toNum();
var lebas_EtEs_O3 = $("#lebas_EtEs_O3").val().toNum();
var lebas_HiEs_O3 = $("#lebas_HiEs_O3").val().toNum();
var lebas_Ac_O3 = $("#lebas_Ac_O3").val().toNum();
var lebas_tospn_O3 = $("#lebas_tospn_O3").val().toNum();
var lebas_dbl_N3 = $("#lebas_dbl_N3").val().toNum();
var lebas_pri_N3 = $("#lebas_pri_N3").val().toNum();
var lebas_sec_N3 = $("#lebas_sec_N3").val().toNum();
var lebas_Br3 = $("#lebas_Br3").val().toNum();
var lebas_Cl3 = $("#lebas_Cl3").val().toNum();
var lebas_F3 = $("#lebas_F3").val().toNum();
var lebas_I3 = $("#lebas_I3").val().toNum();
var lebas_S3 = $("#lebas_S3").val().toNum();
var lebas_ringThr3 = $("#lebas_ringThr3").val().toNum();
var lebas_ringFo3 = $("#lebas_ringFo3").val().toNum();
var lebas_ringFi3 = $("#lebas_ringFi3").val().toNum();
var lebas_ringSi3 = $("#lebas_ringSi3").val().toNum();
var lebas_nphth3 = $("#lebas_nphth3").val().toNum();
var lebas_anthr3 = $("#lebas_anthr3").val().toNum();
var lebas_C4 = $("#lebas_C4").val().toNum(); //molecule 4
var lebas_H4 = $("#lebas_H4").val().toNum();
var lebas_O4 = $("#lebas_O4").val().toNum();
var lebas_MeEs_O4 = $("#lebas_MeEs_O4").val().toNum();
var lebas_EtEs_O4 = $("#lebas_EtEs_O4").val().toNum();
var lebas_HiEs_O4 = $("#lebas_HiEs_O4").val().toNum();
var lebas_Ac_O4 = $("#lebas_Ac_O4").val().toNum();
var lebas_tospn_O4 = $("#lebas_tospn_O4").val().toNum();
var lebas_dbl_N4 = $("#lebas_dbl_N4").val().toNum();
var lebas_pri_N4 = $("#lebas_pri_N4").val().toNum();
var lebas_sec_N4 = $("#lebas_sec_N4").val().toNum();
var lebas_Br4 = $("#lebas_Br4").val().toNum();
var lebas_Cl4 = $("#lebas_Cl4").val().toNum();
var lebas_F4 = $("#lebas_F4").val().toNum();
var lebas_I4 = $("#lebas_I4").val().toNum();
var lebas_S4 = $("#lebas_S4").val().toNum();
var lebas_ringThr4 = $("#lebas_ringThr4").val().toNum();
var lebas_ringFo4 = $("#lebas_ringFo4").val().toNum();
var lebas_ringFi4 = $("#lebas_ringFi4").val().toNum();
var lebas_ringSi4 = $("#lebas_ringSi4").val().toNum();
var lebas_nphth4 = $("#lebas_nphth4").val().toNum();
var lebas_anthr4 = $("#lebas_anthr4").val().toNum();
var lebas_C5 = $("#lebas_C5").val().toNum(); //molecule 5
var lebas_H5 = $("#lebas_H5").val().toNum();
var lebas_O5 = $("#lebas_O5").val().toNum();
var lebas_MeEs_O5 = $("#lebas_MeEs_O5").val().toNum();
var lebas_EtEs_O5 = $("#lebas_EtEs_O5").val().toNum();
var lebas_HiEs_O5 = $("#lebas_HiEs_O5").val().toNum();
var lebas_Ac_O5 = $("#lebas_Ac_O5").val().toNum();
var lebas_tospn_O5 = $("#lebas_tospn_O5").val().toNum();
var lebas_dbl_N5 = $("#lebas_dbl_N5").val().toNum();
var lebas_pri_N5 = $("#lebas_pri_N5").val().toNum();
var lebas_sec_N5 = $("#lebas_sec_N5").val().toNum();
var lebas_Br5 = $("#lebas_Br5").val().toNum();
var lebas_Cl5 = $("#lebas_Cl5").val().toNum();
var lebas_F5 = $("#lebas_F5").val().toNum();
var lebas_I5 = $("#lebas_I5").val().toNum();
var lebas_S5 = $("#lebas_S5").val().toNum();
var lebas_ringThr5 = $("#lebas_ringThr5").val().toNum();
var lebas_ringFo5 = $("#lebas_ringFo5").val().toNum();
var lebas_ringFi5 = $("#lebas_ringFi5").val().toNum();
var lebas_ringSi5 = $("#lebas_ringSi5").val().toNum();
var lebas_nphth5 = $("#lebas_nphth5").val().toNum();
var lebas_anthr5 = $("#lebas_anthr5").val().toNum();
//construct arrays based on above variables for later use in calcualting molar volume, molar weight, and molar formula
var lebas_Array1 = [lebas_C1,lebas_H1,lebas_O1,lebas_MeEs_O1,lebas_EtEs_O1,lebas_HiEs_O1,lebas_Ac_O1,lebas_tospn_O1,lebas_dbl_N1,lebas_pri_N1,lebas_sec_N1,lebas_Br1,lebas_Cl1,lebas_F1,lebas_I1,lebas_S1,lebas_ringThr1,lebas_ringFo1,lebas_ringFi1,lebas_ringSi1,lebas_nphth1,lebas_anthr1];
var lebas_Array2 = [lebas_C2,lebas_H2,lebas_O2,lebas_MeEs_O2,lebas_EtEs_O2,lebas_HiEs_O2,lebas_Ac_O2,lebas_tospn_O2,lebas_dbl_N2,lebas_pri_N2,lebas_sec_N2,lebas_Br2,lebas_Cl2,lebas_F2,lebas_I2,lebas_S2,lebas_ringThr2,lebas_ringFo2,lebas_ringFi2,lebas_ringSi2,lebas_nphth2,lebas_anthr2];
var lebas_Array3 = [lebas_C3,lebas_H3,lebas_O3,lebas_MeEs_O3,lebas_EtEs_O3,lebas_HiEs_O3,lebas_Ac_O3,lebas_tospn_O3,lebas_dbl_N3,lebas_pri_N3,lebas_sec_N3,lebas_Br3,lebas_Cl3,lebas_F3,lebas_I3,lebas_S3,lebas_ringThr3,lebas_ringFo3,lebas_ringFi3,lebas_ringSi3,lebas_nphth3,lebas_anthr3];
var lebas_Array4 = [lebas_C4,lebas_H4,lebas_O4,lebas_MeEs_O4,lebas_EtEs_O4,lebas_HiEs_O4,lebas_Ac_O4,lebas_tospn_O4,lebas_dbl_N4,lebas_pri_N4,lebas_sec_N4,lebas_Br4,lebas_Cl4,lebas_F4,lebas_I4,lebas_S4,lebas_ringThr4,lebas_ringFo4,lebas_ringFi4,lebas_ringSi4,lebas_nphth4,lebas_anthr4];
var lebas_Array5 = [lebas_C5,lebas_H5,lebas_O5,lebas_MeEs_O5,lebas_EtEs_O5,lebas_HiEs_O5,lebas_Ac_O5,lebas_tospn_O5,lebas_dbl_N5,lebas_pri_N5,lebas_sec_N5,lebas_Br5,lebas_Cl5,lebas_F5,lebas_I5,lebas_S5,lebas_ringThr5,lebas_ringFo5,lebas_ringFi5,lebas_ringSi5,lebas_nphth5,lebas_anthr5];
lebas_Array1 = replaceNaN(lebas_Array1);
lebas_Array2 = replaceNaN(lebas_Array2);
lebas_Array3 = replaceNaN(lebas_Array3);
lebas_Array4 = replaceNaN(lebas_Array4);
lebas_Array5 = replaceNaN(lebas_Array5);
var lebas_Array1_mw = lebas_Array1.slice(0,-6); //
var lebas_Array2_mw = lebas_Array2.slice(0,-6);
var lebas_Array3_mw = lebas_Array3.slice(0,-6);
var lebas_Array4_mw = lebas_Array4.slice(0,-6);
var lebas_Array5_mw = lebas_Array5.slice(0,-6);
catscope.lebas_Array1 = lebas_Array1;
catscope.lebas_Array2 = lebas_Array2;
catscope.lebas_Array3 = lebas_Array3;
catscope.lebas_Array4 = lebas_Array4;
catscope.lebas_Array5 = lebas_Array5;
catscope.lebas_Array1_mw = lebas_Array1_mw;
catscope.lebas_Array2_mw = lebas_Array2_mw;
catscope.lebas_Array3_mw = lebas_Array3_mw;
catscope.lebas_Array4_mw = lebas_Array4_mw;
catscope.lebas_Array5_mw = lebas_Array5_mw;
var lebas_MW_array = [12.011,1.008,15.999,15.999,15.999,15.999,15.999,15.999,14.007,14.007,14.007,79.904,35.453,18.998,126.905,32.066]; //has duplicate entries that match with duplicates in array
catscope.lebas_MW_array = lebas_MW_array;
var lebas_molarvb_array = [14.8,3.7,7.4,9.1,9.9,11,12,8.3,15.6,10.5,12,27,24.6,8.7,37,25.6,-6.0,-8.5,-11.5,-15.0,-30.0,-47.5]; //has all entries for all molar volume contributions
catscope.lebas_molarvb_array = lebas_molarvb_array;
var lebas_molweight1 = math.eval('lebas_Array1_mw*transpose(lebas_MW_array)',catscope); //calculate molecular weight of "1" by multiplying against MW_array^T
var lebas_molweight2 = math.eval('lebas_Array2_mw*transpose(lebas_MW_array)',catscope); //units are g/mpl for all of these
var lebas_molweight3 = math.eval('lebas_Array3_mw*transpose(lebas_MW_array)',catscope);
var lebas_molweight4 = math.eval('lebas_Array4_mw*transpose(lebas_MW_array)',catscope);