41 { |
41 { |
42 simulator_list *simulator; |
42 simulator_list *simulator; |
43 time_t now, last = (time_t)0; |
43 time_t now, last = (time_t)0; |
44 int seconds = 0; |
44 int seconds = 0; |
45 double k_room_air, k_beer_air, sqm_room_air, sqm_beer_air, thick_room_air, thick_beer_air, air_heat_transfer, beer_heat_transfer; |
45 double k_room_air, k_beer_air, sqm_room_air, sqm_beer_air, thick_room_air, thick_beer_air, air_heat_transfer, beer_heat_transfer; |
46 double air_change, beer_change, vhc_air = 0.00121, vhc_water = 4.1796; |
46 double air_change, /* beer_change, */ vhc_air = 0.00121 /*, vhc_water = 4.1796 */; |
47 |
47 |
48 syslog(LOG_NOTICE, "Thread my_simulator_loop started"); |
48 syslog(LOG_NOTICE, "Thread my_simulator_loop started"); |
49 if (debug) |
49 if (debug) |
50 fprintf(stdout, "Thread my_simulator_loop started\n"); |
50 fprintf(stdout, "Thread my_simulator_loop started\n"); |
51 |
51 |
77 */ |
77 */ |
78 sqm_room_air = (cbrtl(simulator->volume_air) * cbrtl(simulator->volume_air) * 6) / 100; /* square meters all fridge sides */ |
78 sqm_room_air = (cbrtl(simulator->volume_air) * cbrtl(simulator->volume_air) * 6) / 100; /* square meters all fridge sides */ |
79 thick_room_air = 0.04; /* 4 cm walls */ |
79 thick_room_air = 0.04; /* 4 cm walls */ |
80 k_room_air = 0.03; /* Polystrene */ |
80 k_room_air = 0.03; /* Polystrene */ |
81 air_heat_transfer=(k_room_air * sqm_room_air * (simulator->room_temperature - simulator->air_temperature)) / thick_room_air; |
81 air_heat_transfer=(k_room_air * sqm_room_air * (simulator->room_temperature - simulator->air_temperature)) / thick_room_air; |
82 air_change = air_heat_transfer / (vhc_air * ((simulator->volume_air - simulator->volume_beer) * 1000)); |
82 air_change = (air_heat_transfer / (vhc_air * ((simulator->volume_air - simulator->volume_beer) * 1000))) / 60.0; |
83 simulator->air_temperature += air_change; |
83 simulator->air_temperature += air_change; |
84 |
84 |
85 /* |
85 /* |
86 * If heating, calculate temperature of the heating plate. If heating is off but |
86 * If heating, calculate temperature of the heating plate. If heating is off but |
87 * the plate is warmer then the air, calculate the cooling down temperature. |
87 * the plate is warmer then the air, calculate the cooling down temperature. |
88 * Finally, calculate the new air and plate temperature. |
88 * Finally, calculate the new air and plate temperature. |
89 */ |
89 */ |
90 if (SIMheating) { |
90 if (SIMheating) { |
91 if (simulator->s_heat_temp < simulator->heater_temp) |
91 if (simulator->s_heat_temp < simulator->heater_temp) { |
92 simulator->s_heat_temp += 0.05; |
92 simulator->s_heat_temp += 0.05; |
|
93 if (simulator->s_heat_temp > simulator->air_temperature) |
|
94 simulator->air_temperature += ((simulator->s_heat_temp - simulator->air_temperature) / 100.0); |
|
95 } |
93 } else { |
96 } else { |
94 if (simulator->s_heat_temp > simulator->room_temperature) |
97 /* |
95 simulator->s_heat_temp -= 0.05; |
98 * Follow the air temperature |
|
99 */ |
|
100 simulator->s_heat_temp -= (simulator->s_heat_temp - simulator->air_temperature) / 25.0; |
96 } |
101 } |
97 |
102 |
98 /* |
103 /* |
99 * If cooling, calculate temperature of the cooling plate. If cooling is off but |
104 * If cooling, calculate temperature of the cooling plate. If cooling is off but |
100 * the plate is colder then the air, calculate the warming up temperature. |
105 * the plate is colder then the air, calculate the warming up temperature. |
101 * Finsally, calculate the new air and plate temperature. |
106 * Finsally, calculate the new air and plate temperature. |
102 */ |
107 */ |
103 if (SIMcooling) { |
108 if (SIMcooling) { |
104 if (simulator->s_cool_temp > simulator->cooler_temp) |
109 if (simulator->s_cool_temp > simulator->cooler_temp) { |
105 simulator->s_cool_temp -= 0.05; |
110 simulator->s_cool_temp -= 0.05; |
|
111 if (simulator->s_cool_temp < simulator->air_temperature) |
|
112 simulator->air_temperature -= ((simulator->air_temperature - simulator->s_cool_temp) / 100.0); |
|
113 } |
106 } else { |
114 } else { |
107 if (simulator->s_cool_temp < simulator->room_temperature) |
115 simulator->s_cool_temp -= (simulator->s_cool_temp - simulator->air_temperature) / 25.0; |
108 simulator->s_cool_temp += 0.05; |
|
109 } |
116 } |
110 |
|
111 simulator->air_temperature += ((simulator->s_heat_temp - simulator->air_temperature) / 50.0); |
|
112 simulator->air_temperature -= ((simulator->air_temperature - simulator->s_cool_temp) / 50.0); |
|
113 |
117 |
114 /* |
118 /* |
115 * Calculate the extra beer temperatur rise to simulate the heat produced by the |
119 * Calculate the extra beer temperatur rise to simulate the heat produced by the |
116 * fermentation process. Peak about one day after start and slowly decrease after |
120 * fermentation process. Peak about one day after start and slowly decrease after |
117 * that. |
121 * that. |
118 */ |
122 */ |
119 sqm_beer_air = (cbrtl(simulator->volume_beer) * cbrtl(simulator->volume_beer) * 6) / 100; /* Simple, the beer is in a cubic box */ |
123 sqm_beer_air = (cbrtl(simulator->volume_beer) * cbrtl(simulator->volume_beer) * 6) / 100; /* Simple, the beer is in a cubic box */ |
120 thick_beer_air = 0.001; |
124 thick_beer_air = 0.001; |
121 k_beer_air = 0.5; /* HDPE */ |
125 k_beer_air = 0.5; /* HDPE */ |
122 beer_heat_transfer=(k_beer_air * sqm_beer_air * (simulator->air_temperature - simulator->beer_temperature)) / thick_beer_air; |
126 beer_heat_transfer=(k_beer_air * sqm_beer_air * (simulator->air_temperature - simulator->beer_temperature)) / thick_beer_air; |
123 beer_change = 0; |
127 /* beer_change = 0; */ |
124 |
128 |
125 /* |
129 /* |
126 * Calculate final temperature of the beer and the air. |
130 * Calculate final temperature of the beer and the air. |
127 */ |
131 */ |
128 // Cheap trick, just follow slowly the air temp. |
132 // Cheap trick, just follow slowly the air temp. |
129 simulator->beer_temperature += ((simulator->air_temperature - simulator->beer_temperature) / 200.0); |
133 simulator->beer_temperature += ((simulator->air_temperature - simulator->beer_temperature) / 200.0); |
|
134 simulator->air_temperature += ((simulator->beer_temperature - simulator->air_temperature) / 1000.0); |
130 |
135 |
131 syslog(LOG_NOTICE, "air=%.3f beer=%.3f heater=%.3f cooler=%.3f", simulator->air_temperature, simulator->beer_temperature, |
136 syslog(LOG_NOTICE, "air=%.3f beer=%.3f heater=%.3f cooler=%.3f", simulator->air_temperature, simulator->beer_temperature, |
132 simulator->s_heat_temp, simulator->s_cool_temp); |
137 simulator->s_heat_temp, simulator->s_cool_temp); |
133 |
138 |
134 if (debug) |
139 if (debug) |