Guest User

EM Drive acceleration estimator

a guest
Jan 18th, 2017
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.46 KB | None | 0 0
  1. package emcalc;
  2.  
  3. import java.util.function.Function;
  4.  
  5. /**
  6.  * Derive EMDrive acceleration from NASA figures.
  7.  *
  8.  * @author ps200306
  9.  * @since 17-Jan-2017
  10.  *
  11.  */
  12. public class Emcalc {
  13.  
  14.     // Constants
  15.    
  16.     final double G = 6.67408e-11; // Gravitational constant, units m3 kg-1 s-2.
  17.     final double M = 1.989e30; // Mass of Sun in kg.
  18.     final double GM = G * M; // convenience constant.
  19.     final double Re = 1.496e11; // Sun-Earth distance in metres.
  20.     final double Rp = 5.906380e12; // Sun-Pluto distance in metres.
  21.     final double Rx = 4.014e16; // Sun-Proxima distance in metres.
  22.     final double yr = 365 * 24 * 3600; // year in seconds
  23.     final double ft = yr * 1.5; // target flight time = 18 months
  24.     final double v0 = 0; // initial radial velocity is zero (just added for completeness)
  25.    
  26.     double a0 = 0; // The EMDrive acceleration which we seek.
  27.  
  28.    
  29.     public static void main(String args[]) {
  30.         (new Emcalc()).calc();
  31.     }
  32.  
  33.  
  34.     /**
  35.      * Main calculation. Take initial estimate of EMdrive acceleration
  36.      * (in the range zero to something big) then binary chop until we
  37.      * get within desired accuracy of the target flight time.
  38.      */
  39.     void calc() {
  40.        
  41.         final double precision = 0.01; // target precision 1%      
  42.         double error = 1; // try to reduce this error to within target precision
  43.         final int numSteps = 100 * 1000; // divisions for numerical integration
  44.        
  45.         // initial range of EMDrive acceleration in m/s^2
  46.         double aLo = 0;
  47.         double aHi = 1000; // something big
  48.  
  49.         System.out.printf("target flight time=%s, in years = %s\n\n", ft, ft/yr);
  50.        
  51.         while (error > precision) {
  52.            
  53.             a0 = (aLo + aHi) / 2;
  54.            
  55.             final double aconst = a0; // final needed for Java 8 lambda
  56.  
  57.             // Perform numerical integration on 1/v
  58.             double t = integrate(Re, Rp, numSteps, r ->
  59.                 1/Math.sqrt(2 * (v0 + aconst * r + GM/r) - 2 * (aconst * Re + GM/Re))
  60.             );
  61.  
  62.             // Compare to required target
  63.             error = Math.abs(1 - t / ft);
  64.            
  65.             System.out.printf("a0=%3.3e, t=%3.3e, error=%3.3e \n", a0, t, error);
  66.            
  67.             // We can get some singularities e.g. divide by zero, in which case we
  68.             // just pretend the result was too high and let the binary chop do the rest.
  69.             if (Double.isNaN(t)) {
  70.                 t = 2* ft;
  71.                 error = precision + 1;
  72.             }
  73.            
  74.             // Binary chop depending on whether result was high or low.
  75.             aLo = (t > ft)? a0 : aLo;
  76.             aHi = (t > ft)? aHi : a0;
  77.  
  78.         }
  79.        
  80.         // Final acceleration estimate
  81.         System.out.printf("\nFinal accelelation a0 = %s\n", a0);
  82.        
  83.         // Use this acceleration to fly to Proxima Centauri
  84.         final double aconst = a0;
  85.         double u = integrate(Re, Rx, numSteps * 10, r ->
  86.             1/Math.sqrt(2 * (v0 + aconst * r + GM/r) - 2 * (aconst * Re + GM/Re))
  87.         );
  88.         System.out.printf("\nFlight time to Proxima = %s, in years = %s\n\n", u, u/yr);
  89.        
  90.     }
  91.  
  92.     /**
  93.      *
  94.      * Numerical integrator.
  95.      *
  96.      * @param lower - integration lower bound
  97.      * @param upper - integration upper bound
  98.      * @param numSteps - number of integration steps (affects precision)
  99.      * @param integrand - function to integrate
  100.      * @return the integral over the bounds
  101.      */
  102.     double integrate(double lower, double upper, int numSteps, Function<Double, Double> integrand) {
  103.  
  104.         double step = (upper - lower)/numSteps; // step size
  105.         double integral = 0;
  106.        
  107.         for (int i = 0; i < numSteps; i++) {
  108.             double L = lower + step * i + step/2; // use midpoint of each step
  109.             integral += (step * integrand.apply(L));
  110.         }
  111.        
  112.         return integral;
  113.        
  114.     }
  115.  
  116. }
Advertisement
Add Comment
Please, Sign In to add comment