Elvas Tower: Looking for FCalC code - Elvas Tower

Jump to content

  • 2 Pages +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

Looking for FCalC code Rate Topic: -----

#11 User is offline   NickonWheels 

  • Conductor
  • Group: Status: Active Member
  • Posts: 327
  • Joined: 05-December 19
  • Gender:Male
  • Simulator:ORTS
  • Country:

Posted 02 April 2020 - 07:14 AM

FCalc 2.0 Standard Freight.xls does contain the equation for C2, but uses fixed values for E2, which the actual program does not. Still something missing...

#12 User is offline   dajones 

  • Open Rails Developer
  • Group: Status: Contributing Member
  • Posts: 413
  • Joined: 27-February 08
  • Gender:Male
  • Location:Durango, CO
  • Country:

Posted 02 April 2020 - 09:58 AM

Based on the description in the document, it looks like E2 was calculated numerically to minimize the squared difference between the davis equation and the MSTS equation. In other words, pick a value for E2. Loop over all integer speeds from 5 to 80 mph and calculate the difference between the davis equation and the MSTS equation. Sum the square of this difference over all speeds. Then pick a different value for E2 and repeat the calculation. Select the E2 that gives the smaller sum. Repeat until the sum doesn't change too much.

The hard part is picking good E2 values. I'm not sure what method the fcalc code used, but I would probably use golden section search.

Doug

#13 User is offline   NickonWheels 

  • Conductor
  • Group: Status: Active Member
  • Posts: 327
  • Joined: 05-December 19
  • Gender:Male
  • Simulator:ORTS
  • Country:

Posted 02 April 2020 - 10:41 AM

Thanks for your advise

I managed to download the source code from UKTS and now looking through it, hope I can find the missing pieces.

#14 User is offline   Genma Saotome 

  • Owner Emeritus and Admin
  • PipPipPipPipPipPipPipPipPipPipPipPipPip
  • Group: ET Admin
  • Posts: 15,308
  • Joined: 11-January 04
  • Gender:Male
  • Location:United States
  • Simulator:Open Rails
  • Country:

Posted 02 April 2020 - 11:27 AM

 NickonWheels, on 02 April 2020 - 04:29 AM, said:

Well, I have read Methodology and Theory of FCalc 2.txt to the best of my understanding. FCalC puts out five values termed C1, E1, V2, C2, E2.


Those are MSTS parameters, not Davis parameters. In the early stages of creating FCalc OR was not on the scene and the objective was values for MSTS's Friction() parameter. That is NOT the same as Davis -- close, but different.

AFAIK what you want to produce are the A, B, C values going into OR.

#15 User is offline   ebnertra000 

  • Superintendant
  • Group: Status: Elite Member
  • Posts: 1,234
  • Joined: 27-February 17
  • Gender:Male
  • Location:East-Central Minnesota
  • Simulator:OR/TSRE
  • Country:

Posted 02 April 2020 - 12:36 PM

I'm pretty sure there is an option in FCalc specifically for Davis Coefficients. Unless that's not in all versions...that could be

#16 User is offline   R H Steele 

  • Executive Vice President
  • PipPipPipPipPipPipPipPipPip
  • Group: ET Admin
  • Posts: 3,404
  • Joined: 14-March 13
  • Gender:Male
  • Location:known universe
  • Simulator:Open Rails
  • Country:

Posted 02 April 2020 - 03:38 PM

 ebnertra000, on 02 April 2020 - 12:36 PM, said:

I'm pretty sure there is an option in FCalc specifically for Davis Coefficients. Unless that's not in all versions...that could be

Yes there is Menu\View\Check Davis coefficients Using FCalc2 ver#2.0.2139.34987 (found under Help )


#17 User is offline   NickonWheels 

  • Conductor
  • Group: Status: Active Member
  • Posts: 327
  • Joined: 05-December 19
  • Gender:Male
  • Simulator:ORTS
  • Country:

Posted 03 April 2020 - 12:37 AM

 Genma Saotome, on 02 April 2020 - 11:27 AM, said:

Those are MSTS parameters, not Davis parameters. In the early stages of creating FCalc OR was not on the scene and the objective was values for MSTS's Friction() parameter. That is NOT the same as Davis -- close, but different.

AFAIK what you want to produce are the A, B, C values going into OR.


No, I´m indeed looking for the old MSTS parameters in order to get around ORTS Davis lines because of their inappropriate way to define starting resistance and principally non-working private ORTS versions. I finally found the code, but it looks needlessly complicated, mostly because of speed settings everywhere. For Davis lines speed settings don´t matter so there is need to replace them with some general value but this obviously does not work...again

/* Quickly estimate optimum e2 value using midpoint values of vequal and v2 */

    c1_temp=0;
    c2_temp=0;
    e2_temp=1.0;
    v2_temp=0.5*(v2_max + v2_min);
    vequal=0.5*(speed_range + 13.4112);
    speed=0.44704*ceil(v2_temp);
    RMS_minimum_error=1e9;
    RMS_error=1e9;

    while ((RMS_error = RMS_minimum_error)&&(e2_temp <= 2.0))
     { 
      if ((bearingtype == 'S')||(bearingtype == 's'))
       c1_temp=(A + 0.268224*v2_temp*B + C*pow(0.268224*v2_temp, 2))/pow(0.44704*v2_temp, e1);
      else  
       c1_temp=A;

      c2_temp=(A + vequal*B + C*pow(vequal, 2) - c1_temp*pow(0.44704*v2_temp, e1))/(0.44704*v2_temp + pow(vequal, e2_temp));

      RMS_error=0;
      while (speed <= speed_range)
       {
        friction1=A + speed*B + C*pow(speed, 2);
        if (speed > 0.44704*v2_temp)
         friction2=c1_temp*pow(0.44704*v2_temp, e1) + 0.44704*v2_temp*c2_temp +  c2_temp*pow(speed, e2_temp);
        else
         friction2=c1_temp*pow(speed, e1);
       error=friction1-friction2; 
       if (speed > 0.44704*v2_temp)
         RMS_error=RMS_error + error*error;
        speed = speed + 0.44704;
       }
      RMS_error=sqrt(RMS_error/(speed_range/0.44704 - ceil(v2_temp) + 1));
      speed=0.44704*ceil(v2_temp);
      if (RMS_error < RMS_minimum_error)
       {
        RMS_minimum_error=RMS_error;
        v2=v2_temp;
        c1=c1_temp;
        c2=c2_temp;
        e2=e2_temp;
        vequal_best=vequal;
       }
      if (RMS_error<=50)
       e2_temp=e2_temp+0.001; 
      else if (RMS_error<=100)
       e2_temp=e2_temp+0.01; 
      else
       e2_temp=e2_temp+0.05;
     }

/* Calculate final values using best e2 value as starting point */

    RMS_error_last=RMS_minimum_error;
    RMS_minimum_iteration_error=RMS_minimum_error;
    v2_temp=v2_min;
    e2_temp=e2;
    vequal=13.4112;
    speed=0.44704*ceil(v2_temp);
    while ((e2_temp <= 2)&&(RMS_minimum_iteration_error <= RMS_error_last))
     { 
      RMS_error_last=RMS_minimum_iteration_error;
      RMS_minimum_iteration_error = 1e9;
      while (v2_temp <= v2_max)
       {
        if ((bearingtype == 'S')||(bearingtype == 's'))
         c1_temp=(A + 0.268224*v2_temp*B + C*pow(0.268224*v2_temp, 2))/pow(0.44704*v2_temp, e1);
        else  
         c1_temp=A;

        while (vequal <= speed_range)
         {
          c2_temp=(A + vequal*B + C*pow(vequal, 2) - c1_temp*pow(0.44704*v2_temp, e1))/(0.44704*v2_temp + pow(vequal, e2_temp));
          RMS_error=0;
          while (speed <= speed_range)
           {
            friction1=A + speed*B + C*pow(speed, 2);
            friction2=c1_temp*pow(0.44704*v2_temp, e1) + 0.44704*v2_temp*c2_temp +  c2_temp*pow(speed, e2_temp);
            error=friction1-friction2;
            RMS_error=RMS_error + error*error;
            speed = speed + 0.44704;
           }
          RMS_error=sqrt(RMS_error/(speed_range/0.44704 - ceil(v2_temp) + 1));
          if (RMS_error < RMS_minimum_error)
           {
            RMS_minimum_error=RMS_error;
            v2=v2_temp;
            c1=c1_temp;
            c2=c2_temp;
            e2=e2_temp;
            vequal_best=vequal;
           }
          if (RMS_error < RMS_minimum_iteration_error)
           RMS_minimum_iteration_error=RMS_error;
          error_ratio=RMS_error/RMS_minimum_error;
          if ((error_ratio<=1.3)&&(error_ratio>=0.77))
           vequal=vequal+0.44704;
          else
           vequal=vequal+2.23535;
          speed=0.44704*ceil(v2_temp);
         }
        v2_temp=v2_temp+0.1;
        vequal=13.4112;
       }

      e2_temp=e2_temp+0.001;
      v2_temp=v2_min;
     }


It seems to me that E2 only got calculated in regards to solid bearings, but even this puts out values not even close enough than what you get in the actual program.

#18 User is offline   Genma Saotome 

  • Owner Emeritus and Admin
  • PipPipPipPipPipPipPipPipPipPipPipPipPip
  • Group: ET Admin
  • Posts: 15,308
  • Joined: 11-January 04
  • Gender:Male
  • Location:United States
  • Simulator:Open Rails
  • Country:

Posted 03 April 2020 - 10:34 AM

 NickonWheels, on 03 April 2020 - 12:37 AM, said:

No, I´m indeed looking for the old MSTS parameters in order to get around ORTS Davis lines because of their inappropriate way to define starting resistance and principally non-working private ORTS versions. I finally found the code, but it looks needlessly complicated, mostly because of speed settings everywhere. For Davis lines speed settings don´t matter so there is need to replace them with some general value but this obviously does not work...again


IIRC Joe was trying to push the Friction() values towards something that was closer to Davis values.

I made a spreadsheet for the purpose of plotting resistance (Newtons) over speed where I could see how the two compared. The lines were close but subtly different. I then changed the chart to display only the differences at speed. Looking at value differences, this chart often showed wild variability (e.g., often an s curve) going above and below zero. That is what convinced me to drop Friction() and go with Davis.

  • 2 Pages +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users