-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
59 lines (49 loc) · 2.21 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
using System.Numerics;
using System.Text;
using Simul1.Integrators;
using Simul1.OutputHandlers;
using Simul1.ParticleSimulation;
namespace Simul1;
internal class Program
{
/// <summary>
/// only for this one test. I do it here becuase unit tests dont give real time output which is dumb but I need it
/// </summary>
/// <param name="args"></param>
private static void Main(string[] args)
{
TestStepsizeDependency("stepsizeTestOutput.txt");
}
public static void TestStepsizeDependency(string outputFilename)
{
var wholePeriod = 8.0 * Math.Atan(1.0);
var stepSizes = new []{ 1e-1, 1e-2, 1e-3, 1e-4, 1e-5, 1e-6, 1e-7, 1e-8 };
for (int i = 0; i < stepSizes.Count(); i++){
stepSizes[i] *= wholePeriod;
}
var methods = new []{ EIntegrationMethod.EULER, EIntegrationMethod.RK2, EIntegrationMethod.RK4 };
var handler = new NoActionOutputHandler();
var outputString = new StringBuilder("");
outputString.AppendLine("\nFinal Time\tstepsize\tx\ty\tEnergy error");
foreach (var method in methods)
{
outputString.AppendLine("\n" + method);
Console.WriteLine($"Currently trying the {method} method");
foreach (var stepSize in stepSizes)
{
Console.WriteLine($"Currently running stepsize {stepSize}");
// setup new simnulation
const double eccentricity = 0.3; // unitless eccentricity of an orbit
var initialPosition = new Vector<double>(new [] {1 - eccentricity, 0, 0, 0}); // four dimensions cuz .NET 6.0 is kinda weird
var initialMomentum = new Vector<double>(new [] {0, Math.Sqrt((1 + eccentricity) / (1 - eccentricity)), 0, 0});
var simulation = new Simulation(initialPosition, initialMomentum);
var simulationResult = simulation.Integrate(handler, wholePeriod, stepSize, write: false,
method: method);
outputString.AppendLine(simulationResult);
}
}
using (StreamWriter sw = new StreamWriter(outputFilename)){
sw.Write(outputString);
}
}
}