protected SingleOdeEngine(Func <double, double, double> rhs, double x, OdeEvaluationSettings settings) : base(x)
 {
     Debug.Assert(rhs != null);
     Debug.Assert(settings != null);
     this.rhs      = rhs;
     this.settings = settings;
 }
 public SingleBulrischStoerEngine(Func <double, double, double> rhs, double x, double y, OdeEvaluationSettings settings) : base(rhs, x, settings)
 {
     this.Y      = y;
     this.YPrime = this.Evaluate(x, y);
     ComputeInitialStep();
 }
        /// <summary>
        /// Solves a conservative second order ordinary differential equation initial value problem using the given settings.
        /// </summary>
        /// <param name="rhs">The right hand side function.</param>
        /// <param name="x0">The initial value of the independent variable.</param>
        /// <param name="y0">The initial value of the function variable.</param>
        /// <param name="yPrime0">The intial value of the function derivative.</param>
        /// <param name="x1">The final value of the independent variable.</param>
        /// <param name="settings">The settings to use when solving the problem.</param>
        /// <returns>The solution, including the final value of the function and its derivative.</returns>
        /// <exception cref="ArgumentNullException">The <paramref name="rhs"/> or <paramref name="settings"/> is null.</exception>
        /// <exception cref="NonconvergenceException">The ODE could not be integrated to the required precision before exhausting the maximum allowed number of <paramref name="rhs"/> evaluations.</exception>
        /// <remarks>
        /// <para>A conservative ODE is an ODE of the form</para>
        /// <img src="../images/ConservativeODE.png" />
        /// <para>where the right-hand-side depends only on x and y, not on the derivative y'. ODEs of this form are called conservative because
        /// they exhibit conserved quantities: combinations of y and y' that maintain the same value as the system evolves. Many forms of
        /// Newtonian equations of motion, for example, are conservative ODEs, with conserved quantities such as energy, momentum, and
        /// angular momentum. Our specialized conservative ODE integrator is not only more efficient for conservative ODEs, but does a
        /// better job of maintaining the conserved quantities.</para>
        /// </remarks>
        public static OdeResult IntegrateConservativeOde(Func <double, double, double> rhs, double x0, double y0, double yPrime0, double x1, OdeEvaluationSettings settings)
        {
            if (rhs == null)
            {
                throw new ArgumentNullException(nameof(rhs));
            }
            if (settings == null)
            {
                throw new ArgumentNullException(nameof(settings));
            }

            SetOdeDefaults(settings);

            SingleStoermerEngine  engine   = new SingleStoermerEngine(rhs, x0, y0, yPrime0, settings);
            BulrischStoerStrategy strategy = new BulrischStoerStrategy(engine);

            strategy.IntegrateTo(x1);
            return(engine.GetResult());
        }