www/js/rec_edit.js

changeset 158
3b9e4dfb0476
parent 156
35860890224c
child 159
6428dae0605d
equal deleted inserted replaced
157:5b2f553175a6 158:3b9e4dfb0476
329 } 329 }
330 330
331 //Z alkalinity is the amount of acid (in mEq/l) needed to bring water to the target pH (Z pH) 331 //Z alkalinity is the amount of acid (in mEq/l) needed to bring water to the target pH (Z pH)
332 function ZAlkalinity(pHZ) { 332 function ZAlkalinity(pHZ) {
333 var C43 = Charge(4.3); 333 var C43 = Charge(4.3);
334 //var Cw = Charge(parseFloat($("#wg_ph").jqxNumberInput('decimal'))); 334 var Cw = Charge(parseFloat($("#wg_ph").jqxNumberInput('decimal')));
335 var Cw = Charge(7.0);
336 var Cz = Charge(pHZ); 335 var Cz = Charge(pHZ);
337 var DeltaCNaught = -C43+Cw; 336 var DeltaCNaught = -C43+Cw;
338 var CT = parseFloat($("#wg_total_alkalinity").jqxNumberInput('decimal')) / 50 / DeltaCNaught; 337 var CT = parseFloat($("#wg_total_alkalinity").jqxNumberInput('decimal')) / 50 / DeltaCNaught;
339 var DeltaCZ = -Cz+Cw; 338 var DeltaCZ = -Cz+Cw;
340 return CT * DeltaCZ; 339 return CT * DeltaCZ;
553 pK2 = result.pK2; 552 pK2 = result.pK2;
554 pK3 = result.pK3; 553 pK3 = result.pK3;
555 MolWt = result.MolWt; 554 MolWt = result.MolWt;
556 AcidSG = result.AcidSG; 555 AcidSG = result.AcidSG;
557 AcidPrc = result.AcidPrc; 556 AcidPrc = result.AcidPrc;
558 console.log(AT+" pK1: "+pK1+" pK2: "+pK2+" pK3: "+pK3+" MolWt: "+MolWt+" AcidSG: "+AcidSG+" AcidPrc: "+AcidPrc); 557 // console.log(AT+" pK1: "+pK1+" pK2: "+pK2+" pK3: "+pK3+" MolWt: "+MolWt+" AcidSG: "+AcidSG+" AcidPrc: "+AcidPrc);
559 558
560 if (dataRecord.calc_acid) { 559 if (dataRecord.calc_acid) {
561 TpH = parseFloat(dataRecord.mash_ph); 560 TpH = parseFloat(dataRecord.mash_ph);
562 protonDeficit = ProtonDeficit(TpH); 561 protonDeficit = ProtonDeficit(TpH);
563 console.log("calc_acid tgt: "+TpH+" protonDeficit: "+protonDeficit); 562 console.log("calc_acid tgt: "+TpH+" protonDeficit: "+protonDeficit);
710 } 709 }
711 } 710 }
712 } 711 }
713 712
714 TpH = parseFloat(dataRecord.mash_ph); 713 TpH = parseFloat(dataRecord.mash_ph);
715 // pHa = MashpH(); 714 pHa = MashpH(); // This one is in demi water, should be in adjusted water???
716 pHa = parseFloat($("#wb_ph").jqxNumberInput('decimal'));
717 // Then calculate the new pH with added acids 715 // Then calculate the new pH with added acids
718 if (parseFloat($("#wa_acid").jqxNumberInput('decimal')) > 0) { 716 if (parseFloat($("#wa_acid").jqxNumberInput('decimal')) > 0) {
719 console.log("TpH: "+TpH+" water: "+pHa); 717 console.log("TpH: "+TpH+" water: "+pHa);
720 Acid = parseFloat($("#wa_acid").jqxNumberInput('decimal')); 718 Acid = parseFloat($("#wa_acid").jqxNumberInput('decimal'));
721 if (parseFloat($("#wa_acid_perc").jqxNumberInput('decimal')) == 0) 719 if (parseFloat($("#wa_acid_perc").jqxNumberInput('decimal')) == 0)
722 $("#wa_acid_perc").val(AcidPrc); 720 $("#wa_acid_perc").val(AcidPrc);
723 Acid = Acid / AcidPrc * (parseFloat($("#wa_acid_perc").jqxNumberInput('decimal')) / 100); // ml 721 Acid = Acid / AcidPrc * (parseFloat($("#wa_acid_perc").jqxNumberInput('decimal')) / 100); // ml
724 Acid = Acid * AcidSG; // ml 722 Acid *= AcidSG; // ml
725 Acid = Acid / MolWt; // mg 723 Acid /= MolWt; // mg
726 Acidmg = Acid; 724 Acidmg = Acid;
727 725
728 //find the pH where the protondeficit = protondeficit by the acid 726 //find the pH where the protondeficit = protondeficit by the acid
729 frac = CalcFrac(pHa, pK1, pK2, pK3); 727 frac = CalcFrac(pHa, pK1, pK2, pK3);
730 protonDeficit = Acid * frac; 728 protonDeficit = Acid * frac;
731 729
732 deltapH = 0.001; 730 deltapH = 0.001;
733 deltapd = 0.1; 731 deltapd = 0.1;
734 pd = ProtonDeficit(TpH); 732 pd = ProtonDeficit(pHa);
735 n = 0; 733 n = 0;
736 console.log("n: "+n+" pd: "+pd+" protonDeficit: "+protonDeficit+" frac: "+frac+" pHa: "+pHa); 734 // console.log("n: "+n+" pd: "+pd+" protonDeficit: "+protonDeficit+" frac: "+frac+" pHa: "+pHa);
737 735
738 while (((pd < (protonDeficit - deltapd)) || (pd > (protonDeficit + deltapd))) && (n < 2000)) { 736 while (((pd < (protonDeficit - deltapd)) || (pd > (protonDeficit + deltapd))) && (n < 2000)) {
739 n++; 737 n++;
740 if (pd < (protonDeficit-deltapd)) 738 if (pd < (protonDeficit-deltapd))
741 pHa = pHa - deltapH; 739 pHa -= deltapH;
742 else if (pd > (protonDeficit+deltapd)) 740 else if (pd > (protonDeficit+deltapd))
743 pHa = pHa + deltapH; 741 pHa += deltapH;
744 frac = CalcFrac(pHa, pK1, pK2, pK3); 742 frac = CalcFrac(pHa, pK1, pK2, pK3);
745 protonDeficit = Acid * frac; 743 protonDeficit = Acid * frac;
746 pd = ProtonDeficit(pHa); 744 pd = ProtonDeficit(pHa);
747 // console.log("n: "+n+" pd: "+pd+" protonDeficit: "+protonDeficit+" frac: "+frac+" pHa: "+pHa);
748 } 745 }
749 console.log("n: "+n+" pd: "+pd+" protonDeficit: "+protonDeficit+" frac: "+frac+" pHa: "+pHa); 746 console.log("n: "+n+" pd: "+pd+" protonDeficit: "+protonDeficit+" frac: "+frac+" pHa: "+pHa);
750 RA = wg_bicarbonate - protonDeficit * frac / liters; 747 RA = wg_bicarbonate - protonDeficit * frac / liters;
751 bicarbonate = RA; 748 bicarbonate = RA;
752 total_alkalinity = RA * 50 / 61; 749 total_alkalinity = RA * 50 / 61;
830 827
831 // Code from BrewBuddy/Brouwhulp, who got it from http://www.brewery.org/brewery/library/Acidi0,00fWaterAJD0497.html 828 // Code from BrewBuddy/Brouwhulp, who got it from http://www.brewery.org/brewery/library/Acidi0,00fWaterAJD0497.html
832 var TargetpH = dataRecord.sparge_ph; 829 var TargetpH = dataRecord.sparge_ph;
833 var Source_pH = dataRecord.w1_ph; 830 var Source_pH = dataRecord.w1_ph;
834 var Source_alkalinity = dataRecord.w1_total_alkalinity; 831 var Source_alkalinity = dataRecord.w1_total_alkalinity;
832 // Select watersource or fallback to the first source.
835 if (dataRecord.sparge_source == 'Bron 2') { 833 if (dataRecord.sparge_source == 'Bron 2') {
836 if (dataRecord.w2_ph > 0.0) { 834 if (dataRecord.w2_ph > 0.0) {
837 Source_pH = dataRecord.w2_ph; 835 Source_pH = dataRecord.w2_ph;
838 Source_alkalinity = dataRecord.w2_total_alkalinity; 836 Source_alkalinity = dataRecord.w2_total_alkalinity;
839 } else { 837 } else {
912 910
913 Acid *= dataRecord.sparge_volume; //ml lactic acid total 911 Acid *= dataRecord.sparge_volume; //ml lactic acid total
914 Acid = Math.round(Acid * 100) / 100; 912 Acid = Math.round(Acid * 100) / 100;
915 dataRecord.sparge_acid_amount = Acid / 1000; 913 dataRecord.sparge_acid_amount = Acid / 1000;
916 $("#sparge_acid_amount").val(Acid); 914 $("#sparge_acid_amount").val(Acid);
917 console.log("acid needed: "+Acid);
918 } 915 }
919 916
920 function calcFermentablesFromOG(OG) { 917 function calcFermentablesFromOG(OG) {
921 918
922 console.log("calcFermentablesFromOG("+OG+")"); 919 console.log("calcFermentablesFromOG("+OG+")");

mercurial