示例#1
0
 /// <summary>
 /// Performs iterator
 /// </summary>
 /// <param name="consumer">Data consumer</param>
 /// <param name="iterator">Iterator</param>
 /// <param name="timeProvider">Time provider</param>
 /// <param name="reason">Reason</param>
 /// <param name="stop">Stop</param>
 /// <returns>True in case of interruption</returns>
 public static bool PerformIterator(this IDataConsumer consumer, IIterator iterator,
                                    ITimeMeasureProvider timeProvider, string reason, Func <bool> stop)
 {
     try
     {
         using (TimeProviderBackup backup = new TimeProviderBackup(consumer, timeProvider, null, reason, 0))
         {
             IDataRuntime runtime = backup.Runtime;
             IStep        st      = null;
             IMeasurement time    = timeProvider.TimeMeasurement;
             if (runtime is IStep)
             {
                 st      = runtime as IStep;
                 st.Step = 0;
             }
             iterator.Reset();
             double t    = (double)time.Parameter();
             double last = t;
             Action <double, double, long> act = runtime.Step(null,
                                                              (double timer) => { }, reason, null);
             int i = 0;
             while (iterator.Next())
             {
                 t = (double)time.Parameter();
                 act(last, t, i);
                 ++i;
                 if (st != null)
                 {
                     st.Step = i;
                 }
                 last = t;
                 if (stop())
                 {
                     return(true);
                 }
             }
         }
         return(false);
     }
     catch (Exception ex)
     {
         ex.ShowError(10);
     }
     return(true);
 }
示例#2
0
 /// <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;
     }
 }