static bool Bench(int n, bool verbose) { NBodySystem bodies = new NBodySystem(); double initialEnergy = bodies.Energy(); if (verbose) { Console.WriteLine("{0:f9}", initialEnergy); } for (int i = 0; i < n; i++) { bodies.Advance(0.01); } double finalEnergy = bodies.Energy(); if (verbose) { Console.WriteLine("{0:f9}", finalEnergy); } double deltaEnergy = Math.Abs(initialEnergy - finalEnergy); bool result = deltaEnergy < 1e-4; if (verbose) { Console.WriteLine("Energy {0} conserved", result ? "was" : "was not"); } return(result); }
public static int Main(String[] args) { int n = args.Length > 0 ? Int32.Parse(args[0]) : 10000; NBodySystem bodies = new NBodySystem(); double initialEnergy = bodies.Energy(); Console.WriteLine("{0:f9}", initialEnergy); for (int i = 0; i < n; i++) bodies.Advance(0.01); double finalEnergy = bodies.Energy(); Console.WriteLine("{0:f9}", finalEnergy); double deltaEnergy = Math.Abs(initialEnergy - finalEnergy); bool result = deltaEnergy < 1e-4; Console.WriteLine("Energy {0} conserved", result ? "was" : "was not"); return (result ? 100 : -1); }
public static int Main(String[] args) { int n = args.Length > 0 ? Int32.Parse(args[0]) : 10000; NBodySystem bodies = new NBodySystem(); double initialEnergy = bodies.Energy(); Console.WriteLine("{0:f9}", initialEnergy); for (int i = 0; i < n; i++) { bodies.Advance(0.01); } double finalEnergy = bodies.Energy(); Console.WriteLine("{0:f9}", finalEnergy); double deltaEnergy = Math.Abs(initialEnergy - finalEnergy); bool result = deltaEnergy < 1e-4; Console.WriteLine("Energy {0} conserved", result ? "was" : "was not"); return(result ? 100 : -1); }