279 function Charge(pH) { |
325 function Charge(pH) { |
280 return (-2 * PartCO3(pH) - PartHCO3(pH)); |
326 return (-2 * PartCO3(pH) - PartHCO3(pH)); |
281 } |
327 } |
282 |
328 |
283 //Z alkalinity is the amount of acid (in mEq/l) needed to bring water to the target pH (Z pH) |
329 //Z alkalinity is the amount of acid (in mEq/l) needed to bring water to the target pH (Z pH) |
284 function ZAlkalinity(pHZ) { |
330 function ZAlkalinity(pHZ, WpH) { |
285 var C43 = Charge(4.3); |
331 var C43 = Charge(4.3); |
286 var Cw = Charge(parseFloat(dataRecord.mash_ph)); |
332 var Cw = Charge(WpH); |
287 var Cz = Charge(pHZ); |
333 var Cz = Charge(pHZ); |
288 var DeltaCNaught = -C43+Cw; |
334 var DeltaCNaught = -C43+Cw; |
289 var CT = parseFloat($("#wg_total_alkalinity").jqxNumberInput('decimal')) / 50 / DeltaCNaught; |
335 var CT = parseFloat($("#wg_total_alkalinity").jqxNumberInput('decimal')) / 50 / DeltaCNaught; |
290 var DeltaCZ = -Cz+Cw; |
336 var DeltaCZ = -Cz+Cw; |
291 return CT * DeltaCZ; |
337 return CT * DeltaCZ; |
292 } |
338 } |
293 |
339 |
294 function ZRA(pHZ) { |
340 //Z Residual alkalinity is the amount of acid (in mEq/l) needed to bring the water in the mash to the target pH (Z pH) |
|
341 function ZRA(pHZ, WpH) { |
295 |
342 |
296 var Calc = parseFloat($("#wg_calcium").jqxNumberInput('decimal')) / (MMCa / 2); |
343 var Calc = parseFloat($("#wg_calcium").jqxNumberInput('decimal')) / (MMCa / 2); |
297 var Magn = parseFloat($("#wg_magnesium").jqxNumberInput('decimal')) / (MMMg / 2); |
344 var Magn = parseFloat($("#wg_magnesium").jqxNumberInput('decimal')) / (MMMg / 2); |
298 var Z = ZAlkalinity(pHZ); |
345 var Z = ZAlkalinity(pHZ, WpH); |
299 return Z - (Calc / 3.5 + Magn / 7); |
346 return Z - (Calc / 3.5 + Magn / 7); |
300 } |
347 } |
301 |
348 |
302 function ProtonDeficit(pHZ) { |
349 function ProtonDeficit(pHZ) { |
303 |
350 |
304 var Result = ZRA(pHZ) * parseFloat($("#wg_amount").jqxNumberInput('decimal')); |
351 var Result = ZRA(pHZ, parseFloat($("#wg_ph").jqxNumberInput('decimal'))) * parseFloat($("#wg_amount").jqxNumberInput('decimal')); |
305 |
352 var rows = $('#fermentableGrid').jqxGrid('getrows'); |
|
353 for (var i = 0; i < rows.length; i++) { |
|
354 var row = rows[i]; |
|
355 if (row.f_added == 'Mash' && row.f_graintype != 'No malt') { |
|
356 // Check if acid is required |
|
357 var C1 = 0; |
|
358 if ((row.f_di_ph != 5.7) && ((row.f_acid_to_ph_57 < - 0.1) || (row.f_acid_to_ph_57 > 0.1))) { |
|
359 C1 = row.f_acid_to_ph_57 / (row.f_di_ph - 5.7); |
|
360 // console.log("formula C1: "+C1); |
|
361 } else { |
|
362 // If the acid_to_ph_5.7 is unknown from the malter, guess the required acid. |
|
363 var ebc = row.f_color; |
|
364 switch (row.f_graintype) { |
|
365 case 'Base': |
|
366 case 'Special': |
|
367 case 'Kilned': C1 = 0.014 * ebc - 34.192; |
|
368 break; |
|
369 case 'Crystal': C1 = -0.0597 * ebc - 32.457; |
|
370 break; |
|
371 case 'Roast': C1 = 0.0107 * ebc - 54.768; |
|
372 break; |
|
373 case 'Sour': C1 = -149; |
|
374 break; |
|
375 } |
|
376 // console.log("Logic C1: "+C1); |
|
377 } |
|
378 x = C1 * (pHZ - row.f_di_ph); // AcidRequired(ZpH) |
|
379 // console.log(row.f_name+" C1: "+C1+" ZpH: "+pHZ+" di_ph: "+row.f_di_ph+" acid rquired: "+x); |
|
380 Result += x * row.f_amount; |
|
381 } |
|
382 } |
|
383 // console.log("Final: "+Result); |
306 return Result; |
384 return Result; |
307 } |
385 } |
308 |
386 |
|
387 function MashpH() { |
|
388 var n = 0; |
|
389 var pH = 5.4; |
|
390 var deltapH = 0.001; |
|
391 var deltapd = 0.1; |
|
392 var pd = ProtonDeficit(pH); |
|
393 while (((pd < -deltapd) || (pd > deltapd)) && (n < 1000)) { |
|
394 n++; |
|
395 if (pd < -deltapd) |
|
396 pH -= deltapH; |
|
397 else if (pd > deltapd) |
|
398 pH += deltapH; |
|
399 pd = ProtonDeficit(pH); |
|
400 } |
|
401 console.log("MashpH() n: "+n+" pH: "+pH); |
|
402 } |
|
403 |
|
404 function GetAcidSpecs(AT) { |
|
405 switch(AT) { |
|
406 case 'Melkzuur': return { |
|
407 pK1: 3.08, |
|
408 pK2: 20, |
|
409 pK3: 20, |
|
410 MolWt: 90.08, |
|
411 AcidSG: 1214, |
|
412 AcidPrc: 0.88 |
|
413 }; |
|
414 case 'Zoutzuur': return { |
|
415 pK1: -10, |
|
416 pK2: 20, |
|
417 pK3: 20, |
|
418 MolWt: 36.46, |
|
419 AcidSG: 1142, |
|
420 AcidPrc: 0.28 |
|
421 }; |
|
422 case 'Fosforzuur': return { |
|
423 pK1: 2.12, |
|
424 pK2: 7.20, |
|
425 pK3: 12.44, |
|
426 MolWt: 98.00, |
|
427 AcidSG: 1170, |
|
428 AcidPrc: 0.25 |
|
429 }; |
|
430 case 'Zwavelzuur': return { |
|
431 pK1: -10, |
|
432 pK2: 1.92, |
|
433 pK3: 20, |
|
434 MolWt: 98.07, |
|
435 AcidSG: 1700, |
|
436 AcidPrc: 0.93 |
|
437 }; |
|
438 } |
|
439 } |
|
440 |
|
441 // Procedure TFrmWaterAdjustment.CalcWater2; |
309 function calcWater() { |
442 function calcWater() { |
310 |
443 |
311 console.log("calcWater()"); |
444 console.log("calcWater()"); |
312 var liters = 0; |
445 var liters = 0; |
313 var calcium = 0; |
446 var calcium = 0; |
314 var magnesium = 0; |
447 var magnesium = 0; |
315 var sodium = 0; |
448 var sodium = 0; |
316 var total_alkalinity = 0; |
449 var total_alkalinity = 0; |
|
450 var bicarbonate = 0; |
317 var chloride = 0; |
451 var chloride = 0; |
318 var sulfate = 0; |
452 var sulfate = 0; |
319 var ph = 0; |
453 var ph = 0; |
320 var RA = 0; |
454 var RA = 0; |
321 var acid = 0; |
455 var acid = 0; |
327 var TpH = 0; |
461 var TpH = 0; |
328 var AcidSG = 0; |
462 var AcidSG = 0; |
329 var AcidPrc = 0; |
463 var AcidPrc = 0; |
330 var protonDeficit = 0; |
464 var protonDeficit = 0; |
331 |
465 |
332 // console.log((dataRecord.w1_name != "") + " " + (dataRecord.w2_name != "")); |
466 if (dataRecord.w1_name == "") { |
333 if (dataRecord.w1_name != "") { |
467 return; |
334 if (dataRecord.w2_name != "") { |
468 } |
335 liters = dataRecord.w1_amount + dataRecord.w2_amount; |
469 // Check for a recipe too. Fermentables, Mash schedule? |
336 calcium = mix(dataRecord.w1_amount, dataRecord.w2_amount, dataRecord.w1_calcium, dataRecord.w2_calcium); |
470 |
337 magnesium = mix(dataRecord.w1_amount, dataRecord.w2_amount, dataRecord.w1_magnesium, dataRecord.w2_magnesium); |
471 // If there is a dillute water source, mix the waters. |
338 sodium = mix(dataRecord.w1_amount, dataRecord.w2_amount, dataRecord.w1_sodium, dataRecord.w2_sodium); |
472 if (dataRecord.w2_name != "") { |
339 chloride = mix(dataRecord.w1_amount, dataRecord.w2_amount, dataRecord.w1_chloride, dataRecord.w2_chloride); |
473 liters = dataRecord.w1_amount + dataRecord.w2_amount; |
340 sulfate = mix(dataRecord.w1_amount, dataRecord.w2_amount, dataRecord.w1_sulfate, dataRecord.w2_sulfate); |
474 calcium = mix(dataRecord.w1_amount, dataRecord.w2_amount, dataRecord.w1_calcium, dataRecord.w2_calcium); |
341 total_alkalinity = mix(dataRecord.w1_amount, dataRecord.w2_amount, dataRecord.w1_total_alkalinity, dataRecord.w2_total_alkalinity); |
475 magnesium = mix(dataRecord.w1_amount, dataRecord.w2_amount, dataRecord.w1_magnesium, dataRecord.w2_magnesium); |
342 ph = -Math.log10(((Math.pow(10, -dataRecord.w1_ph) * dataRecord.w1_amount) + (Math.pow(10, -dataRecord.w2_ph) * dataRecord.w2_amount)) / liters); |
476 sodium = mix(dataRecord.w1_amount, dataRecord.w2_amount, dataRecord.w1_sodium, dataRecord.w2_sodium); |
343 } else { |
477 chloride = mix(dataRecord.w1_amount, dataRecord.w2_amount, dataRecord.w1_chloride, dataRecord.w2_chloride); |
344 liters = dataRecord.w1_amount; |
478 sulfate = mix(dataRecord.w1_amount, dataRecord.w2_amount, dataRecord.w1_sulfate, dataRecord.w2_sulfate); |
345 calcium = dataRecord.w1_calcium; |
479 total_alkalinity = mix(dataRecord.w1_amount, dataRecord.w2_amount, dataRecord.w1_total_alkalinity, dataRecord.w2_total_alkalinity); |
346 magnesium = dataRecord.w1_magnesium; |
480 ph = -Math.log10(((Math.pow(10, -dataRecord.w1_ph) * dataRecord.w1_amount) + (Math.pow(10, -dataRecord.w2_ph) * dataRecord.w2_amount)) / liters); |
347 sodium = dataRecord.w1_sodium; |
481 } else { |
348 chloride = dataRecord.w1_chloride; |
482 liters = dataRecord.w1_amount; |
349 sulfate = dataRecord.w1_sulfate; |
483 calcium = dataRecord.w1_calcium; |
350 total_alkalinity = dataRecord.w1_total_alkalinity; |
484 magnesium = dataRecord.w1_magnesium; |
351 ph = dataRecord.w1_ph; |
485 sodium = dataRecord.w1_sodium; |
352 } |
486 chloride = dataRecord.w1_chloride; |
|
487 sulfate = dataRecord.w1_sulfate; |
|
488 total_alkalinity = dataRecord.w1_total_alkalinity; |
|
489 ph = dataRecord.w1_ph; |
353 } |
490 } |
354 $('#wg_amount').val(liters); |
491 $('#wg_amount').val(liters); |
355 $('#wg_calcium').val(Math.round(calcium * 10) / 10); |
492 $('#wg_calcium').val(Math.round(calcium * 10) / 10); |
356 $('#wg_magnesium').val(Math.round(magnesium * 10) / 10); |
493 $('#wg_magnesium').val(Math.round(magnesium * 10) / 10); |
357 $('#wg_sodium').val(Math.round(sodium * 10) / 10); |
494 $('#wg_sodium').val(Math.round(sodium * 10) / 10); |
358 $('#wg_total_alkalinity').val(Math.round(total_alkalinity * 10) / 10); |
495 $('#wg_total_alkalinity').val(Math.round(total_alkalinity * 10) / 10); |
359 $('#wg_chloride').val(Math.round(chloride * 10) / 10); |
496 $('#wg_chloride').val(Math.round(chloride * 10) / 10); |
360 $('#wg_sulfate').val(Math.round(sulfate * 10) / 10); |
497 $('#wg_sulfate').val(Math.round(sulfate * 10) / 10); |
361 // Note: brouwhulp has the malts included here in the result. |
498 // Note: brouwhulp has the malts included here in the result. |
362 $('#wg_ph').val(Math.round(ph * 10) / 10); |
499 $('#wg_ph').val(Math.round(ph * 10) / 10); |
|
500 $('#wb_ph').val(Math.round(ph * 10) / 10); |
|
501 bicarbonate = total_alkalinity * 1.22; |
363 |
502 |
364 // Noot: de volgende berekeningen geven bijna gelijke resultaten in Brun'water. |
503 // Noot: de volgende berekeningen geven bijna gelijke resultaten in Brun'water. |
365 // Calculate Ca |
504 // Calculate Ca |
366 RA = parseFloat($("#wa_cacl2").jqxNumberInput('decimal')) * MMCa / MMCaCl2 + |
505 RA = parseFloat($("#wa_cacl2").jqxNumberInput('decimal')) * MMCa / MMCaCl2 + |
367 parseFloat($("#wa_caso4").jqxNumberInput('decimal')) * MMCa / MMCaSO4; |
506 parseFloat($("#wa_caso4").jqxNumberInput('decimal')) * MMCa / MMCaSO4; |
368 calcium += 1000 * RA / parseFloat($("#wg_amount").jqxNumberInput('decimal')); |
507 calcium += 1000 * RA / liters; |
369 |
508 |
370 // Calculate Mg |
509 // Calculate Mg |
371 RA = parseFloat($("#wa_mgso4").jqxNumberInput('decimal')) * MMMg / MMMgSO4; |
510 RA = parseFloat($("#wa_mgso4").jqxNumberInput('decimal')) * MMMg / MMMgSO4; |
372 magnesium += 1000 * RA / parseFloat($("#wg_amount").jqxNumberInput('decimal')); |
511 magnesium += 1000 * RA / liters; |
373 |
512 |
374 // Calculate Na |
513 // Calculate Na |
375 RA = parseFloat($("#wa_nacl").jqxNumberInput('decimal')) * MMNa / MMNaCl + |
514 RA = parseFloat($("#wa_nacl").jqxNumberInput('decimal')) * MMNa / MMNaCl; |
376 parseFloat($("#wa_base").jqxNumberInput('decimal')) * MMNa / MMNaHCO3; |
515 sodium += 1000 * RA / liters; |
377 sodium += 1000 * RA / parseFloat($("#wg_amount").jqxNumberInput('decimal')); |
|
378 |
516 |
379 // Calculate SO4 |
517 // Calculate SO4 |
380 RA = parseFloat($("#wa_caso4").jqxNumberInput('decimal')) * MMSO4 / MMCaSO4 + |
518 RA = parseFloat($("#wa_caso4").jqxNumberInput('decimal')) * MMSO4 / MMCaSO4 + |
381 parseFloat($("#wa_mgso4").jqxNumberInput('decimal')) * MMSO4 / MMMgSO4; |
519 parseFloat($("#wa_mgso4").jqxNumberInput('decimal')) * MMSO4 / MMMgSO4; |
382 sulfate += 1000 * RA / parseFloat($("#wg_amount").jqxNumberInput('decimal')); |
520 sulfate += 1000 * RA / liters; |
383 |
521 |
384 // Calculate Cl |
522 // Calculate Cl |
385 RA = 2 * parseFloat($("#wa_cacl2").jqxNumberInput('decimal')) * MMCl / MMCaCl2 + |
523 RA = 2 * parseFloat($("#wa_cacl2").jqxNumberInput('decimal')) * MMCl / MMCaCl2 + |
386 parseFloat($("#wa_nacl").jqxNumberInput('decimal')) * MMCl / MMNaCl; |
524 parseFloat($("#wa_nacl").jqxNumberInput('decimal')) * MMCl / MMNaCl; |
387 chloride += 1000 * RA / parseFloat($("#wg_amount").jqxNumberInput('decimal')); |
525 chloride += 1000 * RA / liters; |
388 // Einde noot. |
526 // Einde noot. |
389 |
527 |
|
528 var AT = $("#wa_acid_name").val(); |
|
529 var BT = $("#wa_base_name").val(); |
|
530 |
|
531 var result = GetAcidSpecs(AT); |
|
532 pK1 = result.pK1; |
|
533 pK2 = result.pK2; |
|
534 pK3 = result.pK3; |
|
535 MolWt = result.MolWt; |
|
536 AcidSG = result.AcidSG; |
|
537 AcidPrc = result.AcidPrc; |
|
538 console.log(AT+" pK1: "+pK1+" pK2: "+pK2+" pK3: "+pK3+" MolWt: "+MolWt+" AcidSG: "+AcidSG+" AcidPrc: "+AcidPrc); |
|
539 |
|
540 if (dataRecord.calc_acid) { |
|
541 TpH = parseFloat(dataRecord.mash_ph); |
|
542 protonDeficit = ProtonDeficit(TpH); |
|
543 console.log("calc_acid tgt: "+TpH+" protonDeficit: "+protonDeficit); |
|
544 if (protonDeficit > 0) { // Add acid |
|
545 $("#wa_base").val(0); |
|
546 setWaterAgent(last_base, 0); |
|
547 if ($("#wa_acid_name").val() == "") { |
|
548 $("#wa_acid_name").val('Melkzuur'); |
|
549 last_acid = 'Melkzuur'; |
|
550 } |
|
551 frac = CalcFrac(TpH, pK1, pK2, pK3); |
|
552 Acid = protonDeficit / frac; |
|
553 console.log("Required moles: "+Acid); |
|
554 Acid *= MolWt; // mg |
|
555 // Acidmg = Acid; |
|
556 // console.log("Required mg: "+Acidmg); |
|
557 Acid = Acid / AcidSG; // ml |
|
558 |
|
559 if (parseFloat($("#wa_acid_perc").jqxNumberInput('decimal')) == 0) |
|
560 $("#wa_acid_perc").val(AcidPrc); |
|
561 Acid = Acid * AcidPrc / (parseFloat($("#wa_acid_perc").jqxNumberInput('decimal')) / 100); // ml |
|
562 console.log("Final ml: "+Acid); |
|
563 $("#wa_acid").val(Math.round(Acid * 100) / 100); |
|
564 setWaterAgent(AT, Math.round(Acid * 100) / 100); |
|
565 |
|
566 bicarbonate = bicarbonate - protonDeficit * frac / liters; |
|
567 total_alkalinity = bicarbonate * 50 / 61; |
|
568 } else if (protonDeficit < 0) { //Add base |
|
569 $("#wa_acid").val(0); |
|
570 setWaterAgent(last_acid, 0); |
|
571 if ($("#wa_base_name").val() == "") { |
|
572 $("#wa_base_name").val('NaHCO3'); |
|
573 last_base = 'NaHCO3'; |
|
574 } |
|
575 r1d = Math.pow(10, (TpH - 6.38)); |
|
576 r2d = Math.pow(10, (TpH - 10.38)); |
|
577 f1d = 1 / (1 + r1d + r1d * r2d); |
|
578 f2d = f1d * r1d; |
|
579 f3d = f2d * r2d; |
|
580 switch (BT) { |
|
581 case 'NaHCO3': base = -protonDeficit / (f1d - f3d); //mmol totaal |
|
582 base = base * MMNaHCO3/1000; //gram |
|
583 $("#wa_base").val(Math.round(base * 100) / 100); |
|
584 setWaterAgent(BT, Math.round(base * 100) / 100); |
|
585 if (liters > 0) { |
|
586 // Na |
|
587 RA = parseFloat($("#wa_nacl").jqxNumberInput('decimal')) * MMNa / MMNaCl + |
|
588 parseFloat($("#wa_base").jqxNumberInput('decimal')) * MMNa / MMNaHCO3; |
|
589 RA = 1000 * RA / liters; |
|
590 sodium = parseFloat($('#wg_sodium').jqxNumberInput('decimal')) + RA; |
|
591 // HCO3 |
|
592 RA = parseFloat($("#wa_base").jqxNumberInput('decimal')) * MMHCO3 / MMNaHCO3; |
|
593 RA = 1000 * RA / liters; |
|
594 bicarbonate = (parseFloat($('#wg_total_alkalinity').jqxNumberInput('decimal')) * 1.22) + RA; |
|
595 total_alkalinity = bicarbonate * 50 / 61; |
|
596 } |
|
597 break; |
|
598 case 'Na2CO3': base = -protonDeficit / (2 * f1d + f2d); //mmol totaal |
|
599 base = base * MMNa2CO3/1000; //gram |
|
600 $("#wa_base").val(Math.round(base * 100) / 100); |
|
601 setWaterAgent(BT, Math.round(base * 100) / 100); |
|
602 if (liters > 0) { |
|
603 RA = parseFloat($("#wa_nacl").jqxNumberInput('decimal')) * MMNa / MMNaCl + |
|
604 parseFloat($("#wa_base").jqxNumberInput('decimal')) * 2 * MMNa / MMNa2CO3; |
|
605 RA = 1000 * RA / liters; |
|
606 sodium = parseFloat($('#wg_sodium').jqxNumberInput('decimal')) + RA; |
|
607 // HCO3 |
|
608 RA = parseFloat($("#wa_base").jqxNumberInput('decimal')) * MMHCO3 / MMNa2CO3; |
|
609 RA = 1000 * RA / liters; |
|
610 bicarbonate = (parseFloat($('#wg_total_alkalinity').jqxNumberInput('decimal')) * 1.22) + RA; |
|
611 total_alkalinity = bicarbonate * 50 / 61; |
|
612 } |
|
613 break; |
|
614 case 'CaCO3': base = -protonDeficit * (f1d - f3d); //mmol totaal |
|
615 base = base * MMCaCO3/1000; //gram |
|
616 //but only 1/3 is effective, so add 3 times as much |
|
617 base = 3 * base; |
|
618 $("#wa_base").val(Math.round(base * 100) / 100); |
|
619 setWaterAgent(BT, Math.round(base * 100) / 100); |
|
620 if (liters > 0) { |
|
621 //Bicarbonate |
|
622 RA = parseFloat($("#wa_base").jqxNumberInput('decimal')) / 3 * MMHCO3 / MMCaCO3; |
|
623 RA = 1000 * RA / liters; |
|
624 bicarbonate = (parseFloat($('#wg_total_alkalinity').jqxNumberInput('decimal')) * 1.22) + RA; |
|
625 total_alkalinity = bicarbonate * 50 / 61; |
|
626 //Ca precipitates out as Ca10(PO4)6(OH)2 |
|
627 RA = parseFloat($("#wa_cacl2").jqxNumberInput('decimal')) * MMCa / MMCaCl2 + |
|
628 parseFloat($("#wa_caso4").jqxNumberInput('decimal')) * MMCa / MMCaSO4 + |
|
629 parseFloat($("#wa_base").jqxNumberInput('decimal')) * MMCa / MMCaCO3; |
|
630 RA = 1000 * RA / liters; |
|
631 calcium = parseFloat($('#wg_calcium').jqxNumberInput('decimal')) + RA; |
|
632 } |
|
633 break; |
|
634 case 'Ca(OH)2': base = -protonDeficit / 19.3; // g |
|
635 $("#wa_base").val(Math.round(base * 100) / 100); |
|
636 setWaterAgent(BT, Math.round(base * 100) / 100); |
|
637 if (liters > 0) { |
|
638 // Bicarbonate |
|
639 RA = -protonDeficit / liters; |
|
640 total_alkalinity = parseFloat($('#wg_total_alkalinity').jqxNumberInput('decimal')) + RA; |
|
641 bicarbonate = total_alkalinity * 61 / 50; |
|
642 // Calcium |
|
643 RA = parseFloat($("#wa_cacl2").jqxNumberInput('decimal')) * MMCa / MMCaCl2 + |
|
644 parseFloat($("#wa_caso4").jqxNumberInput('decimal')) * MMCa / MMCaSO4 + |
|
645 parseFloat($("#wa_base").jqxNumberInput('decimal')) * MMCa / MMCaOH2; |
|
646 RA = 1000 * RA / liters; |
|
647 calcium = parseFloat($('#wg_calcium').jqxNumberInput('decimal')) + RA; |
|
648 } |
|
649 break; |
|
650 } |
|
651 } |
|
652 ph = TpH; |
|
653 $('#wb_ph').val(Math.round(ph * 10) / 10); |
|
654 } else { // Manual |
|
655 console.log("calc_acid no"); |
|
656 // First add base salts |
|
657 if (parseFloat($("#wa_base").jqxNumberInput('decimal')) > 0) { |
|
658 |
|
659 } |
|
660 |
|
661 TpH = parseFloat(dataRecord.mash_ph); |
|
662 pHa = parseFloat($('#wg_ph').jqxNumberInput('decimal')); |
|
663 //pHa = parseFloat(dataRecord.mash_ph); |
|
664 // Then calculate the new pH with added acids |
|
665 if (parseFloat($("#wa_acid").jqxNumberInput('decimal')) > 0) { |
|
666 console.log("TpH: "+TpH+" water: "+pHa); |
|
667 Acid = parseFloat($("#wa_acid").jqxNumberInput('decimal')); |
|
668 if (parseFloat($("#wa_acid_perc").jqxNumberInput('decimal')) == 0) |
|
669 $("#wa_acid_perc").val(AcidPrc); |
|
670 Acid = Acid / AcidPrc * (parseFloat($("#wa_acid_perc").jqxNumberInput('decimal')) / 100); // ml |
|
671 Acid = Acid * AcidSG; // ml |
|
672 Acid = Acid / MolWt; // mg |
|
673 |
|
674 //find the pH where the protondeficit = protondeficit by the acid |
|
675 frac = CalcFrac(pHa, pK1, pK2, pK3); |
|
676 protonDeficit = Acid * frac; |
|
677 |
|
678 deltapH = 0.01; |
|
679 deltapd = 0.1; |
|
680 pd = ProtonDeficit(TpH); |
|
681 n = 0; |
|
682 console.log("n: "+n+" pd: "+pd+" protonDeficit: "+protonDeficit+" frac: "+frac+" pHa: "+pHa); |
|
683 |
|
684 while (((pd < (protonDeficit - deltapd)) || (pd > (protonDeficit + deltapd))) && (n < 1000)) { |
|
685 n++; |
|
686 if (pd < (protonDeficit-deltapd)) |
|
687 pHa = pHa - deltapH; |
|
688 else if (pd > (protonDeficit+deltapd)) |
|
689 pHa = pHa + deltapH; |
|
690 frac = CalcFrac(pHa, pK1, pK2, pK3); |
|
691 protonDeficit = Acid * frac; |
|
692 pd = ProtonDeficit(pHa); |
|
693 // console.log("n: "+n+" pd: "+pd+" protonDeficit: "+protonDeficit+" frac: "+frac+" pHa: "+pHa); |
|
694 } |
|
695 console.log("n: "+n+" pd: "+pd+" protonDeficit: "+protonDeficit+" frac: "+frac+" pHa: "+pHa); |
|
696 |
|
697 } |
|
698 } |
|
699 /* |
390 TpH = parseFloat(dataRecord.mash_ph); |
700 TpH = parseFloat(dataRecord.mash_ph); |
391 if (TpH < 5.0 || TpH > 6.0) { |
701 if (TpH < 5.0 || TpH > 6.0) { |
392 TpH = 5.4; |
702 TpH = 5.4; |
393 dataRecord.mash_ph = 5.4; |
703 dataRecord.mash_ph = 5.4; |
394 $("#mash_ph").val(5.4); |
704 $("#mash_ph").val(5.4); |
395 $("#tgt_mash_ph").val(5.4); |
|
396 } |
705 } |
397 var acid_amount = parseFloat($("#wa_acid").jqxNumberInput('decimal')); |
706 var acid_amount = parseFloat($("#wa_acid").jqxNumberInput('decimal')); |
398 var acid_perc = parseFloat($("#wa_acid_perc").jqxNumberInput('decimal')); |
707 var acid_perc = parseFloat($("#wa_acid_perc").jqxNumberInput('decimal')); |
399 |
708 |
400 switch ($("#wa_acid_name").val()) { |
709 switch ($("#wa_acid_name").val()) { |
441 Acidmg = acid_amount * acid_perc / 100 * AcidSG / liters; |
750 Acidmg = acid_amount * acid_perc / 100 * AcidSG / liters; |
442 acid += Acidmg / MolWt * frac; //mEq/l |
751 acid += Acidmg / MolWt * frac; //mEq/l |
443 sulfate += Acidmg / 1000 * MMSO4 / (MMSO4 + 2); |
752 sulfate += Acidmg / 1000 * MMSO4 / (MMSO4 + 2); |
444 break; |
753 break; |
445 } |
754 } |
446 protonDeficit = ProtonDeficit(TpH); |
755 |
447 console.log("frac: "+frac+" acid: "+acid+" protonDeficit: "+protonDeficit); |
756 if (dataRecord.calc_acid) { |
|
757 } else if (liters > 0) { // not calc_acid |
|
758 // First add base salts |
|
759 if (parseFloat($("#wa_base").jqxNumberInput('decimal')) > 0) { |
|
760 |
|
761 } |
|
762 |
|
763 pHa = parseFloat($("#wb_ph").jqxNumberInput('decimal')); |
|
764 console.log("Adjusted water mash pH: "+pHa); |
|
765 // Then calculate the new pH with added acids |
|
766 if (parseFloat($("#wa_acid").jqxNumberInput('decimal')) > 0) { |
|
767 acid = parseFloat($("#wa_acid").jqxNumberInput('decimal')); |
|
768 if (parseFloat($("#wa_acid_perc").jqxNumberInput('decimal')) == 0) |
|
769 $("#wa_acid_perc").val(AcidPrc); |
|
770 console.log("screen value: "+acid); |
|
771 acid = acid / AcidPrc * (parseFloat($("#wa_acid_perc").jqxNumberInput('decimal')) / 100); // ml |
|
772 console.log("acid ml: "+acid); |
|
773 acid = acid * AcidSG // ml |
|
774 console.log("acid ml: "+acid); |
|
775 acid = acid / MolWt; // mg |
|
776 console.log("acid mg: "+acid); |
|
777 var Acidmg = acid; |
|
778 |
|
779 frac = CalcFrac(pHa, pK1, pK2, pK3); |
|
780 protonDeficit = acid * frac; |
|
781 |
|
782 deltapH = 0.001; |
|
783 deltapd = 0.1; |
|
784 pd = ProtonDeficit(pHa); |
|
785 n = 0; |
|
786 console.log("n: "+n+" pd: "+pd+" protonDeficit: "+protonDeficit+" frac: "+frac+" pHa: "+pHa); |
|
787 |
|
788 while (((pd < (protonDeficit - deltapd)) || (pd > (protonDeficit + deltapd))) && (n < 1000)) { |
|
789 n++; |
|
790 if (pd < (protonDeficit-deltapd)) |
|
791 pHa = pHa - deltapH; |
|
792 else if (pd > (protonDeficit+deltapd)) |
|
793 pHa = pHa + deltapH; |
|
794 frac = CalcFrac(pHa, pK1, pK2, pK3); |
|
795 protonDeficit = acid * frac; |
|
796 pd = ProtonDeficit(pHa); |
|
797 console.log("n: "+n+" pd: "+pd+" protonDeficit: "+protonDeficit+" frac: "+frac+" pHa: "+pHa); |
|
798 } |
|
799 console.log("n: "+n+" pd: "+pd+" protonDeficit: "+protonDeficit+" frac: "+frac+" pHa: "+pHa); |
|
800 } |
|
801 } |
448 total_alkalinity -= 50 / 61 * protonDeficit * frac / liters; |
802 total_alkalinity -= 50 / 61 * protonDeficit * frac / liters; |
|
803 MashpH(); |
|
804 */ |
|
805 $('#tgt_bu').val(Math.round(GetBUGU() * 100) / 100); |
|
806 $('#tgt_cl_so4').val(Math.round(GetOptClSO4ratio() * 10) / 10); |
449 |
807 |
450 $('#wb_calcium').val(Math.round(calcium * 10) / 10); |
808 $('#wb_calcium').val(Math.round(calcium * 10) / 10); |
451 $('#wb_magnesium').val(Math.round(magnesium * 10) / 10); |
809 $('#wb_magnesium').val(Math.round(magnesium * 10) / 10); |
452 $('#wb_sodium').val(Math.round(sodium * 10) / 10); |
810 $('#wb_sodium').val(Math.round(sodium * 10) / 10); |
453 $('#wb_sulfate').val(Math.round(sulfate * 10) / 10); |
811 $('#wb_sulfate').val(Math.round(sulfate * 10) / 10); |
2008 $("#st_carb_min").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 50, height: 23, decimalDigits: 1, readOnly: true }); |
2382 $("#st_carb_min").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 50, height: 23, decimalDigits: 1, readOnly: true }); |
2009 $("#st_carb_max").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 50, height: 23, decimalDigits: 1, readOnly: true }); |
2383 $("#st_carb_max").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 50, height: 23, decimalDigits: 1, readOnly: true }); |
2010 |
2384 |
2011 $("#mash_name").jqxInput({ theme: theme, width: 320, height: 23 }); |
2385 $("#mash_name").jqxInput({ theme: theme, width: 320, height: 23 }); |
2012 $("#mash_ph").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 100, height: 23, min: 4, max: 8, decimalDigits: 1, spinButtons: true, spinButtonsStep: 0.1 }); |
2386 $("#mash_ph").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 100, height: 23, min: 4, max: 8, decimalDigits: 1, spinButtons: true, spinButtonsStep: 0.1 }); |
2013 $("#tgt_mash_ph").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 100, height: 23, decimalDigits: 1, readOnly: true }); |
|
2014 $("#sparge_temp").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 100, height: 23, min: 70, max: 98, decimalDigits: 1, spinButtons: true, spinButtonsStep: 0.5 }); |
2387 $("#sparge_temp").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 100, height: 23, min: 70, max: 98, decimalDigits: 1, spinButtons: true, spinButtonsStep: 0.5 }); |
2015 // Several gauges |
2388 // Several gauges |
2016 $("#hop_flavour").jqxProgressBar({ width: 300, height: 23, theme: theme, showText: true }); |
2389 $("#hop_flavour").jqxProgressBar({ width: 300, height: 23, theme: theme, showText: true }); |
2017 $("#hop_aroma").jqxProgressBar({ width: 300, height: 23, theme: theme, showText: true }); |
2390 $("#hop_aroma").jqxProgressBar({ width: 300, height: 23, theme: theme, showText: true }); |
2018 $("#perc_malts").jqxProgressBar({ width: 300, height: 23, theme: theme, showText: true }); |
2391 $("#perc_malts").jqxProgressBar({ width: 300, height: 23, theme: theme, showText: true }); |
2151 $("#pr_sodium").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 74, height: 23, decimalDigits: 1, readOnly: true }); |
2524 $("#pr_sodium").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 74, height: 23, decimalDigits: 1, readOnly: true }); |
2152 $("#pr_total_alkalinity").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 74, height: 23, decimalDigits: 1, readOnly: true }); |
2525 $("#pr_total_alkalinity").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 74, height: 23, decimalDigits: 1, readOnly: true }); |
2153 $("#pr_chloride").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 74, height: 23, decimalDigits: 1, readOnly: true }); |
2526 $("#pr_chloride").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 74, height: 23, decimalDigits: 1, readOnly: true }); |
2154 $("#pr_sulfate").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 74, height: 23, decimalDigits: 1, readOnly: true }); |
2527 $("#pr_sulfate").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 74, height: 23, decimalDigits: 1, readOnly: true }); |
2155 |
2528 |
2156 $("#wa_cacl2").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 100, height: 23, min: 0, decimalDigits: 1, spinButtons: true, spinButtonsStep: 0.1, symbol: ' gr', symbolPosition: 'right' }); |
2529 $("#tgt_bu").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 74, height: 23, decimalDigits: 2, readOnly: true }); |
2157 $("#wa_caso4").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 100, height: 23, min: 0, decimalDigits: 1, spinButtons: true, spinButtonsStep: 0.1, symbol: ' gr', symbolPosition: 'right' }); |
2530 $("#tgt_cl_so4").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 74, height: 23, decimalDigits: 1, readOnly: true }); |
2158 $("#wa_mgso4").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 100, height: 23, min: 0, decimalDigits: 1, spinButtons: true, spinButtonsStep: 0.1, symbol: ' gr', symbolPosition: 'right' }); |
2531 |
2159 $("#wa_nacl").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 100, height: 23, min: 0, decimalDigits: 1, spinButtons: true, spinButtonsStep: 0.1, symbol: ' gr', symbolPosition: 'right' }); |
2532 $("#wa_cacl2").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 100, height: 23, min: 0, max: 1000, decimalDigits: 1, spinButtons: true, spinButtonsStep: 0.1, symbol: ' gr', symbolPosition: 'right' }); |
|
2533 $("#wa_caso4").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 100, height: 23, min: 0, max: 1000, decimalDigits: 1, spinButtons: true, spinButtonsStep: 0.1, symbol: ' gr', symbolPosition: 'right' }); |
|
2534 $("#wa_mgso4").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 100, height: 23, min: 0, max: 1000, decimalDigits: 1, spinButtons: true, spinButtonsStep: 0.1, symbol: ' gr', symbolPosition: 'right' }); |
|
2535 $("#wa_nacl").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 100, height: 23, min: 0, max: 1000, decimalDigits: 1, spinButtons: true, spinButtonsStep: 0.1, symbol: ' gr', symbolPosition: 'right' }); |
2160 |
2536 |
2161 $("#calc_acid").jqxCheckBox({ theme: theme, width: 120, height: 23 }); |
2537 $("#calc_acid").jqxCheckBox({ theme: theme, width: 120, height: 23 }); |
2162 $("#wa_base_name").jqxDropDownList({ theme: theme, source: srcBase, width: 125, height: 23, dropDownHeight: 128 }); |
2538 $("#wa_base_name").jqxDropDownList({ theme: theme, source: srcBase, width: 125, height: 23, dropDownHeight: 128 }); |
2163 $("#wa_base").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 100, height: 23, min: 0, decimalDigits: 2, spinButtons: true, spinButtonsStep: 0.05, symbol: ' gr', symbolPosition: 'right' }); |
2539 $("#wa_base").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 100, height: 23, min: 0, decimalDigits: 2, spinButtons: true, spinButtonsStep: 0.05, symbol: ' gr', symbolPosition: 'right' }); |
2164 $("#wa_acid_name").jqxDropDownList({ theme: theme, source: srcAcid, width: 125, height: 23, dropDownHeight: 128 }) |
2540 $("#wa_acid_name").jqxDropDownList({ theme: theme, source: srcAcid, width: 125, height: 23, dropDownHeight: 128 }) |