Advertisement
JachyHm

Maszyna teplota dizelu

Jul 4th, 2019
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 9.72 KB | None | 0 0
  1. void TMoverParameters::dizel_Heat( double const dt ) {
  2.  
  3.     auto const qs { 44700.0 };
  4.     auto const Cs { 11000.0 };
  5.     auto const Cw { 4.189 };
  6.     auto const Co { 1.885 };
  7.     auto const gwmin { 400.0 };
  8.     auto const gwmax { 4000.0 };
  9.     auto const gwmin2 { 400.0 };
  10.     auto const gwmax2 { 4000.0 };
  11.  
  12.     dizel_heat.Te = Global.AirTemperature;
  13.  
  14.     auto const engineon { ( Mains ? 1 : 0 ) };
  15.     auto const engineoff { ( Mains ? 0 : 1 ) };
  16.     auto const rpm { enrot * 60 };
  17.     // TODO: calculate this once and cache for further use, instead of doing it repeatedly all over the place
  18.     auto const maxrevolutions { (
  19.         EngineType == TEngineType::DieselEngine ? dizel_nmax * 60 :
  20.         EngineType == TEngineType::DieselElectric ? DElist[ MainCtrlPosNo ].RPM :
  21.         std::numeric_limits<double>::max() ) }; // shouldn't ever get here but, eh
  22.     auto const revolutionsfactor { clamp( rpm / maxrevolutions, 0.0, 1.0 ) };
  23.     auto const waterpump { WaterPump.is_active ? 1 : 0 };
  24.  
  25.     auto const gw = engineon * interpolate( gwmin, gwmax, revolutionsfactor ) + waterpump * 1000 + engineoff * 200;
  26.     auto const gw2 = engineon * interpolate( gwmin2, gwmax2, revolutionsfactor ) + waterpump * 1000 + engineoff * 200;
  27.     auto const gwO = interpolate( gwmin, gwmax, revolutionsfactor );
  28.  
  29.     dizel_heat.water.is_cold = (
  30.         ( dizel_heat.water.config.temp_min > 0 )
  31.      && ( dizel_heat.temperatura1 < dizel_heat.water.config.temp_min - ( Mains ? 5 : 0 ) ) );
  32.     dizel_heat.water.is_hot = (
  33.         ( dizel_heat.water.config.temp_max > 0 )
  34.      && ( dizel_heat.temperatura1 > dizel_heat.water.config.temp_max - ( dizel_heat.water.is_hot ? 8 : 0 ) ) );
  35.     dizel_heat.water_aux.is_cold = (
  36.         ( dizel_heat.water_aux.config.temp_min > 0 )
  37.      && ( dizel_heat.temperatura2 < dizel_heat.water_aux.config.temp_min - ( Mains ? 5 : 0 ) ) );
  38.     dizel_heat.water_aux.is_hot = (
  39.         ( dizel_heat.water_aux.config.temp_max > 0 )
  40.      && ( dizel_heat.temperatura2 > dizel_heat.water_aux.config.temp_max - ( dizel_heat.water_aux.is_hot ? 8 : 0 ) ) );
  41.     dizel_heat.oil.is_cold = (
  42.         ( dizel_heat.oil.config.temp_min > 0 )
  43.      && ( dizel_heat.To < dizel_heat.oil.config.temp_min - ( Mains ? 5 : 0 ) ) );
  44.     dizel_heat.oil.is_hot = (
  45.         ( dizel_heat.oil.config.temp_max > 0 )
  46.      && ( dizel_heat.To > dizel_heat.oil.config.temp_max - ( dizel_heat.oil.is_hot ? 8 : 0 ) ) );
  47.  
  48.     auto const PT = (
  49.         ( false == dizel_heat.water.is_cold )
  50.      && ( false == dizel_heat.water.is_hot )
  51.      && ( false == dizel_heat.water_aux.is_cold )
  52.      && ( false == dizel_heat.water_aux.is_hot )
  53.      && ( false == dizel_heat.oil.is_cold )
  54.      && ( false == dizel_heat.oil.is_hot ) /* && ( false == awaria_termostatow ) */ ) /* || PTp */;
  55.     auto const PPT = ( false == PT ) /* && ( false == PPTp ) */;
  56.     dizel_heat.PA = ( /* ( ( !zamkniecie or niedomkniecie ) and !WBD ) || */ PPT /* || nurnik || ( woda < 7 ) */ ) /* && ( !PAp ) */;
  57.  
  58.     // engine heat transfers
  59.     auto const Ge { engineon * ( 0.21 * EnginePower + 12 ) / 3600 };
  60.     // TODO: replace fixed heating power cost with more accurate calculation
  61.     auto const obciazenie { engineon * ( ( EnginePower / 950 ) + ( Heating ? HeatingPower : 0 ) + 70 ) };
  62.     auto const Qd { qs * Ge - obciazenie };
  63.     // silnik oddaje czesc ciepla do wody chlodzacej, a takze pewna niewielka czesc do otoczenia, modyfikowane przez okienko
  64.     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 ) ) ) };
  65.     auto const dTss { Qs / Cs };
  66.     dizel_heat.Ts += ( dTss * dt );
  67.  
  68.     // oil heat transfers
  69.     // olej oddaje cieplo do wody gdy krazy przez wymiennik ciepla == wlaczona pompka lub silnik
  70.     auto const dTo { (
  71.         dizel_heat.auxiliary_water_circuit ?
  72.             ( ( dizel_heat.kfo * ( dizel_heat.Ts - dizel_heat.To ) ) - ( dizel_heat.kfo2 * ( dizel_heat.To - dizel_heat.Tsr2 ) ) ) / ( gwO * Co ) :
  73.             ( ( dizel_heat.kfo * ( dizel_heat.Ts - dizel_heat.To ) ) - ( dizel_heat.kfo2 * ( dizel_heat.To - dizel_heat.Tsr ) ) ) / ( gwO * Co ) ) };
  74.     dizel_heat.To += ( dTo * dt );
  75.  
  76.     // heater
  77. /*
  78.     if( typ == "SP45" )
  79.         Qp = (float)( podgrzewacz and ( true == WaterPump.is_active ) and ( Twy < 55 ) and ( Twy2 < 55 ) ) * 1000;
  80.     else
  81. */
  82.         auto const Qp = ( ( ( true == WaterHeater.is_active ) && ( true == WaterPump.is_active ) && ( dizel_heat.Twy < 60 ) && ( dizel_heat.Twy2 < 60 ) ) ? 1 : 0 ) * 1000;
  83.  
  84.     auto const kurek07 { 1 }; // unknown/unimplemented device TBD, TODO: identify and implement?
  85.  
  86.     if( true == dizel_heat.auxiliary_water_circuit ) {
  87.         // auxiliary water circuit setup
  88.         dizel_heat.water_aux.is_warm = (
  89.             ( true == dizel_heat.cooling )
  90.          || ( ( true == Mains )
  91.            && ( BatteryVoltage > ( 0.75 * NominalBatteryVoltage ) ) /* && !bezpompy && !awaria_chlodzenia && !WS10 */
  92.            && ( dizel_heat.water_aux.config.temp_cooling > 0 )
  93.            && ( dizel_heat.temperatura2 > dizel_heat.water_aux.config.temp_cooling - ( dizel_heat.water_aux.is_warm ? 8 : 0 ) ) ) );
  94.         auto const PTC2 { ( dizel_heat.water_aux.is_warm /*or PTC2p*/ ? 1 : 0 ) };
  95.         dizel_heat.rpmwz2 = PTC2 * ( dizel_heat.fan_speed >= 0 ? ( rpm * dizel_heat.fan_speed ) : ( dizel_heat.fan_speed * -1 ) );
  96.         dizel_heat.zaluzje2 = ( dizel_heat.water_aux.config.shutters ? ( PTC2 == 1 ) : true ); // no shutters is an equivalent to having them open
  97.         auto const zaluzje2 { ( dizel_heat.zaluzje2 ? 1 : 0 ) };
  98.         // auxiliary water circuit heat transfer values
  99.         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 };
  100.         auto const dTs2 { ( ( dizel_heat.kfo2 * ( dizel_heat.To - dizel_heat.Tsr2 ) ) ) / ( gw2 * Cw ) };
  101.         // przy otwartym kurku B ma³y obieg jest dogrzewany przez du¿y - stosujemy przy korzystaniu z podgrzewacza oraz w zimie
  102.         auto const Qch2 { -kf2 * ( dizel_heat.Tsr2 - dizel_heat.Te ) + ( 80 * ( true == WaterCircuitsLink ? 1 : 0 ) * ( dizel_heat.Twy - dizel_heat.Tsr2 ) ) };
  103.         auto const dTch2 { Qch2 / ( gw2 * Cw ) };
  104.         // auxiliary water circuit heat transfers finalization
  105.         // NOTE: since primary circuit doesn't read data from the auxiliary one, we can pretty safely finalize auxiliary updates before touching the primary circuit
  106.         auto const Twe2 { dizel_heat.Twy2 + ( dTch2 * dt ) };
  107.         dizel_heat.Twy2 = Twe2 + ( dTs2 * dt );
  108.         dizel_heat.Tsr2 = 0.5 * ( dizel_heat.Twy2 + Twe2 );
  109.         dizel_heat.temperatura2 = dizel_heat.Twy2;
  110.     }
  111.     // primary water circuit setup
  112.     dizel_heat.water.is_flowing = (
  113.         ( dizel_heat.water.config.temp_flow < 0 )
  114.      || ( dizel_heat.temperatura1 > dizel_heat.water.config.temp_flow - ( dizel_heat.water.is_flowing ? 5 : 0 ) ) );
  115.     auto const obieg { ( dizel_heat.water.is_flowing ? 1 : 0 ) };
  116.     dizel_heat.water.is_warm = (
  117.         ( true == dizel_heat.cooling )
  118.      || ( ( true == Mains )
  119.        && ( BatteryVoltage > ( 0.75 * NominalBatteryVoltage ) ) /* && !bezpompy && !awaria_chlodzenia && !WS10 */
  120.        && ( dizel_heat.water.config.temp_cooling > 0 )
  121.        && ( dizel_heat.temperatura1 > dizel_heat.water.config.temp_cooling - ( dizel_heat.water.is_warm ? 8 : 0 ) ) ) );
  122.     auto const PTC1 { ( dizel_heat.water.is_warm /*or PTC1p*/ ? 1 : 0 ) };
  123.     dizel_heat.rpmwz = PTC1 * ( dizel_heat.fan_speed >= 0 ? ( rpm * dizel_heat.fan_speed ) : ( dizel_heat.fan_speed * -1 ) );
  124.     dizel_heat.zaluzje1 = ( dizel_heat.water.config.shutters ? ( PTC1 == 1 ) : true ); // no shutters is an equivalent to having them open
  125.     auto const zaluzje1 { ( dizel_heat.zaluzje1 ? 1 : 0 ) };
  126.     // primary water circuit heat transfer values
  127.     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 };
  128.     auto const dTs { (
  129.         dizel_heat.auxiliary_water_circuit ?
  130.             ( ( dizel_heat.kfs * ( dizel_heat.Ts - dizel_heat.Tsr ) ) ) / ( gw * Cw ) :
  131.             ( ( dizel_heat.kfs * ( dizel_heat.Ts - dizel_heat.Tsr ) ) + ( dizel_heat.kfo2 * ( dizel_heat.To - dizel_heat.Tsr ) ) ) / ( gw * Cw ) ) };
  132.     auto const Qch { -kf * ( dizel_heat.Tsr - dizel_heat.Te ) + Qp };
  133.     auto const dTch { Qch / ( gw * Cw ) };
  134.     // primary water circuit heat transfers finalization
  135.     auto const Twe { dizel_heat.Twy + ( dTch * dt ) };
  136.     dizel_heat.Twy = Twe + ( dTs * dt );
  137.     dizel_heat.Tsr = 0.5 * ( dizel_heat.Twy + Twe );
  138.     dizel_heat.temperatura1 = dizel_heat.Twy;
  139. /*
  140.     fuelConsumed = fuelConsumed + ( Ge * 0.5 );
  141.  
  142.     while( fuelConsumed >= 0.83 ) {
  143.         fuelConsumed = fuelConsumed - 0.83;
  144.         fuelQueue.DestroyProductMatching( null, 1 );
  145.     }//if
  146.  
  147.     if( engineon )
  148.         temp_turbo = temp_turbo + 0.3 * ( t_pozycja );
  149.     if( t_pozycja == 0 and cisnienie > 0.04 )
  150.         temp_turbo = temp_turbo - 1;
  151.  
  152.     if( temp_turbo > 400 )
  153.         temp_turbo = 400;
  154.     if( temp_turbo < 0 )
  155.         temp_turbo = 0;
  156.  
  157.     if( temp_turbo > 50 and cisnienie < 0.05 )
  158.         timer_turbo = timer_turbo + 1;
  159.  
  160.     if( temp_turbo == 0 )
  161.         timer_turbo = 0;
  162.  
  163.     if( timer_turbo > 360 ) {
  164.         awaria_turbo = true;
  165.         timer_turbo = 400;
  166.     }
  167.  
  168.     if( Ts < 50 )
  169.         p_odpal = 3;
  170.     if( Ts > 49 and Ts < 76 )
  171.         p_odpal = 4;
  172.     if( Ts > 75 )
  173.         p_odpal = 7;
  174.  
  175.     stukanie = stukanie or awaria_oleju;
  176.  
  177.     if( awaria_oleju == true and ilosc_oleju > 0 ) {
  178.         ilosc_oleju = ilosc_oleju - ( 0.002 * rpm / 1500 );
  179.     }
  180.     if( awaria_oleju == true and cisnienie < 0.06 )
  181.         damage = 1;
  182. */
  183. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement