Esempio n. 1
0
        /// <summary>
        /// Sets consumers
        /// </summary>
        /// <param name="collection">Consumers</param>
        /// <returns>Lists of parameters</returns>
        public virtual void Set(object collection)
        {
            IComponentCollection cc = collection as IComponentCollection;
            IDataRuntime         rt = StaticExtensionDataPerformerPortable.Factory.Create(cc, 0);

            Clear();
            variablesStr.Clear();

            /*           IEnumerable<IDataConsumer> consumers = cc.GetAll<IDataConsumer>();
             *         foreach (IDataConsumer c in consumers)
             *         {
             *             c.GetMeasurements(measurements);
             *         }*/
            List <object> l = new List <object>();

            cc.ForEach <IDifferentialEquationSolver>((IDifferentialEquationSolver solver) =>
            {
                if (solver is IMeasurements)
                {
                    if (!l.Contains(solver))
                    {
                        l.Insert(0, solver);
                    }
                }
                if (solver is IDataConsumer)
                {
                    (solver as IDataConsumer).GetDependentObjects(l);
                }
            }
                                                     );
            foreach (object o in l)
            {
                if (o is IMeasurements)
                {
                    measurements.Add(o as IMeasurements);
                }
            }
            foreach (IMeasurements m in measurements)
            {
                IDataRuntimeFactory s = StaticExtensionDataPerformerPortable.Factory;
                if (m is IDifferentialEquationSolver)
                {
                    IDifferentialEquationSolver ds = m as IDifferentialEquationSolver;
                    Add(ds);
                }
                else if (s != null)
                {
                    IDifferentialEquationSolver ds = rt.GetDifferentialEquationSolver(m);
                    if (ds != null)
                    {
                        Add(ds);
                    }
                }
                if (m is INormalizable)
                {
                    Add(m as INormalizable);
                }
            }
            measurements.SortMeasurements();
        }
        /// <summary>
        /// Initialization
        /// </summary>
        protected virtual void Init()
        {
            List <IAggregableMechanicalObject> lo = new List <IAggregableMechanicalObject>();

            foreach (AggregableWrapper aw in aggrWrappres)
            {
                lo.Add(aw.Aggregate);
            }
            aggregates = lo.ToArray();
            indexes    = new int[aggrWrappres.Length];
            int kn = 0;
            int nn = 0;

            for (int i = 0; i < indexes.Length; i++)
            {
                int dd = aggrWrappres[i].Aggregate.Dimension;
                indexes[i] = kn;
                kn        += aggrWrappres[i].Aggregate.Dimension;
                nn        += dd;
            }
            derivations = new double[nn, 2];
            foreach (IAggregableMechanicalObject amo in aggregates)
            {
                if (amo is IStarted)
                {
                    IStarted st = amo as IStarted;
                    st.Start(0);
                }
            }
            IDifferentialEquationSolver s = this;

            Set(ref measures, derivations);
            s.CalculateDerivations();
        }
        void IStarted.Start(double time)
        {
            Reset();
            if (aggregate is IStarted)
            {
                IStarted s = aggregate as IStarted;
                s.Start(time);
            }

            Normalize(aggregate);
            IDifferentialEquationSolver so = this;

            so.CalculateDerivations();
        }
Esempio n. 4
0
        /// <summary>
        /// Adds solver
        /// </summary>
        /// <param name="solver">Solver to add</param>
        public void Add(IDifferentialEquationSolver solver)
        {
            if (equations.Contains(solver))
            {
                return;
            }

            /*           string n = solver.GetName();
             *         List<string> var = solver.Variables;
             *         foreach (string s in var)
             *         {
             *             variablesStr.Add(new string[] { n, s });
             *         }*/
            equations.Add(solver);

            if (solver is INormalizable)
            {
                Add(solver as INormalizable);
            }
        }
Esempio n. 5
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;
            double t  = t0;

            foreach (IMeasurements m in equations)
            {
                for (int j = 0; j < m.Count; j++)
                {
                    w[i] = (double)m[j].Parameter();
                    ++i;
                }
            }
            StaticExtensionDataPerformerPortable.Time = t;
            StaticExtensionDataPerformerPortable.Desktop.ResetUpdatedMeasurements();
            UpdateMeasurements();
            i = 0;
            foreach (IMeasurements m in equations)
            {
                IDifferentialEquationSolver s = m as IDifferentialEquationSolver;
                s.CalculateDerivations();
                for (int j = 0; j < m.Count; j++)
                {
                    IDerivation der = m[j] as IDerivation;
                    w[i] = w[i] + Measurement.GetDouble(der.Derivation) * dt;
                    ++i;
                }
                s.CopyVariablesToSolver(i - m.Count, w);
            }
            isBusy = false;
        }
Esempio n. 6
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;
        }
Esempio n. 7
0
        private int GetCount(IMeasurements m)
        {
            IDifferentialEquationSolver s = m as IDifferentialEquationSolver;

            return(s.GetVariablesCount());
        }
Esempio n. 8
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;
            paramCount = 0;
            if (stepCount < order)
            {
                runge.Step(t0, t1);
                foreach (IMeasurements m in equations)
                {
                    runge.Step(t0, t1);
                    IDifferentialEquationSolver s = m as IDifferentialEquationSolver;
                    s.CalculateDerivations();
                    for (int j = 0; j < m.Count; j++)
                    {
                        IDerivation der = m[j] as IDerivation;
                        prevDeri[paramCount, stepCount] = Measurement.GetDouble(der.Derivation);
                        prevStep[paramCount]            = (double)m[j].Parameter();
                        ++paramCount;
                    }
                    s.CopyVariablesToSolver(paramCount - m.Count, prevStep);
                    ++stepCount;
                }
                paramCount = 0;
            }

            else
            {
                foreach (IMeasurements m in equations)
                {
                    IDifferentialEquationSolver s = m as IDifferentialEquationSolver;
                    s.CalculateDerivations();
                    for (int j = 0; j < m.Count; j++)
                    {
                        prevStep[paramCount] = (double)m[j].Parameter();
                        oldStep[paramCount]  = prevStep[paramCount];
                        for (int i = 0; i < order; i++)
                        {
                            prevStep[paramCount] += prevDeri[paramCount, i] * prCoeff[i] * (t1 - t0);
                        }
                        ++paramCount;
                    }
                    s.CopyVariablesToSolver(paramCount - m.Count, prevStep);
                }

                paramCount = 0;
                foreach (IMeasurements m in equations)
                {
                    for (int j = 0; j < m.Count; j++)
                    {
                        for (int i = 0; i < order - 1; i++)
                        {
                            prevDeri[paramCount, i] = prevDeri[paramCount, i + 1];
                        }
                        ++paramCount;
                    }
                }

                paramCount = 0;
                foreach (IMeasurements m in equations)
                {
                    IDifferentialEquationSolver s = m as IDifferentialEquationSolver;
                    s.CalculateDerivations();
                    for (int j = 0; j < m.Count; j++)
                    {
                        IDerivation der = m[j] as IDerivation;
                        prevDeri[paramCount, order - 1] = Measurement.GetDouble(der.Derivation);
                        ++paramCount;
                    }
                }
                paramCount = 0;


                foreach (IMeasurements m in equations)
                {
                    IDifferentialEquationSolver s = m as IDifferentialEquationSolver;
                    for (int j = 0; j < m.Count; j++)
                    {
                        prevStep[paramCount] = oldStep[paramCount];
                        for (int i = 0; i < order; i++)
                        {
                            prevStep[paramCount] += prevDeri[paramCount, i] * aqCoeff[i] * (t1 - t0);
                        }
                        ++paramCount;
                    }
                    s.CopyVariablesToSolver(paramCount - m.Count, prevStep);
                }
                ++stepCount;
            }
            isBusy = false;
        }