@beerwright/core
    Preparing search index...

    Function solveWaterRule

    • Satisfy a water rule exactly, with calcium salts.

      Both conditions are linear in grams of salt, so the rule is a small system with as many equations as unknowns, and isn't over-determined:

      Σ xₛ · (so4ₛ − r · clₛ)  =  r · Cl_source − SO4_source     (the balance)
      Σ xₛ · caₛ = minCa − Ca_source (the floor)

      Gypsum carries sulfate and calcium, calcium chloride carries chloride and calcium, and between them the two rows are exactly determined. It takes one call to the same solveLinearSystem the profile solver uses on its normal equations, and the answer is exact instead of the best of 130 compromises.

      We solve the floor as an equality. Salts only add, so the solution that lands on the floor is the one that clears it with the least salt. Going higher is up to the brewer. When the source already clears the floor we drop that row and one salt sets the balance. Gypsum's coefficient is positive and calcium chloride's is negative, so the sign of the right-hand side picks the salt: gypsum to raise the balance, calcium chloride to lower it, at the smallest dose that gets there.

      This happens in two ways, and the advice differs. The system can ask for a negative dose, when the source has more of one ion than the ratio allows. Salts can't remove an ion, so the fix is dilution. Or the dose can be positive but far too large. Burton's 725 ppm sulfate balances 1:1 against 700 ppm of added chloride. That's arithmetically correct, but it's 40 g of calcium chloride in a 28 L brew, leaving nearly five times the comfortable chloride maximum. We don't report a schedule nobody should weigh out, so a dose past MATERIAL_BREACH_FACTOR (1.5) times an ion's ION_ADVISORY_RANGE_PPM ceiling is refused too. The advice there is a gentler rule, because diluting a water doesn't change its ratio. A schedule that's only uncomfortable stands, with the water's own warning attached.

      Sodium and magnesium salts aren't used. Table salt and Epsom can move the ratio without touching calcium, but they add an ion the rule said nothing about, and a rule that doesn't mention sodium shouldn't add any.

      Like the profile solver, this is deterministic: the same input gives the same schedule, to the last decimal place.

      Parameters

      Returns WaterRuleSolverResult