'##############
'Heizungs-Script
'##############

'Simuliert Wagenheizung, Zusatzheizung (evtl. auch gleich den Kühlkreislauf mit...)

'(c) 20.02.2009 Rüdiger Hülsmann

'Script Version: 1.1
'Omsi release: 1.0

'Needs:
'cockpit (für Taster und Regler)
'engine (for cooling circuit)
'door (for door opening status)

'Revision History:
'- Rüdiger Hülsmann	17.02.2009	File created
'- Rüdiger Hülsmann	20.02.2009	Batterietrennschalter eingefügt (v1.1)
'- Marcel Kuhnt		10.08.2009	Added Revision History
'- Marcel & Rüdiger	23.09.2010	Parking Heater, room temperature
'- RÜdiger Hülsmann	16.11.2010	Front heater
'- Rüdiger Hülsmann	18.11.2010	Improved front heater
'- Rüdiger Hülsmann	20.11.2010	Cabin heater, values adjusted
'- Rüdiger Hülsmann	22.11.2010	Auxheat Schmitt-triggered, engine coolable by fan heaters
'- Rüdiger Hülsmann	10.01.2011	Driver window airflow

'------------------------------------------------------------------------------------------






'----------------------
'	Init
'----------------------
{macro:heizung_init}
	(L.S.Weather_Temperature) (S.L.Cabinair_Temp)
	(L.S.Weather_AbsHum) (S.L.Cabinair_absHum)
{end}


{macro:heizung_frame}

	(M.L.standheizung_frame)	
	(M.L.cabinair_frame)
{end}








{macro:cabinair_frame}

'	Izraèun stopnje:
	(L.L.Cabinair_Temp) (L.S.Weather_Temperature) - (C.L.cabinair_Qrate_envir_factor) * (S.L.cabinair_Qrate_envir)

'	Neposredna prevodnost toplote iz motorja v prostor za potnike
	(L.L.engine_temperature_envir) (L.L.Cabinair_Temp) - (C.L.cabinair_Qrate_engine_factor) * (S.L.cabinair_Qrate_engine)


'	Izraèunajte temperaturo na grelniku stene
	(L.L.cockpit_heizregler_ventilation_mode) s0 0 =
	{if}
		(L.L.Cabinair_Temp) (L.L.engine_temperature) (L.L.Cabinair_Temp) - (L.L.cockpit_heizregler_temp) * (C.L.heat_exchanger_effectivity) * + (S.L.fanheater_t_target)
	{else}
		l0 2 =
		{if}
'			Svež zrak za ogrevanje:
			(L.S.Weather_Temperature) (L.L.engine_temperature) (L.S.Weather_Temperature) - (L.L.cockpit_heizregler_temp) * (C.L.heat_exchanger_effectivity) * + (S.L.fanheater_t_target)
		{else}
'			Direktno prezraèevanje:
			(L.S.Weather_Temperature) (S.L.fanheater_t_target)
		{endif}		
	{endif}


'Izracun efektivne skupne izmenjave zraka po povrsini:
	(L.L.door_0) (L.L.door_1) (L.L.door_2) (L.L.door_3) + + + (C.L.cabinair_A_perdoor) *

	(L.L.cp_klappfenster_1) (L.L.cp_klappfenster_2) (L.L.cp_klappfenster_3) (L.L.cp_klappfenster_4) + + +
	(L.L.cp_dachluke_1_pos) (L.L.cp_dachluke_2_pos) (L.L.cp_dachluke_3_pos) + 2 * +
	(C.L.cabinair_A_perwindow) * + 
	(C.L.cabinair_A_driverwindow) (L.L.cp_fahrerfenster_pos) * +

'Izracun celotnega toka v zunanjem svetu in obratno (V šteje vsako smer, da se je skupna premakne 2 * V)
	(L.L.velocity) 20 / abs (C.L.cabinair_windowdoor_minkmh) + (C.L.cabinair_windowdoor_effectivity) * 3.6 / * (S.L.cabinair_Vrate_doorwindow)

'Izracuna volumski pretok skozi grelec stene
	(L.L.cockpit_heizregler_ventilation_mode) 1 =
	{if}
		(C.L.cabinair_A_frontheater) (L.L.velocity) 20 / abs (C.L.cabinair_windowdoor_minkmh) + (C.L.cabinair_windowdoor_effectivity) * 3.6 / * (S.L.cabinair_Vrate_fanheater)
	{else}
		(C.L.cabinair_A_frontheater) (L.L.cp_klimator_RPM) 100 / * (S.L.cabinair_Vrate_fanheater)
		(C.L.cabinair_A_frontheater) (L.L.cp_klimator1_RPM) 100 / * (S.L.cabinair_Vrate_fanheater)
		(C.L.cabinair_A_frontheater) (L.L.cp_heizluefter1_sw) 1 = * (S.L.cabinair_Vrate_fanheater)
	{endif}

'Izracuna volumski pretok skozi grelnike prostorov
	(L.L.cp_preklopk_rot) 1 =
	(C.L.cabinair_A_cabinheater) (L.L.cp_heizluefter_sw) 1 = * (L.L.elec_busbar_main) 1 = * (S.L.cabinair_Vrate_cabinheater)



'Izracun stopnje segrevanja temperature z motorjem in sevanja na okolje ...
	(L.L.cabinair_Qrate_engine) (L.L.cabinair_Qrate_envir) - (C.L.cabinair_cvm) /
'...in potniki mero temperature...
	(C.L.cabinair_T_passenger) (L.L.Cabinair_Temp) - (C.L.cabinair_V) / (C.L.cabinair_Vrate_passenger) * (L.L.humans_count) * +
'...in to z obsegom okna in vrata:
	(L.S.Weather_Temperature) (L.L.Cabinair_Temp) - (C.L.cabinair_V) / (L.L.cabinair_Vrate_doorwindow) * +
'...in prednji grelec...
	(L.L.fanheater_t_target) (L.L.Cabinair_Temp) - (C.L.cabinair_V) / (L.L.cabinair_Vrate_fanheater) * +
'...in ogrevala...
	(L.L.engine_temperature) (C.L.heat_exchange_effectivity) * (L.L.Cabinair_Temp) - (C.L.cabinair_V) / (L.L.cabinair_Vrate_cabinheater) * +
'...vkljuciti:
	(L.S.Timegap) * (L.L.Cabinair_Temp) + (S.L.Cabinair_Temp)

'Izracun hitrosti hlajenja motorja skozi toplotni izmenjevalnik v grelnih naprav:

	(L.L.fanheater_t_target) (L.L.Cabinair_Temp) - 0 max (C.L.cabinair_V) / (L.L.cabinair_Vrate_fanheater) * 
	(L.L.engine_temperature) (C.L.heat_exchanger_effectivity) * (L.L.Cabinair_Temp) max (L.L.Cabinair_Temp) - (C.L.cabinair_V) / (L.L.cabinair_Vrate_cabinheater) * +
	(C.L.cabinair_cvm) * 8 * (S.L.cabinair_Qrate_engine_fanheatcooling)



'Izracun stopnje vlage, ki ga dobimo od potnikov:
	(C.L.cabinair_absHum_passenger) (L.L.Cabinair_absHum) - (C.L.cabinair_V) / (C.L.cabinair_Vrate_passenger) * (L.L.humans_count) *
'Izracun stopnje vlage po obsegu tokov z zunanjim svetom:
	(L.S.Weather_AbsHum) (L.L.Cabinair_absHum) - (C.L.cabinair_V) / (L.L.cabinair_Vrate_doorwindow) * +
'Izracun stopnje vlage s stenskim grelnikom
	(L.S.Weather_AbsHum) (L.L.Cabinair_absHum) - (C.L.cabinair_V) / (L.L.cabinair_Vrate_fanheater) * (L.L.cockpit_heizregler_ventilation_mode) 1 >= * + (S.L.cabinair_test)
'... vkljuciti:
	(L.S.Timegap) * (L.L.Cabinair_absHum) + (S.L.Cabinair_absHum)



{end}






{macro:standheizung_frame}


	(L.L.cp_taster_standheizung) (L.L.elec_busbar_avail) &&
	{if}
		(L.L.standheizung_running) !
		{if}
			0 (S.L.standheizung_volume_stufe1) (S.L.standheizung_volume_stufe2)
			1 (S.L.standheizung_running)  
			0 (S.L.standheizung_stufe1_time_elapsed)
			1 (S.L.standheizung_stufe1) 
		{endif}
		1 (S.L.standheizung)
	
	{else}
		0 (S.L.standheizung)
	{endif}
	



'	Raufrödeln èasovnik:
	(L.L.standheizung_running)
	{if}
		(L.L.standheizung_stufe1_time_elapsed) (L.S.Timegap) + (S.L.standheizung_stufe1_time_elapsed)
		(L.L.standheizung_stufe2_time_elapsed) (L.S.Timegap) + (S.L.standheizung_stufe2_time_elapsed)
	{endif}

'	Preklopite na 2. stopnji:
	(L.L.standheizung) (L.L.standheizung_stufe1_time_elapsed) (C.L.standheizung_vorlauf) > &&
	(L.L.engine_temperature) (C.L.standheizung_brenner_t_ein) < &&
	{if}
		(L.L.standheizung_stufe2) !
		{if}
			0 (S.L.standheizung_stufe2_time_elapsed)
		{endif}
		1 (S.L.standheizung_stufe2)
	{endif}

'	Izklopite 2. stopnjo:
	(L.L.standheizung) ! (L.L.standheizung_stufe2_time_elapsed) (C.L.standheizung_minlauf) > &&
	(L.L.engine_temperature) (C.L.standheizung_brenner_t_aus) > ||
	{if}
		(L.L.standheizung_stufe2)
		{if}
			0 (S.L.standheizung_stufe1_time_elapsed)
		{endif}
		0 (S.L.standheizung_stufe2) 
	{endif}

'	Izklopite 1. stopnjo:
	(L.L.standheizung) ! (L.L.standheizung_stufe1_time_elapsed) (C.L.standheizung_nachlauf) > && 
	{if}
		0 (S.L.standheizung_stufe1)
	{endif}

	(L.L.standheizung_stufe1) 
	{if}
		(L.L.standheizung_volume_stufe1) (L.S.Timegap) 3 / + 1 min (S.L.standheizung_volume_stufe1)
	{else}
		(L.L.standheizung_volume_stufe1) (L.S.Timegap) 3 / - 0 max (S.L.standheizung_volume_stufe1)
		0.01 <
		{if}
			0 (S.L.standheizung_running)
		{endif}
	{endif}

	(L.L.standheizung_stufe2) 
	{if}
		(L.L.standheizung_volume_stufe2) (L.S.Timegap) 4 / + 1 min (S.L.standheizung_volume_stufe2)

'		Izraèunaj spremembo temperature:
		(C.L.heizung_Qrate_standheizung) (L.L.cabinair_Qrate_envir) - (C.L.engine_cvm_engine) / (L.S.Timegap) * (L.L.engine_temperature) + (S.L.engine_temperature) 


	{else}
		(L.L.standheizung_volume_stufe2) (L.S.Timegap) 4 / - 0 max (S.L.standheizung_volume_stufe2)
	{endif}



{end}
