diff -r 4a4cc3497a57 -r 0a5abea575a9 www/includes/formulas.php --- a/www/includes/formulas.php Wed Jan 02 14:49:17 2019 +0100 +++ b/www/includes/formulas.php Wed Jan 02 17:34:53 2019 +0100 @@ -270,40 +270,6 @@ Brouwhulp data.pas -Function THop.FlavourContribution : double; //in % * concentration in g/l -var bt, vol : double; -begin - bt:= FTime.Value; - vol:= 0; - if FRecipe <> NIL then vol:= FRecipe.BatchSize.Value; - if FUse = huFirstWort then Result:= 0.15 * FAmount.Value * 1000 //assume 15% flavourcontribution for fwh - else if bt > 50 then Result:= 0.10 * FAmount.Value * 1000 //assume 10% flavourcontribution as a minimum - else - begin - Result:= 15.25 / (6 * sqrt(2 * PI)) * Exp(-0.5*Power((bt-21)/6, 2)) - * FAmount.Value * 1000; - if result < 0.10 * FAmount.Value * 1000 then - Result:= 0.10 * FAmount.Value * 1000 //assume 10% flavourcontribution as a minimum - end; - if vol > 0 then Result:= Result / vol; -end; - -Function THop.AromaContribution : double; //in % * concentration in g/l -var bt, vol : double; -begin - bt:= FTime.Value; - vol:= 0; - if FRecipe <> NIL then vol:= FRecipe.BatchSize.Value; - if bt > 20 then Result:= 0 - else if bt > 7.5 then - Result:= 10.03 / (4 * sqrt(2 * PI)) * Exp(-0.5*Power((bt-7.5)/4, 2)) - * FAmount.Value * 1000 - else if FUse = huBoil then Result:= FAmount.Value * 1000 - else if FUse = huAroma then Result:= 1.2 * FAmount.Value * 1000 - else if FUse = huWhirlpool then Result:= 1.2 * FAmount.Value * 1000 - else if FUse = huDryHop then Result:= 1.33 * FAmount.Value * 1000; - if vol > 0 then Result:= Result / vol; -end; Procedure TFermentable.SetpHParameters(force : boolean); @@ -439,139 +405,12 @@ end; -Procedure TWater.AddMinerals(Ca, Mg, Na, HCO3, Cl, SO4 : double); -begin - FCalcium.Add(Ca); - FMagnesium.Add(Mg); - FSodium.Add(Na); - FBicarbonate.Add(HCO3); - FChloride.Add(Cl); - FSulfate.Add(SO4); -end; - function TWater.GetResidualAlkalinity: double; begin //Result in mg/l as CaCO3 Result:= FTotalAlkalinity.Value - (FCalcium.Value / 1.4 + FMagnesium.Value / 1.7); end; -const - Ka1 = 0.0000004445; - Ka2 = 0.0000000000468; - -Function PartCO3(pH : double) : double; -var H : double; -begin - H:= Power(10, -pH); - Result:= 100 * Ka1 * Ka2 / (H*H + H * Ka1 + Ka1 * Ka2); -end; - -Function PartHCO3(pH : double) : double; -var H : double; -begin - H:= Power(10, -pH); - Result:= 100 * Ka1 * H / (H*H + H * Ka1 + Ka1 * Ka2); -end; - -Function PartH2CO3(pH : double) : double; -var H : double; -begin - H:= Power(10, -pH); - Result:= 100 * H * H / (H*H + H * Ka1 + Ka1 * Ka2); -end; - -Function Charge(pH : double) : double; -begin - Result:= (-2 * PartCO3(pH) - PartHCO3(pH)); -end; - -//Z alkalinity is the amount of acid (in mEq/l) needed to bring water to the target pH (Z pH) -Function TWater.ZAlkalinity(pHZ : double) : double; //in mEq/l -var CT, DeltaCNaught, DeltaCZ, C43, Cw, Cz : double; -begin - C43:= Charge(4.3); - Cw:= Charge(FpH.Value); - Cz:= Charge(pHz); - DeltaCNaught:= -C43+Cw; - CT:= GetAlkalinity / 50 / DeltaCNaught; - DeltaCZ:= -Cz+Cw; - Result:= CT * DeltaCZ; -end; - -//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) -Function TWater.ZRA(pHZ : double) : double; //in mEq/l -var Calc, Magn, Z : double; -begin - Calc:= FCalcium.Value / (MMCa / 2); - Magn:= FMagnesium.Value / (MMMg / 2); - Z:= ZAlkalinity(pHZ); - Result:= Z - (Calc / 3.5 + Magn / 7); -end; - -Function TWater.ProtonDeficit(pHZ : double) : double; -var i : integer; - F : TFermentable; - x : double; -begin - Result:= ZRA(pHZ) * FAmount.Value; - //proton deficit for the added malts - for i:= 0 to FRecipe.NumFermentables - 1 do - begin - F:= FRecipe.Fermentable[i]; - if (F.AddedType = atMash) and (F.GrainType <> gtNone) then - begin - x:= F.AcidRequired(pHZ) * F.Amount.Value; - Result:= Result + x; - end; - end; -end; - -Function TWater.MashpH : double; -var n : integer; - pd : double; - pH, deltapH, deltapd : double; -begin - Result:= 0; - n:= 0; - pH:= 5.4; - deltapH:= 0.001; - deltapd:= 0.1; - pd:= ProtonDeficit(pH); - while ((pd < -deltapd) or (pd > deltapd)) and (n < 1000) do - begin - inc(n); - if pd < -deltapd then ph:= ph - deltapH - else if pd > deltapd then pH:= pH + deltapH; - pd:= ProtonDeficit(pH); - end; - Result:= pH; -end; - -Function TWater.MashpH2(PrDef : double) : double; -var n : integer; - pd : double; - pH, deltapH, deltapd : double; -begin - Result:= 0; - n:= 0; - pH:= 5.4; - deltapH:= 0.001; - deltapd:= 0.1; - pd:= ProtonDeficit(pH); - while ((pd < PrDef-deltapd) or (pd > PrDef + deltapd)) and (n < 1000) do - begin - inc(n); - if pd < PrDef-deltapd then ph:= ph - deltapH - else if pd > PrDef+deltapd then pH:= pH + deltapH; - pd:= ProtonDeficit(pH); - end; - Result:= pH; -end; - -function TWater.GetAlkalinity: double; -begin - Result := FBicarbonate.Value / 1.22; //mEq/l -end; function TWater.GetHardness: double; begin @@ -593,79 +432,6 @@ end; -function TBeerStyle.GetBUGUMin: double; -var - B, G: double; -begin - Result:= 0; - if ((FOGMax.Value + FOGMin.Value) > 0) and ((FIBUMax.Value + FIBUMin.Value) > 0) then - begin - G := (FOGMax.Value - FOGMin.Value) / ((FOGMax.Value + FOGMin.Value) / 2); - B := (FIBUMax.Value - FIBUMin.Value) / ((FIBUMax.Value + FIBUMin.Value) / 2); - if G > B then - Result := ((FIBUMin.Value + FIBUMax.Value) / 2) / (1000 * (FOGMax.Value - 1)) - else - Result := FIBUMin.Value / (1000 * (((FOGMax.Value + FOGMin.Value) / 2) - 1)); - end; -end; - -function TBeerStyle.GetBUGUMax: double; -var - B, G: double; -begin - Result:= 0; - if ((FOGMax.Value + FOGMin.Value) > 0) and ((FIBUMax.Value + FIBUMin.Value) > 0) - and (FOGMin.Value > 1) then - begin - G := (FOGMax.Value - FOGMin.Value) / ((FOGMax.Value + FOGMin.Value) / 2); - B := (FIBUMax.Value - FIBUMin.Value) / ((FIBUMax.Value + FIBUMin.Value) / 2); - if G > B then - Result := ((FIBUMin.Value + FIBUMax.Value) / 2) / (1000 * (FOGMin.Value - 1)) - else - Result := FIBUMax.Value / (1000 * (((FOGMax.Value + FOGMin.Value) / 2) - 1)); - end; -end; - - - // Get concentration of ions in diluted brewwater (1) and target water (2) in mmol/l - Ca1 := W.Calcium.Value / MMCa; - Ca2 := W2.Calcium.Value / MMCa; - Mg1 := W.Magnesium.Value / MMMg; - Mg2 := W2.Magnesium.Value / MMMg; - Na1 := W.Sodium.Value / MMNa; - Na2 := W2.Sodium.Value / MMNa; - - CO31 := W.Bicarbonate.Value / MMHCO3; - CO32 := W2.Bicarbonate.Value / MMHCO3; - SO41 := W.Sulfate.Value / MMSO4; - SO42 := W2.Sulfate.Value / MMSO4; - Cl1 := W.Sulfate.Value / MMSO4; - Cl2 := W2.Sulfate.Value / MMSO4; - - -procedure TRecipe.CalcWaterBalance; -var - i: integer; - F: TFermentable; -begin - FAbsorbedByGrain := 0; - for i := Low(FFermentables) to High(FFermentables) do - begin - F := TFermentable(FFermentables[i]); - if (F.FermentableType = ftGrain) or (F.FermentableType = ftAdjunct) then - FAbsorbedByGrain := FAbsorbedByGrain + F.Amount.Value; - end; - FAbsorbedByGrain := FAbsorbedByGrain * Settings.GrainAbsorption.Value; - - if FEquipment.CalcBoilVolume.Value then - {FBoilSize.Value := FBatchSize.Value / (1 - (FEquipment.EvapRate.Value / 100) * - (FBoilTime.Value / 60));} - FBoilSize.Value:= FBatchSize.Value + FEquipment.BoilSize.Value - * FEquipment.EvapRate.Value / 100 * - (FBoilTime.Value / 60); -end; - -