Exemple #1
0
        /// <summary>
        /// Performs step of integration
        /// </summary>
        /// <param name="t0">Step start</param>
        /// <param name="t1">Step finish</param>
        public override void Step(double t0, double t1)
        {
            isBusy = true;
            if (Dim == 0)
            {
                return;
            }
            double dt = t1 - t0;
            int    i  = 0;

            foreach (IMeasurements m in equations)
            {
                IDifferentialEquationSolver s = m as IDifferentialEquationSolver;
                m.UpdateMeasurements(true);
                int n = s.GetVariablesCount();
                for (int j = 0; j < n; j++)
                {
                    w[i] = (double)m[j].Parameter();
                    f[i] = w[i];
                    ++i;
                }
                s.CopyVariablesToSolver(i - s.GetVariablesCount(), w);
            }
            double t = t0;

            timeProvider.Time = t;
            i = 0;
            foreach (IMeasurements m in equations)
            {
                IDifferentialEquationSolver s = m as IDifferentialEquationSolver;
                s.CalculateDerivations();
                for (int j = 0; j < s.GetVariablesCount(); j++)
                {
                    IDerivation der = m[j] as IDerivation;
                    z[i]    = Measurement.GetDouble(der.Derivation);
                    k[0, i] = z[i] * dt;
                    w[i]    = f[i] + 0.5 * k[0, i];
                    ++i;
                }
                s.CopyVariablesToSolver(i - s.GetVariablesCount(), w);
            }
            t = t0 + 0.5 * dt;
            timeProvider.Time = t;
            i = 0;
            foreach (IMeasurements m in equations)
            {
                IDifferentialEquationSolver s = m as IDifferentialEquationSolver;
                s.CalculateDerivations();
                for (int j = 0; j < s.GetVariablesCount(); j++)
                {
                    IDerivation der = m[j] as IDerivation;
                    z[i]    = Measurement.GetDouble(der.Derivation);
                    k[1, i] = z[i] * dt;
                    w[i]    = f[i] + 0.5 * k[1, i];
                    ++i;
                }
                s.CopyVariablesToSolver(i - s.GetVariablesCount(), w);
            }
            t = t0 + 0.5 * dt;
            timeProvider.Time = t;
            i = 0;
            foreach (IMeasurements m in equations)
            {
                IDifferentialEquationSolver s = m as IDifferentialEquationSolver;
                s.CalculateDerivations();
                for (int j = 0; j < s.GetVariablesCount(); j++)
                {
                    IDerivation der = m[j] as IDerivation;
                    z[i]    = Measurement.GetDouble(der.Derivation);
                    k[2, i] = z[i] * dt;
                    w[i]    = f[i] + k[2, i];
                    ++i;
                }
                s.CopyVariablesToSolver(i - s.GetVariablesCount(), w);
            }
            t = t0 + dt;
            timeProvider.Time = t;
            i = 0;
            foreach (IMeasurements m in equations)
            {
                IDifferentialEquationSolver s = m as IDifferentialEquationSolver;
                s.CalculateDerivations();
                for (int j = 0; j < s.GetVariablesCount(); j++)
                {
                    IDerivation der = m[j] as IDerivation;
                    z[i]    = Measurement.GetDouble(der.Derivation);
                    k[3, i] = z[i] * dt;
                    ++i;
                }
            }
            i = 0;
            foreach (IMeasurements m in equations)
            {
                IDifferentialEquationSolver s = m as IDifferentialEquationSolver;
                for (int j = 0; j < s.GetVariablesCount(); j++)
                {
                    f[i] += (k[0, i] + 2 * k[1, i] + 2 * k[2, i] + k[3, i]) / 6;
                    ++i;
                }
                s.CopyVariablesToSolver(i - s.GetVariablesCount(), f);
            }
            i = 0;
            foreach (IMeasurements m in equations)
            {
                IDifferentialEquationSolver s = m as IDifferentialEquationSolver;
                for (int j = 0; j < s.GetVariablesCount(); j++)
                {
                    IMeasurement measure = m[j];
                    IDerivation  d       = m[j] as IDerivation;
                    IMeasurement der     = d.Derivation;
                    if (!(der is IDistribution))
                    {
                        ++i;
                        continue;
                    }
                    IDistribution distr = der as IDistribution;
                    f[i] += distr.Integral;
                    distr.Reset();
                    ++i;
                }
                s.CopyVariablesToSolver(i - s.GetVariablesCount(), f);
            }
            isBusy = false;
        }
Exemple #2
0
        private int GetCount(IMeasurements m)
        {
            IDifferentialEquationSolver s = m as IDifferentialEquationSolver;

            return(s.GetVariablesCount());
        }