-
Notifications
You must be signed in to change notification settings - Fork 0
/
Alkalinity.hs
105 lines (79 loc) · 3.16 KB
/
Alkalinity.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
--
-- The code in this module is based on:
--
-- - Description "Wasseraufbereitung" on Maischemalzundmehr.de
-- https://www.maischemalzundmehr.de/index.php?inhaltmitte=toolswasserrechner
--
-- - Braumagazin Frühjahr 2015:
-- http://braumagazin.de/article/von-der-wasseranalyse-zum-brauwasser/
--
module Alkalinity
( MineralContentUnit
, carbonateAlkalinity
, calciumAlkalinity
, magnesiumAlkalinity
, residualAlkalinity
, mmolForResidualAlkalinity
) where
import Common
-- |Common units for mineral content of water
data MineralContentUnit = Unit_mmolPerLiter -- ^ mmol/l
| Unit_mgPerLiter -- ^ mg/l
| Unit_ppm -- ^ ppm
| Unit_mvalPerLiter -- ^ mval/l
| Unit_germanAlkalinity -- ^ °dH
| Unit_frenchAlkalinity -- ^ °fH
deriving (Enum)
-- Molecular and atomic masses
-- |Hydrogen carbonate (g/mol)
molecularMass_HCO3 = 61.0168
-- |Calcium oxide (g/mol)
molecularMass_CaO = 56.0774
-- |Calcium carbonate (g/mol)
molecularMass_CaCO3 = 100.0869
-- |Calcium (u)
atomicMass_Ca = 40.078
-- |Magnesium (u)
atomicMass_Mg = 24.305
-- Derived factors for conversion
-- |mmol/l of CaO corresponding to 1°dH (about 0.1783)
mmol_CaO = 10 / molecularMass_CaO
-- |mmol/l of HCO3 corresponding to 1°dH (about 0.3566)
mmol_HCO3 = 2 * mmol_CaO
-- |mmol/l of CaCO3 corresponding to 1°fH (about 0.0999)
mmol_CaCO3 = 10 / molecularMass_CaCO3
-- |Unit conversion for carbonate alkalinity (°dH).
carbonateAlkalinity :: Double -> MineralContentUnit -> Double
carbonateAlkalinity hco3 unit =
case unit of
Unit_mmolPerLiter -> hco3 / mmol_HCO3
Unit_mgPerLiter -> hco3 / molecularMass_HCO3 / mmol_HCO3
Unit_ppm -> hco3 / molecularMass_HCO3 / mmol_HCO3
Unit_mvalPerLiter -> hco3 / mmol_HCO3
Unit_germanAlkalinity -> hco3
Unit_frenchAlkalinity -> hco3 * mmol_CaCO3 / mmol_CaO
-- |Unit conversion for calcium alkalinity (°dH).
calciumAlkalinity :: Double -> MineralContentUnit -> Double
calciumAlkalinity ca unit =
case unit of
Unit_mmolPerLiter -> ca / mmol_CaO
Unit_mgPerLiter -> ca / atomicMass_Ca / mmol_CaO
Unit_ppm -> ca / atomicMass_Ca / mmol_CaO
Unit_mvalPerLiter -> ca / mmol_HCO3
Unit_germanAlkalinity -> ca
Unit_frenchAlkalinity -> ca * mmol_CaCO3 / mmol_CaO
-- |Unit conversion for magnesium alkalinity (°dH).
magnesiumAlkalinity :: Double -> MineralContentUnit -> Double
magnesiumAlkalinity mg unit =
case unit of
Unit_mmolPerLiter -> mg / mmol_CaO
Unit_mgPerLiter -> mg / atomicMass_Mg / mmol_CaO
Unit_ppm -> mg / atomicMass_Mg / mmol_CaO
Unit_mvalPerLiter -> mg / mmol_HCO3
Unit_germanAlkalinity -> mg
Unit_frenchAlkalinity -> mg * mmol_CaCO3 / mmol_CaO
-- |Compute residual alkalinity from other alkalinities (all values in °dH).
residualAlkalinity alkalinityHCO alkalinityCA alkalinityMG =
alkalinityHCO - ((alkalinityCA + 0.5 * alkalinityMG) / 3.5)
-- |Conversion from °dH to mmol/l for residual alkalinity.
mmolForResidualAlkalinity a = a * mmol_HCO3