src/EditRecipeTab7.cpp

changeset 365
4bc746c65650
parent 361
ec8de79f6ff6
child 395
7212b980a527
equal deleted inserted replaced
364:1efe29f64551 365:4bc746c65650
468 * Based on the work of ajDeLange. 468 * Based on the work of ajDeLange.
469 */ 469 */
470 void EditRecipe::calcSparge() 470 void EditRecipe::calcSparge()
471 { 471 {
472 double TargetpH = recipe->sparge_ph; 472 double TargetpH = recipe->sparge_ph;
473 double Source_pH = recipe->w1_ph; 473 double Source_pH = 7.0;
474 double Source_alkalinity = recipe->w1_total_alkalinity;
475 474
476 qDebug() << "calcSparge()"; 475 qDebug() << "calcSparge()";
477 setButtons(recipe->locked); 476 setButtons(recipe->locked);
478 477
479 if (recipe->sparge_source == 1 && recipe->w2_ph > 0.0) { 478 if (recipe->sparge_source == 1 && recipe->w2_ph > 0.0) {
480 Source_pH = recipe->w2_ph; 479 recipe->ws_calcium = recipe->w2_calcium;
481 Source_alkalinity = recipe->w2_total_alkalinity; 480 recipe->ws_magnesium = recipe->w2_magnesium;
482 ui->sp_caEdit->setValue(recipe->w2_calcium); 481 recipe->ws_total_alkalinity = recipe->w2_total_alkalinity;
483 ui->sp_mgEdit->setValue(recipe->w2_magnesium); 482 recipe->ws_sodium = recipe->w2_sodium;
484 ui->sp_hco3Edit->setValue(Utils::Bicarbonate(recipe->w2_total_alkalinity, recipe->w2_ph)); 483 recipe->ws_chloride = recipe->w2_chloride;
485 ui->sp_caco3Edit->setValue(recipe->w2_total_alkalinity); 484 recipe->ws_sulfate = recipe->w2_sulfate;
486 ui->sp_naEdit->setValue(recipe->w2_sodium); 485 Source_pH = recipe->w2_ph;
487 ui->sp_clEdit->setValue(recipe->w2_chloride);
488 ui->sp_so4Edit->setValue(recipe->w2_sulfate);
489 ui->sp_phShow->setValue(recipe->w2_ph);
490 ui->sp_hardnessEdit->setValue(Utils::Hardness(recipe->w2_calcium, recipe->w2_magnesium));
491 ui->sp_raEdit->setValue(Utils::ResidualAlkalinity(recipe->w2_total_alkalinity, recipe->w2_calcium, recipe->w2_magnesium));
492 } else if (recipe->sparge_source == 2 && recipe->w2_ph > 0.0) { 486 } else if (recipe->sparge_source == 2 && recipe->w2_ph > 0.0) {
493 Source_pH = recipe->wg_ph; 487 recipe->ws_calcium = recipe->wg_calcium;
494 Source_alkalinity = recipe->wg_total_alkalinity; 488 recipe->ws_magnesium = recipe->wg_magnesium;
495 ui->sp_caEdit->setValue(recipe->wg_calcium); 489 recipe->ws_total_alkalinity = recipe->wg_total_alkalinity;
496 ui->sp_mgEdit->setValue(recipe->wg_magnesium); 490 recipe->ws_sodium = recipe->wg_sodium;
497 ui->sp_hco3Edit->setValue(Utils::Bicarbonate(recipe->wg_total_alkalinity, recipe->wg_ph)); 491 recipe->ws_chloride = recipe->wg_chloride;
498 ui->sp_caco3Edit->setValue(recipe->wg_total_alkalinity); 492 recipe->ws_sulfate = recipe->wg_sulfate;
499 ui->sp_naEdit->setValue(recipe->wg_sodium); 493 Source_pH = recipe->wg_ph;
500 ui->sp_clEdit->setValue(recipe->wg_chloride);
501 ui->sp_so4Edit->setValue(recipe->wg_sulfate);
502 ui->sp_phShow->setValue(recipe->wg_ph);
503 ui->sp_hardnessEdit->setValue(Utils::Hardness(recipe->wg_calcium, recipe->wg_magnesium));
504 ui->sp_raEdit->setValue(Utils::ResidualAlkalinity(recipe->wg_total_alkalinity, recipe->wg_calcium, recipe->wg_magnesium));
505 } else { 494 } else {
506 ui->sp_caEdit->setValue(recipe->w1_calcium); 495 recipe->ws_calcium = recipe->w1_calcium;
507 ui->sp_mgEdit->setValue(recipe->w1_magnesium); 496 recipe->ws_magnesium = recipe->w1_magnesium;
508 ui->sp_hco3Edit->setValue(Utils::Bicarbonate(recipe->w1_total_alkalinity, recipe->w1_ph)); 497 recipe->ws_total_alkalinity = recipe->w1_total_alkalinity;
509 ui->sp_caco3Edit->setValue(recipe->w1_total_alkalinity); 498 recipe->ws_sodium = recipe->w1_sodium;
510 ui->sp_naEdit->setValue(recipe->w1_sodium); 499 recipe->ws_chloride = recipe->w1_chloride;
511 ui->sp_clEdit->setValue(recipe->w1_chloride); 500 recipe->ws_sulfate = recipe->w1_sulfate;
512 ui->sp_so4Edit->setValue(recipe->w1_sulfate); 501 Source_pH = recipe->w1_ph;
513 ui->sp_phShow->setValue(recipe->w1_ph); 502 }
514 ui->sp_hardnessEdit->setValue(Utils::Hardness(recipe->w1_calcium, recipe->w1_magnesium)); 503
515 ui->sp_raEdit->setValue(Utils::ResidualAlkalinity(recipe->w1_total_alkalinity, recipe->w1_calcium, recipe->w1_magnesium)); 504 /* Calculate Salt additions */
516 } 505 if (recipe->sparge_volume > 0) {
517 // The spargewater is set. 506 recipe->ws_calcium += ( ui->ss_cacl2Edit->value() * MMCa / MMCaCl2 * 1000 + ui->ss_caso4Edit->value() * MMCa / MMCaSO4 * 1000) / recipe->sparge_volume;
507 recipe->ws_magnesium += (ui->ss_mgso4Edit->value() * MMMg / MMMgSO4 * 1000 + ui->ss_mgcl2Edit->value() * MMMg / MMMgCl2 * 1000) / recipe->sparge_volume;
508 recipe->ws_sodium += (ui->ss_naclEdit->value() * MMNa / MMNaCl * 1000) / recipe->sparge_volume;
509 recipe->ws_sulfate += (ui->ss_caso4Edit->value() * MMSO4 / MMCaSO4 * 1000 + ui->ss_mgso4Edit->value() * MMSO4 / MMMgSO4 * 1000) / recipe->sparge_volume;
510 recipe->ws_chloride += (2 * ui->ss_cacl2Edit->value() * MMCl / MMCaCl2 * 1000 + ui->ss_naclEdit->value() * MMCl / MMNaCl * 1000 +
511 ui->ss_mgcl2Edit->value() * MMCl / MMMgCl2 * 1000) / recipe->sparge_volume;
512 }
513
514 /* Show the spargewater with salt additions. */
515 ui->sp_caEdit->setValue(recipe->ws_calcium);
516 ui->sp_mgEdit->setValue(recipe->ws_magnesium);
517 ui->sp_hco3Edit->setValue(Utils::Bicarbonate(recipe->ws_total_alkalinity, Source_pH));
518 ui->sp_caco3Edit->setValue(recipe->ws_total_alkalinity);
519 ui->sp_naEdit->setValue(recipe->ws_sodium);
520 ui->sp_clEdit->setValue(recipe->ws_chloride);
521 ui->sp_so4Edit->setValue(recipe->ws_sulfate);
522 ui->sp_phShow->setValue(recipe->sparge_ph);
523 ui->sp_hardnessEdit->setValue(Utils::Hardness(recipe->ws_calcium, recipe->ws_magnesium));
524 ui->sp_raEdit->setValue(Utils::ResidualAlkalinity(recipe->ws_total_alkalinity, recipe->ws_calcium, recipe->ws_magnesium));
518 525
519 int AT = recipe->sparge_acid_type; 526 int AT = recipe->sparge_acid_type;
520 if (AT < 0 || AT >= my_acids.size()) { 527 if (AT < 0 || AT >= my_acids.size()) {
521 AT = 0; 528 AT = 0;
522 recipe->sparge_acid_type = 0; 529 recipe->sparge_acid_type = 0;
542 double d43 = 1 + r143 + r143 * r243; 549 double d43 = 1 + r143 + r143 * r243;
543 double f143 = 1 / d43; 550 double f143 = 1 / d43;
544 double f343 = r143 * r243 / d43; 551 double f343 = r143 * r243 / d43;
545 552
546 // Step 4. Solve 553 // Step 4. Solve
547 double Ct = Source_alkalinity / 50 / ((f143 - f1) + (f3 - f343)); 554 double Ct = recipe->ws_total_alkalinity / 50 / ((f143 - f1) + (f3 - f343));
548 555
549 // Step 5. Compute mole fractions at desired pH 556 // Step 5. Compute mole fractions at desired pH
550 double r1g = pow(10, TargetpH - 6.35); 557 double r1g = pow(10, TargetpH - 6.35);
551 double r2g = pow(10, TargetpH - 10.33); 558 double r2g = pow(10, TargetpH - 10.33);
552 double dg = 1 + r1g + r1g * r2g; 559 double dg = 1 + r1g + r1g * r2g;
576 QString w = my_acids[AT].name_en + ' ' + my_acids[AT].name_nl; 583 QString w = my_acids[AT].name_en + ' ' + my_acids[AT].name_nl;
577 brewing_salt_sub(w, Acid, MISC_USES_SPARGE); // Put it in the miscs table. 584 brewing_salt_sub(w, Acid, MISC_USES_SPARGE); // Put it in the miscs table.
578 ui->sp_acidvolEdit->setValue(Acid); 585 ui->sp_acidvolEdit->setValue(Acid);
579 } 586 }
580 587
581 ui->sp_phShow->setValue(recipe->sparge_ph);
582 // Finally calculate the estimate preboil pH 588 // Finally calculate the estimate preboil pH
583 recipe->preboil_ph = -log10(((pow(10, -recipe->mash_ph) * recipe->wg_amount) + (pow(10, -recipe->sparge_ph) * recipe->sparge_volume)) / 589 recipe->preboil_ph = -log10(((pow(10, -recipe->mash_ph) * recipe->wg_amount) + (pow(10, -recipe->sparge_ph) * recipe->sparge_volume)) /
584 (recipe->wg_amount + recipe->sparge_volume)); 590 (recipe->wg_amount + recipe->sparge_volume));
585 ui->preboil_phEdit->setValue(recipe->preboil_ph); 591 ui->preboil_phEdit->setValue(recipe->preboil_ph);
586 } 592 }
622 628
623 629
624 void EditRecipe::sp_ph_changed(double val) 630 void EditRecipe::sp_ph_changed(double val)
625 { 631 {
626 recipe->sparge_ph = val; 632 recipe->sparge_ph = val;
633 calcSparge();
634 is_changed();
635 }
636
637
638 void EditRecipe::sp_vol_changed(double val)
639 {
640 if (! recipe->calc_acid) {
641 recipe->sparge_acid_amount *= val / recipe->sparge_volume;
642 const QSignalBlocker blocker1(ui->sp_acidvolEdit);
643 ui->sp_acidvolEdit->setValue(recipe->sparge_acid_amount * 1000.0);
644 }
645
646 recipe->sparge_volume = val;
627 calcSparge(); 647 calcSparge();
628 is_changed(); 648 is_changed();
629 } 649 }
630 650
631 651

mercurial