/// <summary> /// Starts all components /// </summary> /// <param name="time">Start time</param> public virtual void StartAll(double time) { provider.Time = time; List <IStarted> ls = new List <IStarted>(); collection.ForEach <IStarted>((IStarted s) => { ls.Add(s); s.Start(time); }); IStep st = this; st.Step = -1; IDifferentialEquationProcessor pr = DifferentialEquationProcessor.Processor; if (pr == null) { return; } ICollection <IDifferentialEquationSolver> de = pr.Equations; foreach (IDifferentialEquationSolver deq in de) { if (deq is IStarted) { IStarted s = deq as IStarted; if (!ls.Contains(s)) { s.Start(time); } } } dynamical.ForEach((IDynamical dyn) => { dyn.Time = time; }); }
/// <summary> /// Construtor /// </summary> /// <param name="collection">Colletion of objects</param> /// <param name="processor">Differential equation proessor</param> public StateTransformer(IObjectCollection collection, IDifferentialEquationProcessor processor) : this(collection, processor, null) { provider = this; processor.TimeProvider = provider; }
private void test(IDesktop desktop) { IDifferentialEquationProcessor processor = DifferentialEquationProcessor.Processor; /* IDataPerformerRuntimeFactory str = StaticDataPerformer.Factory; * if (str is IStep) * { * st = str as IStep; * } * for (int i = 0; i < steps; i++) * { * if (st != null) * { * st.Step = i; * } * if (i == 0) * { * desktop.StartAll(start); * } * desktop.UpdateAll(); * StaticDataPerformerExtension.Time = start + i * step; * * if (i > 0 & processor != null) * { * processor.Step(start + i * step - step, start + i * step); * } * StaticDataPerformerExtension.Time = start + i * step; * UpdateChildrenData(); * desktop.ResetUpdatedMeasurements(); * }*/ }
/// <summary> /// Prepares itself /// </summary> protected override void Prepare() { if (processor == null) { processor = new InternalRungeProcessor(); } base.Prepare(); processor.Set(collection); }
/// <summary> /// Constructor /// </summary> /// <param name="collection">Collection</param> /// <param name="priority">Priority</param> /// <param name="reason">Reason</param> public TimeProviderBackup(IComponentCollection collection, int priority, string reason) { this.collection = collection; CreateMeasurements(priority, reason); runtime = StaticExtensionDataPerformerPortable.Factory.Create(collection, priority); SetTimeProvider(collection, StaticExtensionDataPerformerPortable.Factory.TimeProvider, dictionary); processor = DifferentialEquationProcessors.DifferentialEquationProcessor.Processor; processor.Set(collection); }
/// <summary> /// Preparation /// </summary> /// <param name="collection">Desktop</param> private void prepareAll(IComponentCollection collection) { components.Clear(); components.AddRange(collection.AllComponents); collection.ForEach <ICategoryObject>((ICategoryObject l) => { objects.Add(l); }); arrows.Clear(); collection.ForEach <ICategoryArrow>((ICategoryArrow l) => { arrows.Add(l); }); IDifferentialEquationProcessor processor = DifferentialEquationProcessor.Processor; }
/// <summary> /// Constructor /// </summary> /// <param name="collection">Collection</param> /// <param name="provider">Time provider</param> /// <param name="processor">Differential equation processor</param> /// <param name="priority">Priority</param> /// <param name="reason">Reason</param> public TimeProviderBackup(IComponentCollection collection, ITimeMeasureProvider provider, IDifferentialEquationProcessor processor, int priority, string reason) { this.collection = collection; SetCollectionHolders(); CreateMeasurements(priority, reason); runtime = StaticExtensionDataPerformerPortable.Factory.Create(collection, priority); SetTimeProvider(collection.AllComponents, provider, dictionary); this.processor = processor; processor.Set(collection); }
/// <summary> /// Constructor /// </summary> /// <param name="consumer">Data consumer</param> /// <param name="provider">Time provider</param> /// <param name="processor">Differential equation processor</param> /// <param name="reason">Reason</param> /// <param name="priority">Priority</param> public TimeProviderBackup(IDataConsumer consumer, ITimeMeasureProvider provider, IDifferentialEquationProcessor processor, string reason, int priority) { this.consumer = consumer; collection = consumer.GetDependentCollection(priority); SetTimeProvider(collection, provider, dictionary); CreateMeasurements(priority, null); runtime = consumer.CreateRuntime(reason, priority); this.processor = processor; if (processor != null) { processor.Set(collection); // !!! added to allow buffer processing, as no IDifferentialEquationProcessoris required there } }
/// <summary> /// Performs ation with array of arguments /// </summary> /// <param name="consumer">Data consumer</param> /// <param name="array">Array of arguments</param> /// <param name="collection">Desktop</param> /// <param name="provider">Provider of time measure</param> /// <param name="processor">Differential equation processor</param> /// <param name="priority">Priority</param> /// <param name="action">Additional action</param> /// <param name="reason">Reason</param> static public void PerformArray(this IDataConsumer consumer, Array array, IComponentCollection collection, ITimeMeasureProvider provider, IDifferentialEquationProcessor processor, int priority, Action action, string reason) { using (TimeProviderBackup backup = new TimeProviderBackup(collection, provider, processor, priority, reason)) { IDataRuntime runtime = backup.Runtime; ITimeMeasureProvider old = processor.TimeProvider; processor.TimeProvider = provider; IStep st = null; if (runtime is IStep) { st = runtime as IStep; } int n = array.Length; double t = (double)array.GetValue(0); double last = t; Action <double, double, long> act = runtime.Step(processor, (double time) => { provider.Time = time; }, reason); for (int i = 0; i < n; i++) { t = (double)array.GetValue(i); act(last, t, (long)i); /* last = t; * if (i == 0) * { * runtime.StartAll((double)array.GetValue(0)); * } * if (st != null) * { * st.Step = i; * } * runtime.UpdateAll(); * provider.Time = (double)array.GetValue(i); * if (i > 0 & processor != null) * { * processor.Step((double)array.GetValue(i - 1), (double)array.GetValue(i)); * } * provider.Time = (double)array.GetValue(i);*/ action(); //collection.ResetUpdatedMeasurements(); } processor.TimeProvider = old; } }
/// <summary> /// Performs action with fixed step /// </summary> /// <param name="consumer">Data consumer</param> /// <param name="start">Start</param> /// <param name="step">Step</param> /// <param name="count">Count of steps</param> /// <param name="provider">Provider of time measure</param> /// <param name="processor">Differential equation processor</param> /// <param name="reason">Reason</param> /// <param name="priority">Priority</param> /// <param name="action">Additional action</param> /// <param name="errorHandler">Error handler</param> /// <param name="asynchronousCalculation">Asynchronous calculation</param> static public void PerformFixed(this IDataConsumer consumer, double start, double step, int count, ITimeMeasureProvider provider, IDifferentialEquationProcessor processor, string reason, int priority, Action action, IAsynchronousCalculation asynchronousCalculation = null, IErrorHandler errorHandler = null) { try { using (TimeProviderBackup backup = new TimeProviderBackup(consumer, provider, processor, reason, priority)) { IDataRuntime runtime = backup.Runtime; ITimeMeasureProvider old = processor.TimeProvider; processor.TimeProvider = provider; IStep st = null; if (runtime is IStep) { st = runtime as IStep; } provider.Time = start; double t = start; double last = t; Action <double, double, long> act = runtime.Step(processor, (double time) => { provider.Time = time; }, reason, asynchronousCalculation); for (int i = 0; i < count; i++) { t = start + i * step; act(last, t, i); last = t; action(); } processor.TimeProvider = old; } } catch (Exception ex) { if (errorHandler != null) { errorHandler.ShowError(ex, 10); } else { ex.ShowError(10); } } }
/// <summary> /// Creates processor /// </summary> /// <param name="collection"></param> /// <returns></returns> protected virtual IDifferentialEquationProcessor CreateProcessor(IComponentCollection collection) { IDifferentialEquationProcessor pr = null; collection.ForEach((IDifferentialEquationSolver s) => { if (pr == null) { pr = DifferentialEquationProcessor.Processor.New; pr.Set(collection); } }); if (realtime != null & pr != null) { pr.TimeProvider = realtime; } return(pr); }
/// <summary> /// Prepares itself /// </summary> protected override void Prepare() { base.Prepare(); mechanicalEquationsNew = new Dictionary <AggregableWrapper, MechanicalAggregateEquation>(); IDifferentialEquationProcessor p = DataPerformer.Portable.DifferentialEquationProcessors.DifferentialEquationProcessor.Processor; List <IDifferentialEquationSolver> lds = new List <IDifferentialEquationSolver>(); IEnumerable <object> oll = collection.AllComponents; if (p != null) { MechanicalAggregateEquation.GetSolvers(mechanicalEquationsNew, oll); List <IDifferentialEquationSolver> ss = new List <IDifferentialEquationSolver>(); foreach (MechanicalAggregateEquation wr in mechanicalEquationsNew.Values) { ss.Add(wr); } lds.AddRange(ss); } foreach (MechanicalAggregateEquation eq in lds) { eq.Reset(); } base.Prepare(); if (p != null) { p.AddRange(lds); } mechanicalEquationsOld = mechanicalEquationsNew; p.UpdateDimension(); IDesktop d = collection.Desktop; frames = ReferenceFrameArrow.Prepare(d); if (frames.Count == 0) { updateInternal = base.UpdateAll; } else { updateInternal = UpdateWithFrames; } }
/// <summary> /// Constructor /// </summary> /// <param name="consumer">Data consumer</param> /// <param name="provider">Time provider</param> /// <param name="processor">Differential equation processor</param> /// <param name="reason">Reason</param> /// <param name="priority">Priority</param> public TimeProviderBackup(IDataConsumer consumer, ITimeMeasureProvider provider, IDifferentialEquationProcessor processor, string reason, int priority) { this.consumer = consumer; collection = consumer.GetDependentCollection(priority); SetCollectionHolders(); List <object> l = new List <object>(collection.AllComponents); if (!l.Contains(consumer)) { l.Add(consumer); } SetTimeProvider(l, provider, dictionary); CreateMeasurements(priority, null); runtime = consumer.CreateRuntime(reason, priority); if (processor != null) { this.processor = processor; processor.Set(collection); } }
/// <summary> /// Performs action with fixed step /// </summary> /// <param name="collection">Desktop</param> /// <param name="start">Start</param> /// <param name="step">Step</param> /// <param name="count">Count of steps</param> /// <param name="provider">Provider of time measure</param> /// <param name="processor">Differential equation processor</param> /// <param name="priority">Priority</param> /// <param name="action">Additional action</param> /// <param name="reason">Reason</param> static public void PerformFixed(this IComponentCollection collection, double start, double step, int count, ITimeMeasureProvider provider, IDifferentialEquationProcessor processor, int priority, Action action, string reason) { using (TimeProviderBackup backup = new TimeProviderBackup(collection, provider, processor, priority, reason)) { List <IMeasurements> measurements = backup.Measurements; IDataRuntime runtime = backup.Runtime; ITimeMeasureProvider old = processor.TimeProvider; processor.TimeProvider = provider; Action <double, double, long> act = runtime.Step(processor, (double time) => { provider.Time = time; }, reason); double last = start; double t = start; for (int i = 0; i < count; i++) { t = start + i * step; act(last, t, (long)i); last = t; action(); } processor.TimeProvider = old; } }
/// <summary> /// Creates action /// </summary> /// <param name="runtime">Runtime</param> /// <param name="time">Time</param> /// <param name="processor">processor</param> /// <param name="action">Action</param> /// <param name="update">Update objects</param> /// <returns>Action</returns> protected virtual Action CreateAction(IDataRuntime runtime, double[] time, IDifferentialEquationProcessor processor, Action action, IRealtimeUpdate[] update) { ITimeMeasureProvider rt = realtime; double[] t = new double[1]; Action <double> setTime = (double a) => { }; Action <double, double, long> act = runtime.Step(processor, setTime, StaticExtensionEventInterfaces.Realtime, null); long[] st = new long[] { 0 }; Action updList = null; foreach (IRealtimeUpdate upd in update) { Action actp = upd.Update; if (actp == null) { continue; } if (act != null) { if (updList == null) { updList = actp; continue; } updList = updList + actp; } } if (action != null) { updList = updList + action; } if (updList == null) { updList = action; } if (updList == null) { updList = () => { }; } // Action[] updateActions = updlist.ToArray(); object loc = new object(); if (realtimeStep == null) { return(() => { // !!! REPLACED WITH GLOBAL LOCKER lock(locker) // { realtime.Update(); t[0] = rt.Time; if (time[0] == t[0]) { return; } act(time[0], t[0], st[0]); time[0] = t[0]; st[0] += 1; updList(); //} }); } else { Action <double> acti; acti = (double arg) => { realtimeStep.Start(arg); acti = realtimeStep.Step; }; return(() => { lock (realtime) { realtime.Update(); t[0] = rt.Time; act(time[0], t[0], st[0]); time[0] = t[0]; st[0] += 1; updList(); acti(t[0]); } }); } }
/// <summary> /// Default constructor /// </summary> protected AccumulatorBase() { processor = new InternalRungeProcessor(this); timeMeasurement = new TimeMeasurement(new Func <object>(GetTime)); children[0] = new EventBlock(); }
/// <summary> /// Construtor /// </summary> /// <param name="collection">Colletion of objects</param> /// <param name="processor">Differential equation proessor</param> /// <param name="provider">Provider of time</param> protected StateTransformer(IObjectCollection collection, IDifferentialEquationProcessor processor, ITimeMeasureProvider provider) : base(collection) { this.processor = processor; this.provider = provider; }
/// <summary> /// Constructor /// </summary> /// <param name="collection">Collection of components</param> /// <param name="reason">Reason</param> /// <param name="priority">Priority</param> /// <param name="dataConsumer">Data consumer</param> /// <param name="realtimeStep">Realtime step</param> /// <param name="realtime">Realtime provider</param> public DataRuntime(IComponentCollection collection, string reason, int priority, IDataConsumer dataConsumer = null, IAsynchronousCalculation realtimeStep = null, ITimeMeasureProvider realtime = null) { this.collection = collection; this.priority = priority; this.reason = reason; this.realtimeStep = realtimeStep; Prepare(); if (realtime != null & priority == 0) { if (reason == StaticExtensionEventInterfaces.Realtime | reason.IsRealtimeAnalysis()) { List <IRealtimeUpdate> lr = new List <IRealtimeUpdate>(); realTimeData = new Dictionary <IComponentCollection, Tuple <IDataRuntime, double[], IDifferentialEquationProcessor, Action> >(); this.realtime = realtime as RealtimeProvider; provider = realtime; dCollection = new Dictionary <object, IComponentCollection>(); /*!!!! * DECOMPOSITION THINK AFTER * collections = collection.Decompose(dCollection); */ //========== REPLACED======== collections = new List <IComponentCollection>() { collection }; collection.ForEach((IEvent ev) => { dCollection[ev] = collection; }); //=========================== IEventLog log = null; if (reason.Equals(StaticExtensionEventInterfaces.Realtime)) { log = StaticExtensionEventInterfaces.NewLog; } Action logupd = null; if (log != null) { Dictionary <IMeasurement, string> namem = new Dictionary <IMeasurement, string>(); List <IMeasurement> lim = new List <IMeasurement>(); collection.ForEach((IMeasurements mm) => { string name = (dataConsumer).GetMeasurementsName(mm) + "."; for (int i = 0; i < mm.Count; i++) { IMeasurement mea = mm[i]; if (mea is IReplacedMeasurementParameter) { lim.Add(mea); namem[mea] = name + mea.Name; } } }); if (lim.Count > 0) { if (reason == "Realtime") { logupd = () => { logDictionary = new Dictionary <string, object>(); foreach (IMeasurement mea in namem.Keys) { string n = namem[mea]; logDictionary[n] = mea.Parameter(); } log.Write(logDictionary, DateTime.Now); }; } } } if (collections.Count == 1) { IDifferentialEquationProcessor pr = CreateProcessor(collection); double[] dt = new double[1]; bool find = (reason.Equals(StaticExtensionEventInterfaces.Realtime) | reason.Equals(StaticExtensionEventInterfaces.RealtimeLogAnalysis)); collection.ForEach((IRealtimeUpdate ru) => { lr.Add(ru); }, find); collection.ForEach((IEvent ev) => { IComponentCollection cc = CreateCollection(ev); if (!realTimeData.ContainsKey(cc)) { List <IRealtimeUpdate> lru = new List <IRealtimeUpdate>(); cc.ForEach((IRealtimeUpdate rud) => { lru.Add(rud); }, find); IDataRuntime drc = Copy(cc); double[] dtt = new double[1]; Action actp = CreateAction(drc, dtt, pr, logupd, lru.ToArray()); realTimeData[cc] = new Tuple <IDataRuntime, double[], IDifferentialEquationProcessor, Action> (drc, dtt, pr, actp); } }); } else { foreach (IComponentCollection coll in collections) { List <IRealtimeUpdate> lu = new List <IRealtimeUpdate>(); foreach (object o in coll.AllComponents) { if (o is IObjectLabel) { IRealtimeUpdate ru = (o as IObjectLabel).Object.GetObject <IRealtimeUpdate>(); if (ru != null) { lu.Add(ru); } } } IDataRuntime rt = Copy(coll); IDifferentialEquationProcessor pr = CreateProcessor(collection); double[] dt = new double[1]; Action act = CreateAction(rt, dt, pr, null, lr.ToArray()); realTimeData[coll] = new Tuple <IDataRuntime, double[], IDifferentialEquationProcessor, Action> (rt, dt, pr, act); } } (realtime as RealtimeProvider).Update(); startRuntime = provider.Time; foreach (Tuple <IDataRuntime, double[], IDifferentialEquationProcessor, Action> t in realTimeData.Values) { t.Item2[0] = startRuntime; } collection.ForEach <IStarted>((IStarted st) => { st.Start(startRuntime); }); } } }
/// <summary> /// Sets collection /// </summary> /// <param name="processor">The processor</param> /// <param name="collection">The colletion</param> /// <returns>List of variables</returns> static public void Set(this IDifferentialEquationProcessor processor, IComponentCollection collection) { processor.Set(collection); }