src/Utils.cpp

changeset 454
2dfead81c72f
parent 453
fc0c10d79539
child 498
c6f957fa7442
equal deleted inserted replaced
453:fc0c10d79539 454:2dfead81c72f
442 double AddedAlphaAcids = (alpha * mass * 1000) / Volume; 442 double AddedAlphaAcids = (alpha * mass * 1000) / Volume;
443 double Bigness_factor = 1.65 * pow(0.000125, SG - 1); 443 double Bigness_factor = 1.65 * pow(0.000125, SG - 1);
444 double BoilTime_factor1 = ((1 - exp(-0.04 * T1)) / kUtilisation); 444 double BoilTime_factor1 = ((1 - exp(-0.04 * T1)) / kUtilisation);
445 double BoilTime_factor2 = ((1 - exp(-0.04 * T2)) / kUtilisation); 445 double BoilTime_factor2 = ((1 - exp(-0.04 * T2)) / kUtilisation);
446 double ibu = Bigness_factor * (BoilTime_factor2 - BoilTime_factor1) * AddedAlphaAcids; 446 double ibu = Bigness_factor * (BoilTime_factor2 - BoilTime_factor1) * AddedAlphaAcids;
447 //qDebug() << "TinsethIBU" << SG << Amount << Alpha << Volume << kUtilisation << Bigness_factor * (BoilTime_factor2 - BoilTime_factor1) << "ibu:" << ibu; 447
448 448 #ifdef DEBUG_IBU
449 //qDebug() << "boilIBU" << Form << SG << Volume << Amount << BoilTime_factor2 << BoilTime_factor1 << Alpha << "IBU:" << ibu; 449 qDebug() << "TinsethIBU" << SG << Amount << Alpha << Volume << kUtilisation << Bigness_factor * (BoilTime_factor2 - BoilTime_factor1) << "ibu:" << ibu;
450 qDebug() << " boilIBU" << Form << SG << Volume << Amount << BoilTime_factor2 << BoilTime_factor1 << Alpha << "IBU:" << ibu;
451 #endif
450 return ibu; 452 return ibu;
451 } 453 }
452 454
453 455
454 double Utils::toIBU(int Use, int Form, double preSG, double postSG, double Volume, double Amount, double Boiltime, double Alpha, 456 double Utils::toIBU(int Use, int Form, double preSG, double postSG, double Volume, double Amount, double Boiltime, double Alpha,
499 * Flameout, currently fixed 1 minute. 501 * Flameout, currently fixed 1 minute.
500 */ 502 */
501 double flameout_time = 1; 503 double flameout_time = 1;
502 double fibu = TinsethIBU(Form, postSG, Volume, Amount, boil_time, boil_time + flameout_time, Alpha, Utilisation, BU_factor); 504 double fibu = TinsethIBU(Form, postSG, Volume, Amount, boil_time, boil_time + flameout_time, Alpha, Utilisation, BU_factor);
503 fibu *= IBU_reduction(bp - 0.5); /* Boilpoint minus 0.5 degree */ 505 fibu *= IBU_reduction(bp - 0.5); /* Boilpoint minus 0.5 degree */
504 //qDebug() << "during flameout" << fibu << bp; 506 #ifdef DEBUG_IBU
507 qDebug() << "during flameout" << fibu << bp;
508 #endif
505 nibu += fibu; 509 nibu += fibu;
506 510
507 if ((Cooltype == CHILLER_TYPE_IMMERSION || Cooltype == CHILLER_TYPE_AUBAINMARIE || Cooltype == CHILLER_TYPE_NOCHILL) && CoolTo79 > 0) { 511 if ((Cooltype == CHILLER_TYPE_IMMERSION || Cooltype == CHILLER_TYPE_AUBAINMARIE || Cooltype == CHILLER_TYPE_NOCHILL) && CoolTo79 > 0) {
508 /* 512 /*
509 * Direct wort chilling, calculate the IBU's when chilling down to 79 degrees. 513 * Direct wort chilling, calculate the IBU's when chilling down to 79 degrees.
510 */ 514 */
511 double cibu = 0, tibu; 515 double cibu = 0, tibu;
512 for (int i = 1; i < int(CoolTo79); i++) { 516 for (int i = 1; i < int(CoolTo79); i++) {
513 tibu = TinsethIBU(Form, postSG, Volume, Amount, boil_time + flameout_time + i, boil_time + flameout_time + i + 1, Alpha, Utilisation, BU_factor); 517 tibu = TinsethIBU(Form, postSG, Volume, Amount, boil_time + flameout_time + i, boil_time + flameout_time + i + 1, Alpha, Utilisation, BU_factor);
514 tibu *= IBU_reduction((bp - 1) - (i * ((bp - 80) / CoolTo79))); 518 tibu *= IBU_reduction((bp - 1) - (i * ((bp - 80) / CoolTo79)));
515 //qDebug() << " chill" << i << "time" << boil_time + flameout_time + i << "temp" << (bp - 1) - (i * ((bp - 80) / CoolTo79)) << "ibu" << tibu; 519 #ifdef DEBUG_IBU
520 qDebug() << " chill" << i << "time" << boil_time + flameout_time + i << "temp" << (bp - 1) - (i * ((bp - 80) / CoolTo79)) << "ibu" << tibu;
521 #endif
516 cibu += tibu; 522 cibu += tibu;
517 } 523 }
518 //qDebug() << " immersion" << cibu; 524 #ifdef DEBUG_IBU
525 qDebug() << " immersion" << cibu;
526 #endif
519 nibu += cibu; 527 nibu += cibu;
520 } 528 }
521 529
522 if (Cooltype == CHILLER_TYPE_COUNTERFLOW && CoolLPM > 0) { 530 if (Cooltype == CHILLER_TYPE_COUNTERFLOW && CoolLPM > 0) {
523 /* 531 /*
532 /* 540 /*
533 * Correction for the natural cooling of the wort in the kettle. 541 * Correction for the natural cooling of the wort in the kettle.
534 * Asume 0.1 degree per minute. 542 * Asume 0.1 degree per minute.
535 */ 543 */
536 tibu *= IBU_reduction((bp - 1) - (i * 0.1)); 544 tibu *= IBU_reduction((bp - 1) - (i * 0.1));
537 //qDebug() << " chill" << i << steps << "left" << V << A << "time" << boil_time + flameout_time + i << "ibu" << tibu; 545 #ifdef DEBUG_IBU
546 qDebug() << " chill" << i << steps << "left" << V << A << "time" << boil_time + flameout_time + i << "ibu" << tibu;
547 #endif
538 cibu += tibu; 548 cibu += tibu;
539 } 549 }
540 //qDebug() << " counterflow" << cibu; 550 #ifdef DEBUG_IBU
551 qDebug() << " counterflow" << cibu;
552 #endif
541 nibu += cibu; 553 nibu += cibu;
542 } 554 }
543 555
544 /* 556 /*
545 * Hopstands, this boil hop adds some IBU's too. 557 * Hopstands, this boil hop adds some IBU's too.
546 */ 558 */
547 if (Whirlpool9) { 559 if (Whirlpool9) {
548 double wibu9 = TinsethIBU(Form, postSG, Volume, Amount, boil_time + flameout_time, boil_time + flameout_time + Whirlpool9, Alpha, Utilisation, BU_factor); 560 double wibu9 = TinsethIBU(Form, postSG, Volume, Amount, boil_time + flameout_time, boil_time + flameout_time + Whirlpool9, Alpha, Utilisation, BU_factor);
549 wibu9 *= IBU_reduction(87.0); 561 wibu9 *= IBU_reduction(87.0);
550 //qDebug() << "during whirlpool9" << wibu9; 562 #ifdef DEBUG_IBU
563 qDebug() << "during whirlpool9" << wibu9;
564 #endif
551 nibu += wibu9; 565 nibu += wibu9;
552 } 566 }
553 if (Whirlpool7) { 567 if (Whirlpool7) {
554 double wibu7 = TinsethIBU(Form, postSG, Volume, Amount, boil_time + flameout_time, boil_time + flameout_time + Whirlpool7, Alpha, Utilisation, BU_factor); 568 double wibu7 = TinsethIBU(Form, postSG, Volume, Amount, boil_time + flameout_time, boil_time + flameout_time + Whirlpool7, Alpha, Utilisation, BU_factor);
555 wibu7 *= IBU_reduction(74.0); 569 wibu7 *= IBU_reduction(74.0);
556 //qDebug() << "during whirlpool7" << wibu7; 570 #ifdef DEBUG_IBU
571 qDebug() << "during whirlpool7" << wibu7;
572 #endif
557 nibu += wibu7; 573 nibu += wibu7;
558 } 574 }
559 if (Whirlpool6) { 575 if (Whirlpool6) {
560 double wibu6 = TinsethIBU(Form, postSG, Volume, Amount, boil_time + flameout_time, boil_time + flameout_time + Whirlpool6, Alpha, Utilisation, BU_factor); 576 double wibu6 = TinsethIBU(Form, postSG, Volume, Amount, boil_time + flameout_time, boil_time + flameout_time + Whirlpool6, Alpha, Utilisation, BU_factor);
561 wibu6 *= IBU_reduction(63.0); 577 wibu6 *= IBU_reduction(63.0);
562 //qDebug() << "during whirlpool6" << wibu6; 578 #ifdef DEBUG_IBU
579 qDebug() << "during whirlpool6" << wibu6;
580 #endif
563 nibu += wibu6; 581 nibu += wibu6;
564 } 582 }
565 //qDebug() << "Old IBU" << ibu << "New IBU" << nibu; 583 #ifdef DEBUG_IBU
584 qDebug() << "Old IBU" << ibu << "New IBU" << nibu;
585 #endif
566 ibu = nibu; 586 ibu = nibu;
567 } 587 }
568 588
569 } else if ((Use == HOP_USEAT_AROMA) && (Method > 0)) { 589 } else if ((Use == HOP_USEAT_AROMA) && (Method > 0)) {
570 /* 590 /*
580 */ 600 */
581 double cibu = 0, tibu; 601 double cibu = 0, tibu;
582 for (int i = 1; i < int(CoolTo79); i++) { 602 for (int i = 1; i < int(CoolTo79); i++) {
583 tibu = TinsethIBU(Form, postSG, Volume, Amount, flameout_time + i, flameout_time + i + 1, Alpha, Utilisation, BU_factor); 603 tibu = TinsethIBU(Form, postSG, Volume, Amount, flameout_time + i, flameout_time + i + 1, Alpha, Utilisation, BU_factor);
584 tibu *= IBU_reduction((bp - 1) - (i * ((bp - 80) / CoolTo79))); 604 tibu *= IBU_reduction((bp - 1) - (i * ((bp - 80) / CoolTo79)));
585 //qDebug() << " chill" << i << "time" << flameout_time + i << "temp" << (bp - 1) - (i * ((bp - 80) / CoolTo79)) << "ibu" << tibu; 605 #ifdef DEBUG_IBU
606 qDebug() << " chill" << i << "time" << flameout_time + i << "temp" << (bp - 1) - (i * ((bp - 80) / CoolTo79)) << "ibu" << tibu;
607 #endif
586 cibu += tibu; 608 cibu += tibu;
587 } 609 }
588 //qDebug() << " immersion" << cibu; 610 #ifdef DEBUG_IBU
611 qDebug() << " immersion" << cibu;
612 #endif
589 ibu += cibu; 613 ibu += cibu;
590 } 614 }
591 615
592 if (Cooltype == CHILLER_TYPE_COUNTERFLOW && CoolLPM > 0) { 616 if (Cooltype == CHILLER_TYPE_COUNTERFLOW && CoolLPM > 0) {
593 /* 617 /*
602 /* 626 /*
603 * Correction for the natural cooling of the wort in the kettle. 627 * Correction for the natural cooling of the wort in the kettle.
604 * Asume 0.1 degree per minute. 628 * Asume 0.1 degree per minute.
605 */ 629 */
606 tibu *= IBU_reduction((bp - 1) - (i * 0.1)); 630 tibu *= IBU_reduction((bp - 1) - (i * 0.1));
607 //qDebug() << " chill" << i << steps << "left" << V << A << "time" << flameout_time + i << "ibu" << tibu; 631 #ifdef DEBUG_IBU
632 qDebug() << " chill" << i << steps << "left" << V << A << "time" << flameout_time + i << "ibu" << tibu;
633 #endif
608 cibu += tibu; 634 cibu += tibu;
609 } 635 }
610 //qDebug() << " counterflow" << cibu; 636 #ifdef DEBUG_IBU
637 qDebug() << " counterflow" << cibu;
638 #endif
611 ibu += cibu; 639 ibu += cibu;
612 } 640 }
613 641
614 /* 642 /*
615 * Hopstands, this flameout hop adds some IBU's too. 643 * Hopstands, this flameout hop adds some IBU's too.
616 */ 644 */
617 if (Whirlpool9) { 645 if (Whirlpool9) {
618 double wibu9 = TinsethIBU(Form, postSG, Volume, Amount, flameout_time, flameout_time + Whirlpool9, Alpha, Utilisation, BU_factor); 646 double wibu9 = TinsethIBU(Form, postSG, Volume, Amount, flameout_time, flameout_time + Whirlpool9, Alpha, Utilisation, BU_factor);
619 wibu9 *= IBU_reduction(87.0); 647 wibu9 *= IBU_reduction(87.0);
620 //qDebug() << "during whirlpool9" << wibu9; 648 #ifdef DEBUG_IBU
649 qDebug() << "during whirlpool9" << wibu9;
650 #endif
621 ibu += wibu9; 651 ibu += wibu9;
622 } 652 }
623 if (Whirlpool7) { 653 if (Whirlpool7) {
624 double wibu7 = TinsethIBU(Form, postSG, Volume, Amount, flameout_time, flameout_time + Whirlpool7, Alpha, Utilisation, BU_factor); 654 double wibu7 = TinsethIBU(Form, postSG, Volume, Amount, flameout_time, flameout_time + Whirlpool7, Alpha, Utilisation, BU_factor);
625 wibu7 *= IBU_reduction(74.0); 655 wibu7 *= IBU_reduction(74.0);
626 //qDebug() << "during whirlpool7" << wibu7; 656 #ifdef DEBUG_IBU
657 qDebug() << "during whirlpool7" << wibu7;
658 #endif
627 ibu += wibu7; 659 ibu += wibu7;
628 } 660 }
629 if (Whirlpool6) { 661 if (Whirlpool6) {
630 double wibu6 = TinsethIBU(Form, postSG, Volume, Amount, flameout_time, flameout_time + Whirlpool6, Alpha, Utilisation, BU_factor); 662 double wibu6 = TinsethIBU(Form, postSG, Volume, Amount, flameout_time, flameout_time + Whirlpool6, Alpha, Utilisation, BU_factor);
631 wibu6 *= IBU_reduction(63.0); 663 wibu6 *= IBU_reduction(63.0);
632 //qDebug() << "during whirlpool6" << wibu6; 664 #ifdef DEBUG_IBU
665 qDebug() << "during whirlpool6" << wibu6;
666 #endif
633 ibu += wibu6; 667 ibu += wibu6;
634 } 668 }
635 669
636 } else if ((Use == HOP_USEAT_WHIRLPOOL) && (Method > 0)) { 670 } else if ((Use == HOP_USEAT_WHIRLPOOL) && (Method > 0)) {
637 /* 671 /*
638 * Hopstands. 672 * Hopstands.
639 */ 673 */
640 if (Whirlpool9) { 674 if (Whirlpool9) {
641 double wibu9 = TinsethIBU(Form, postSG, Volume, Amount, 0, Whirlpool9, Alpha, Utilisation, BU_factor); 675 double wibu9 = TinsethIBU(Form, postSG, Volume, Amount, 0, Whirlpool9, Alpha, Utilisation, BU_factor);
642 wibu9 *= IBU_reduction(87.0); 676 wibu9 *= IBU_reduction(87.0);
643 //qDebug() << "during whirlpool9" << wibu9; 677 #ifdef DEBUG_IBU
678 qDebug() << "during whirlpool9" << wibu9;
679 #endif
644 ibu = wibu9; 680 ibu = wibu9;
645 } 681 }
646 if (Whirlpool7) { 682 if (Whirlpool7) {
647 double wibu7 = TinsethIBU(Form, postSG, Volume, Amount, 0, Whirlpool7, Alpha, Utilisation, BU_factor); 683 double wibu7 = TinsethIBU(Form, postSG, Volume, Amount, 0, Whirlpool7, Alpha, Utilisation, BU_factor);
648 wibu7 *= IBU_reduction(74.0); 684 wibu7 *= IBU_reduction(74.0);
649 //qDebug() << "during whirlpool7" << wibu7; 685 #ifdef DEBUG_IBU
686 qDebug() << "during whirlpool7" << wibu7;
687 #endif
650 ibu = wibu7; 688 ibu = wibu7;
651 } 689 }
652 if (Whirlpool6) { 690 if (Whirlpool6) {
653 double wibu6 = TinsethIBU(Form, postSG, Volume, Amount, 0, Whirlpool6, Alpha, Utilisation, BU_factor); 691 double wibu6 = TinsethIBU(Form, postSG, Volume, Amount, 0, Whirlpool6, Alpha, Utilisation, BU_factor);
654 wibu6 *= IBU_reduction(63.0); 692 wibu6 *= IBU_reduction(63.0);
655 //qDebug() << "during whirlpool6" << wibu6; 693 #ifdef DEBUG_IBU
694 qDebug() << "during whirlpool6" << wibu6;
695 #endif
656 ibu = wibu6; 696 ibu = wibu6;
657 } 697 }
658 } else if (Use == HOP_USEAT_BOTTLING) { 698 } else if (Use == HOP_USEAT_BOTTLING) {
659 /* 699 /*
660 * Isomerized hop extracts to use at bottling. 700 * Isomerized hop extracts to use at bottling.
670 } 710 }
671 } 711 }
672 712
673 double rc = round(ibu * 1000.0) / 1000.0; 713 double rc = round(ibu * 1000.0) / 1000.0;
674 714
715 #ifdef DEBUG_IBU
675 qDebug() << "toIBU" << Use << Form << preSG << postSG << Volume << Amount << Boiltime << Alpha << Method << Whirlpool9 << Whirlpool7 << Whirlpool6 << Fulltime << Cooltype << CoolTo79 << CoolLPM << Utilisation << BU_factor << "rc:" << rc; 716 qDebug() << "toIBU" << Use << Form << preSG << postSG << Volume << Amount << Boiltime << Alpha << Method << Whirlpool9 << Whirlpool7 << Whirlpool6 << Fulltime << Cooltype << CoolTo79 << CoolLPM << Utilisation << BU_factor << "rc:" << rc;
717 #endif
676 return rc; 718 return rc;
677 } 719 }
678 720
679 721
680 double Utils::hopFlavourContribution(double bt, double vol, int use, double amount, int form) 722 double Utils::hopFlavourContribution(double bt, double vol, int use, double amount, int form)

mercurial