Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void TMoverParameters::dizel_Heat( double const dt ) {
- auto const qs { 44700.0 };
- auto const Cs { 11000.0 };
- auto const Cw { 4.189 };
- auto const Co { 1.885 };
- auto const gwmin { 400.0 };
- auto const gwmax { 4000.0 };
- auto const gwmin2 { 400.0 };
- auto const gwmax2 { 4000.0 };
- dizel_heat.Te = Global.AirTemperature;
- auto const engineon { ( Mains ? 1 : 0 ) };
- auto const engineoff { ( Mains ? 0 : 1 ) };
- auto const rpm { enrot * 60 };
- // TODO: calculate this once and cache for further use, instead of doing it repeatedly all over the place
- auto const maxrevolutions { (
- EngineType == TEngineType::DieselEngine ? dizel_nmax * 60 :
- EngineType == TEngineType::DieselElectric ? DElist[ MainCtrlPosNo ].RPM :
- std::numeric_limits<double>::max() ) }; // shouldn't ever get here but, eh
- auto const revolutionsfactor { clamp( rpm / maxrevolutions, 0.0, 1.0 ) };
- auto const waterpump { WaterPump.is_active ? 1 : 0 };
- auto const gw = engineon * interpolate( gwmin, gwmax, revolutionsfactor ) + waterpump * 1000 + engineoff * 200;
- auto const gw2 = engineon * interpolate( gwmin2, gwmax2, revolutionsfactor ) + waterpump * 1000 + engineoff * 200;
- auto const gwO = interpolate( gwmin, gwmax, revolutionsfactor );
- dizel_heat.water.is_cold = (
- ( dizel_heat.water.config.temp_min > 0 )
- && ( dizel_heat.temperatura1 < dizel_heat.water.config.temp_min - ( Mains ? 5 : 0 ) ) );
- dizel_heat.water.is_hot = (
- ( dizel_heat.water.config.temp_max > 0 )
- && ( dizel_heat.temperatura1 > dizel_heat.water.config.temp_max - ( dizel_heat.water.is_hot ? 8 : 0 ) ) );
- dizel_heat.water_aux.is_cold = (
- ( dizel_heat.water_aux.config.temp_min > 0 )
- && ( dizel_heat.temperatura2 < dizel_heat.water_aux.config.temp_min - ( Mains ? 5 : 0 ) ) );
- dizel_heat.water_aux.is_hot = (
- ( dizel_heat.water_aux.config.temp_max > 0 )
- && ( dizel_heat.temperatura2 > dizel_heat.water_aux.config.temp_max - ( dizel_heat.water_aux.is_hot ? 8 : 0 ) ) );
- dizel_heat.oil.is_cold = (
- ( dizel_heat.oil.config.temp_min > 0 )
- && ( dizel_heat.To < dizel_heat.oil.config.temp_min - ( Mains ? 5 : 0 ) ) );
- dizel_heat.oil.is_hot = (
- ( dizel_heat.oil.config.temp_max > 0 )
- && ( dizel_heat.To > dizel_heat.oil.config.temp_max - ( dizel_heat.oil.is_hot ? 8 : 0 ) ) );
- auto const PT = (
- ( false == dizel_heat.water.is_cold )
- && ( false == dizel_heat.water.is_hot )
- && ( false == dizel_heat.water_aux.is_cold )
- && ( false == dizel_heat.water_aux.is_hot )
- && ( false == dizel_heat.oil.is_cold )
- && ( false == dizel_heat.oil.is_hot ) /* && ( false == awaria_termostatow ) */ ) /* || PTp */;
- auto const PPT = ( false == PT ) /* && ( false == PPTp ) */;
- dizel_heat.PA = ( /* ( ( !zamkniecie or niedomkniecie ) and !WBD ) || */ PPT /* || nurnik || ( woda < 7 ) */ ) /* && ( !PAp ) */;
- // engine heat transfers
- auto const Ge { engineon * ( 0.21 * EnginePower + 12 ) / 3600 };
- // TODO: replace fixed heating power cost with more accurate calculation
- auto const obciazenie { engineon * ( ( EnginePower / 950 ) + ( Heating ? HeatingPower : 0 ) + 70 ) };
- auto const Qd { qs * Ge - obciazenie };
- // silnik oddaje czesc ciepla do wody chlodzacej, a takze pewna niewielka czesc do otoczenia, modyfikowane przez okienko
- auto const Qs { ( Qd - ( dizel_heat.kfs * ( dizel_heat.Ts - dizel_heat.Tsr ) ) - ( dizel_heat.kfe * /* ( 0.3 + 0.7 * ( dizel_heat.okienko ? 1 : 0 ) ) * */ ( dizel_heat.Ts - dizel_heat.Te ) ) ) };
- auto const dTss { Qs / Cs };
- dizel_heat.Ts += ( dTss * dt );
- // oil heat transfers
- // olej oddaje cieplo do wody gdy krazy przez wymiennik ciepla == wlaczona pompka lub silnik
- auto const dTo { (
- dizel_heat.auxiliary_water_circuit ?
- ( ( dizel_heat.kfo * ( dizel_heat.Ts - dizel_heat.To ) ) - ( dizel_heat.kfo2 * ( dizel_heat.To - dizel_heat.Tsr2 ) ) ) / ( gwO * Co ) :
- ( ( dizel_heat.kfo * ( dizel_heat.Ts - dizel_heat.To ) ) - ( dizel_heat.kfo2 * ( dizel_heat.To - dizel_heat.Tsr ) ) ) / ( gwO * Co ) ) };
- dizel_heat.To += ( dTo * dt );
- // heater
- /*
- if( typ == "SP45" )
- Qp = (float)( podgrzewacz and ( true == WaterPump.is_active ) and ( Twy < 55 ) and ( Twy2 < 55 ) ) * 1000;
- else
- */
- auto const Qp = ( ( ( true == WaterHeater.is_active ) && ( true == WaterPump.is_active ) && ( dizel_heat.Twy < 60 ) && ( dizel_heat.Twy2 < 60 ) ) ? 1 : 0 ) * 1000;
- auto const kurek07 { 1 }; // unknown/unimplemented device TBD, TODO: identify and implement?
- if( true == dizel_heat.auxiliary_water_circuit ) {
- // auxiliary water circuit setup
- dizel_heat.water_aux.is_warm = (
- ( true == dizel_heat.cooling )
- || ( ( true == Mains )
- && ( BatteryVoltage > ( 0.75 * NominalBatteryVoltage ) ) /* && !bezpompy && !awaria_chlodzenia && !WS10 */
- && ( dizel_heat.water_aux.config.temp_cooling > 0 )
- && ( dizel_heat.temperatura2 > dizel_heat.water_aux.config.temp_cooling - ( dizel_heat.water_aux.is_warm ? 8 : 0 ) ) ) );
- auto const PTC2 { ( dizel_heat.water_aux.is_warm /*or PTC2p*/ ? 1 : 0 ) };
- dizel_heat.rpmwz2 = PTC2 * ( dizel_heat.fan_speed >= 0 ? ( rpm * dizel_heat.fan_speed ) : ( dizel_heat.fan_speed * -1 ) );
- dizel_heat.zaluzje2 = ( dizel_heat.water_aux.config.shutters ? ( PTC2 == 1 ) : true ); // no shutters is an equivalent to having them open
- auto const zaluzje2 { ( dizel_heat.zaluzje2 ? 1 : 0 ) };
- // auxiliary water circuit heat transfer values
- auto const kf2 { kurek07 * ( ( dizel_heat.kw * ( 0.3 + 0.7 * zaluzje2 ) ) * dizel_heat.rpmw2 + ( dizel_heat.kv * ( 0.3 + 0.7 * zaluzje2 ) * Vel / 3.6 ) ) + 2 };
- auto const dTs2 { ( ( dizel_heat.kfo2 * ( dizel_heat.To - dizel_heat.Tsr2 ) ) ) / ( gw2 * Cw ) };
- // przy otwartym kurku B ma³y obieg jest dogrzewany przez du¿y - stosujemy przy korzystaniu z podgrzewacza oraz w zimie
- auto const Qch2 { -kf2 * ( dizel_heat.Tsr2 - dizel_heat.Te ) + ( 80 * ( true == WaterCircuitsLink ? 1 : 0 ) * ( dizel_heat.Twy - dizel_heat.Tsr2 ) ) };
- auto const dTch2 { Qch2 / ( gw2 * Cw ) };
- // auxiliary water circuit heat transfers finalization
- // NOTE: since primary circuit doesn't read data from the auxiliary one, we can pretty safely finalize auxiliary updates before touching the primary circuit
- auto const Twe2 { dizel_heat.Twy2 + ( dTch2 * dt ) };
- dizel_heat.Twy2 = Twe2 + ( dTs2 * dt );
- dizel_heat.Tsr2 = 0.5 * ( dizel_heat.Twy2 + Twe2 );
- dizel_heat.temperatura2 = dizel_heat.Twy2;
- }
- // primary water circuit setup
- dizel_heat.water.is_flowing = (
- ( dizel_heat.water.config.temp_flow < 0 )
- || ( dizel_heat.temperatura1 > dizel_heat.water.config.temp_flow - ( dizel_heat.water.is_flowing ? 5 : 0 ) ) );
- auto const obieg { ( dizel_heat.water.is_flowing ? 1 : 0 ) };
- dizel_heat.water.is_warm = (
- ( true == dizel_heat.cooling )
- || ( ( true == Mains )
- && ( BatteryVoltage > ( 0.75 * NominalBatteryVoltage ) ) /* && !bezpompy && !awaria_chlodzenia && !WS10 */
- && ( dizel_heat.water.config.temp_cooling > 0 )
- && ( dizel_heat.temperatura1 > dizel_heat.water.config.temp_cooling - ( dizel_heat.water.is_warm ? 8 : 0 ) ) ) );
- auto const PTC1 { ( dizel_heat.water.is_warm /*or PTC1p*/ ? 1 : 0 ) };
- dizel_heat.rpmwz = PTC1 * ( dizel_heat.fan_speed >= 0 ? ( rpm * dizel_heat.fan_speed ) : ( dizel_heat.fan_speed * -1 ) );
- dizel_heat.zaluzje1 = ( dizel_heat.water.config.shutters ? ( PTC1 == 1 ) : true ); // no shutters is an equivalent to having them open
- auto const zaluzje1 { ( dizel_heat.zaluzje1 ? 1 : 0 ) };
- // primary water circuit heat transfer values
- auto const kf { obieg * kurek07 * ( ( dizel_heat.kw * ( 0.3 + 0.7 * zaluzje1 ) ) * dizel_heat.rpmw + ( dizel_heat.kv * ( 0.3 + 0.7 * zaluzje1 ) * Vel / 3.6 ) + 3 ) + 2 };
- auto const dTs { (
- dizel_heat.auxiliary_water_circuit ?
- ( ( dizel_heat.kfs * ( dizel_heat.Ts - dizel_heat.Tsr ) ) ) / ( gw * Cw ) :
- ( ( dizel_heat.kfs * ( dizel_heat.Ts - dizel_heat.Tsr ) ) + ( dizel_heat.kfo2 * ( dizel_heat.To - dizel_heat.Tsr ) ) ) / ( gw * Cw ) ) };
- auto const Qch { -kf * ( dizel_heat.Tsr - dizel_heat.Te ) + Qp };
- auto const dTch { Qch / ( gw * Cw ) };
- // primary water circuit heat transfers finalization
- auto const Twe { dizel_heat.Twy + ( dTch * dt ) };
- dizel_heat.Twy = Twe + ( dTs * dt );
- dizel_heat.Tsr = 0.5 * ( dizel_heat.Twy + Twe );
- dizel_heat.temperatura1 = dizel_heat.Twy;
- /*
- fuelConsumed = fuelConsumed + ( Ge * 0.5 );
- while( fuelConsumed >= 0.83 ) {
- fuelConsumed = fuelConsumed - 0.83;
- fuelQueue.DestroyProductMatching( null, 1 );
- }//if
- if( engineon )
- temp_turbo = temp_turbo + 0.3 * ( t_pozycja );
- if( t_pozycja == 0 and cisnienie > 0.04 )
- temp_turbo = temp_turbo - 1;
- if( temp_turbo > 400 )
- temp_turbo = 400;
- if( temp_turbo < 0 )
- temp_turbo = 0;
- if( temp_turbo > 50 and cisnienie < 0.05 )
- timer_turbo = timer_turbo + 1;
- if( temp_turbo == 0 )
- timer_turbo = 0;
- if( timer_turbo > 360 ) {
- awaria_turbo = true;
- timer_turbo = 400;
- }
- if( Ts < 50 )
- p_odpal = 3;
- if( Ts > 49 and Ts < 76 )
- p_odpal = 4;
- if( Ts > 75 )
- p_odpal = 7;
- stukanie = stukanie or awaria_oleju;
- if( awaria_oleju == true and ilosc_oleju > 0 ) {
- ilosc_oleju = ilosc_oleju - ( 0.002 * rpm / 1500 );
- }
- if( awaria_oleju == true and cisnienie < 0.06 )
- damage = 1;
- */
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement