forked from CivPirater/minetest-brewery
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Fermenter.lua
82 lines (77 loc) · 2.96 KB
/
Fermenter.lua
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
-- Crafting Mod - Brewing in Minetest
-- Copyright (C) 2020
--
-- This library is free software; you can redistribute it and/or
-- modify it under the terms of the GNU Lesser General Public
-- License as published by the Free Software Foundation; either
-- version 2.1 of the License, or (at your option) any later version.
--
-- This library is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-- Lesser General Public License for more details.
--
-- You should have received a copy of the GNU Lesser General Public
-- License along with this library; if not, write to the Free Software
-- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
fermenter = {}
function fermenter.calculate_yeast_concentration(time_dif, yeast)
if (yeast == nil) then
error("No yeast passed")
elseif
(yeast.growth_rate == nil or yeast.lag_phase_duration == nil or yeast.death_rate == nil or
yeast.yeast.stationary_phase == nil)
then
error("Yeast can't have nil values")
elseif (time_dif > 0) then
error("Difference in time can't be equal or smaller than 0")
end
return 1 / (1 + math.exp(1) ^ (-yeast.growth_rate * (time_dif - yeast.lag_phase_duration))) +
1 / (1 + math.exp(1) ^ (yeast.death_rate * (time_dif - yeast.stationary_phase))) -
1
end
function fermenter.calculate_alcohol_quantity(time_dif, yeast)
if (yeast == nil) then
error("No yeast passed")
elseif
(yeast.growth_rate == nil or yeast.lag_phase_duration == nil or yeast.death_rate == nil or
yeast.yeast.stationary_phase == nil)
then
error("Yeast can't have nil values")
elseif (time_dif > 0) then
error("Difference in time can't be equal or smaller than 0")
end
return -math.log(math.exp(1) ^ (yeast.death_rate * yeast.stationary_phase - yeast.death_rate * time_dif) + 1) /
yeast.death_rate +
math.log(
math.exp(1) ^ (yeast.growth_rate * time_dif) + math.exp(1) ^ (yeast.growth_rate * yeast.lag_phase_duration)
) /
yeast.growth_rate -
time_dif +
(yeast.stationary_phase - yeast.lag_phase_duration)
end
function fermenter.calculate_alcohol_percentage(time_dif, yeast)
if (yeast == nil) then
error("No yeast passed")
elseif
(yeast.growth_rate == nil or yeast.lag_phase_duration == nil or yeast.death_rate == nil or
yeast.yeast.stationary_phase == nil)
then
error("Yeast can't have nil values")
elseif (time_dif > 0) then
error("Difference in time can't be equal or smaller than 0")
end
return (-math.log(
math.exp(1) ^ (yeast.death_rate * yeast.stationary_phase - yeast.death_rate * time_dif) + 1
) /
yeast.death_rate +
math.log(
math.exp(1) ^ (yeast.growth_rate * time_dif) + math.exp(1) ^ (yeast.growth_rate * yeast.lag_phase_duration)
) /
yeast.growth_rate -
time_dif +
(yeast.stationary_phase - yeast.lag_phase_duration)) /
(yeast.stationary_phase - yeast.lag_phase_duration)
end
function fermenter.register_fermenter()
end