using System; using System.Collections.Generic; using System.Text; using RungeKutta.Integrators; using System.Reflection; using RungeKutta.ODEs; using RungeKutta.SimStep; namespace RungeKutta { class Manager { List integrators = new List(); List> computedValues = new List>(); public IList Integrators { get { return integrators; } } public IList> ComputedValues { get { return computedValues; } } public ODE ODE { get; private set; } int Compare(SimStepper t1, SimStepper t2) { return t1.ToString().CompareTo(t2.ToString()); } public Manager() { ODE = new DampedSpring(); //Find all simple integrators in this assembly: List Types = new List(Assembly.GetExecutingAssembly().GetTypes()); foreach (Type type in Types) if ((new List(type.GetInterfaces()).Contains(typeof(SimStepper))) && !type.IsInterface) { integrators.Add((SimStepper)System.Activator.CreateInstance(type)); computedValues.Add(new List()); } integrators.Sort(Compare); } public void Compute(float timestep, float timeToRun, State InitialState) { for (int x = 0; x < integrators.Count; ++x) { computedValues[x] = new List(); State state = InitialState; // Time 0: initial condition computedValues[x].Add(state.position); float deltaTime = timestep * integrators[x].ForceEvaluations; for (float t = timestep; t <= timeToRun; t += deltaTime) { if (Math.Abs(state.position) > 1e10f) //to protect against weirdness... { computedValues[x].Add(float.PositiveInfinity); } else { state = integrators[x].Integrate(state, deltaTime, ODE); computedValues[x].Add(state.position); } } } } } }