66 /* |
66 /* |
67 * First calculate the heat loss for the HLT and MLT liquids. |
67 * First calculate the heat loss for the HLT and MLT liquids. |
68 * Then decrease both liquid temperatures and consider the volume. |
68 * Then decrease both liquid temperatures and consider the volume. |
69 */ |
69 */ |
70 Config.simulator->hlt_temperature -= (Config.simulator->hlt_temperature - Config.simulator->room_temperature) / |
70 Config.simulator->hlt_temperature -= (Config.simulator->hlt_temperature - Config.simulator->room_temperature) / |
71 (40000 * (Config.simulator->hlt_heater_volume / 2)); |
71 (80000 * (Config.simulator->hlt_heater_volume / 2)); |
72 Config.simulator->mlt_temperature -= (Config.simulator->mlt_temperature - Config.simulator->room_temperature) / |
72 Config.simulator->mlt_temperature -= (Config.simulator->mlt_temperature - Config.simulator->room_temperature) / |
73 (40000 * (Config.simulator->mlt_heater_volume / 2)); |
73 (80000 * (Config.simulator->mlt_heater_volume / 2)); |
74 |
74 |
75 /* |
75 /* |
76 * If heating, calculate the heating element temperature but not higher then 250 degrees celcius. |
76 * If heating, calculate the heating element temperature but not higher then 250 degrees celcius. |
77 * I have no data about real temperatures of electric elements, so this is a rough guess. |
77 * I have no data about real temperatures of electric elements, so this is a rough guess. |
78 * If not heating, the elements are couling towards the current liquid temperature. |
78 * If not heating, the elements are couling towards the current liquid temperature. |
79 */ |
79 */ |
80 Config.simulator->hlt_heater_state = SIM_hlt_value; |
80 Config.simulator->hlt_heater_state = SIM_hlt_value; |
81 if (SIM_hlt_value) { |
81 if (SIM_hlt_value) { |
82 Config.simulator->hlt_heater_temp += (250 - Config.simulator->hlt_heater_temp) / 2000; |
82 Config.simulator->hlt_heater_temp += (250 - Config.simulator->hlt_heater_temp) / 2000.0 * (Config.simulator->hlt_heater_power / 2000.0); |
83 } else { |
83 } else { |
84 Config.simulator->hlt_heater_temp -= (Config.simulator->hlt_heater_temp - Config.simulator->hlt_temperature) / 250; |
84 Config.simulator->hlt_heater_temp -= (Config.simulator->hlt_heater_temp - Config.simulator->hlt_temperature) / 250; |
85 } |
85 } |
86 Config.simulator->mlt_heater_state = SIM_mlt_value; |
86 Config.simulator->mlt_heater_state = SIM_mlt_value; |
87 if (SIM_mlt_value) { |
87 if (SIM_mlt_value) { |
88 Config.simulator->mlt_heater_temp += (250 - Config.simulator->mlt_heater_temp) / 2000; |
88 Config.simulator->mlt_heater_temp += (250 - Config.simulator->mlt_heater_temp) / 2000.0 * (Config.simulator->mlt_heater_power / 2000.0); |
89 } else { |
89 } else { |
90 Config.simulator->mlt_heater_temp -= (Config.simulator->mlt_heater_temp - Config.simulator->mlt_temperature) / 250; |
90 Config.simulator->mlt_heater_temp -= (Config.simulator->mlt_heater_temp - Config.simulator->mlt_temperature) / 250; |
91 } |
91 } |
92 |
92 |
93 /* |
93 /* |
94 * If cooling, bring down the MLT temperature. Assume 14 degrees coolwater. |
94 * If cooling, bring down the MLT temperature. Assume 14 degrees coolwater. |
|
95 * The cooler is turned on or off by sending SIGUSR1 or SIGUSR2 to this program. |
95 */ |
96 */ |
96 if (SIM_cooler) { |
97 if (SIM_cooler) { |
97 Config.simulator->mlt_temperature -= (Config.simulator->mlt_temperature - 14) / (175 * Config.simulator->hlt_heater_volume); |
98 Config.simulator->mlt_temperature -= (Config.simulator->mlt_temperature - 14) / (175 * Config.simulator->hlt_heater_volume); |
98 } |
99 } |
99 |
100 |
100 /* |
101 /* |
101 * Shift the liquid temperature towards the heating elements temperature, |
102 * Shift the liquid temperature towards the heating elements temperature, |
102 * but never higher then 100 degrees celcius. |
103 * but never higher then 100 degrees celcius. |
103 */ |
104 */ |
104 Config.simulator->hlt_temperature += (Config.simulator->hlt_heater_temp - Config.simulator->hlt_temperature) / (10000 * Config.simulator->hlt_heater_volume); |
105 Config.simulator->hlt_temperature += (Config.simulator->hlt_heater_temp - Config.simulator->hlt_temperature) / |
|
106 (10000.0 * Config.simulator->hlt_heater_volume * (2000.0 / Config.simulator->hlt_heater_power)); |
105 if (Config.simulator->hlt_temperature > 100.25) |
107 if (Config.simulator->hlt_temperature > 100.25) |
106 Config.simulator->hlt_temperature = 100.25; |
108 Config.simulator->hlt_temperature = 100.25; |
107 Config.simulator->mlt_temperature += (Config.simulator->mlt_heater_temp - Config.simulator->mlt_temperature) / (10000 * Config.simulator->mlt_heater_volume); |
109 Config.simulator->mlt_temperature += (Config.simulator->mlt_heater_temp - Config.simulator->mlt_temperature) / |
|
110 (10000.0 * Config.simulator->mlt_heater_volume * (2000.0 / Config.simulator->mlt_heater_power)); |
108 if (Config.simulator->mlt_temperature > 100.25) |
111 if (Config.simulator->mlt_temperature > 100.25) |
109 Config.simulator->mlt_temperature = 100.25; |
112 Config.simulator->mlt_temperature = 100.25; |
110 |
113 |
111 loops++; |
114 loops++; |
112 now = time(NULL); |
115 now = time(NULL); |
113 if (now != last) { |
116 if (now != last) { |
114 last = now; |
117 last = now; |
115 /* |
118 /* |
116 * Each second |
119 * Each second |
117 */ |
120 */ |
118 // if (debug) |
121 if (debug) |
119 // fprintf(stdout, "HLT temp=%f plate=%f val=%d MLT temp=%f plate=%f val=%d Room %.1f loops=%d cool=%s\n", |
122 fprintf(stdout, "HLT temp=%f plate=%f val=%d MLT temp=%f plate=%f val=%d Room %.1f loops=%d cool=%s\n", |
120 // Config.simulator->hlt_temperature, Config.simulator->hlt_heater_temp, Config.simulator->hlt_heater_state, |
123 Config.simulator->hlt_temperature, Config.simulator->hlt_heater_temp, Config.simulator->hlt_heater_state, |
121 // Config.simulator->mlt_temperature, Config.simulator->mlt_heater_temp, Config.simulator->mlt_heater_state, |
124 Config.simulator->mlt_temperature, Config.simulator->mlt_heater_temp, Config.simulator->mlt_heater_state, |
122 // Config.simulator->room_temperature, loops, SIM_cooler ? "Yes":"No"); |
125 Config.simulator->room_temperature, loops, SIM_cooler ? "Yes":"No"); |
123 loops = 0; |
126 loops = 0; |
124 } |
127 } |
125 usleep(50000); |
128 usleep(50000); |
126 } |
129 } |
127 |
130 |