/// <summary> /// Synchronously runs the discrete simulation and blocks until it finishes /// </summary> public void Run() { _dataColumns = new List <string>(); _timeSeries = new ConcurrentDictionary <long, ConcurrentDictionary <string, double> >(); Init(); State = SimulationRunState.Running; Logger.AddMessage(LogEntryType.Info, string.Format("Started dynamics module [{0}]", this.GetType().Name)); while (State == SimulationRunState.Running) { #if !DEBUG try{ #endif TimeStep(SimulationTime); if (OnStep != null) { OnStep(SimulationTime); } SimulationTime++; #if !DEBUG } catch (Exception ex) { State = SimulationRunState.Error; Logger.AddMessage(LogEntryType.Error, "Exception in dynamics module at " + ex.Source + ", message = " + ex.Message + "\n" + ex.StackTrace); return; } #endif } Finish(); }
/// <summary> /// Synchronously runs the discrete simulation and blocks until it finishes /// </summary> public void Run() { _dataColumns = new List<string>(); _timeSeries = new ConcurrentDictionary<long, ConcurrentDictionary<string,double>>(); Init(); State = SimulationRunState.Running; Logger.AddMessage(LogEntryType.Info, string.Format("Started dynamics module [{0}]", this.GetType().Name)); while(State == SimulationRunState.Running) { #if !DEBUG try{ #endif TimeStep(SimulationTime); if (OnStep != null) OnStep(SimulationTime); SimulationTime++; #if !DEBUG } catch(Exception ex) { State = SimulationRunState.Error; Logger.AddMessage(LogEntryType.Error, "Exception in dynamics module at " + ex.Source + ", message = " + ex.Message + "\n" + ex.StackTrace); return; } #endif } Finish(); }
/// <summary> /// Stops a simulation /// </summary> public void Stop() { State = SimulationRunState.Stopped; if (OnStop != null) { OnStop(); } }
/// <summary> /// Synchronously runs the simulation and blocks until it finishes /// </summary> public void Run() { _dataColumns = new List <string>(); _timeSeries = new ConcurrentDictionary <double, ConcurrentDictionary <string, double> >(); State = SimulationRunState.Running; Logger.AddMessage(LogEntryType.Info, string.Format("Started continuous dynamics module [{0}]", this.GetType().Name)); while (State == SimulationRunState.Running) { #if !DEBUG try{ #endif // Compute change based on 4th-order Runge-Kutta and user-provided dynamics DenseVector k1 = TimeDelta * ComputeDelta(Time, CurrentValues); DenseVector k2 = TimeDelta * ComputeDelta(Time + TimeDelta / 2d, CurrentValues + k1 / 2d); DenseVector k3 = TimeDelta * ComputeDelta(Time + TimeDelta / 2d, CurrentValues + k2 / 2d); DenseVector k4 = TimeDelta * ComputeDelta(Time + TimeDelta, CurrentValues + k3); CurrentValues += (k1 + 2d * k2 + 2d * k3 + k4) / 6d; // Advance time Time += TimeDelta; // Trigger update if (OnStep != null) { OnStep(Time); } #if !DEBUG } catch (Exception ex) { State = SimulationRunState.Error; Logger.AddMessage(LogEntryType.Error, "Exception in dynamics module at " + ex.Source + ", message = " + ex.Message + "\n" + ex.StackTrace); return; } #endif } Finish(); }
/// <summary> /// Synchronously runs the simulation and blocks until it finishes /// </summary> public void Run() { _dataColumns = new List<string>(); _timeSeries = new ConcurrentDictionary<double, ConcurrentDictionary<string,double>>(); State = SimulationRunState.Running; Logger.AddMessage(LogEntryType.Info, string.Format("Started continuous dynamics module [{0}]", this.GetType().Name)); while(State == SimulationRunState.Running) { #if !DEBUG try{ #endif // Compute change based on 4th-order Runge-Kutta and user-provided dynamics DenseVector k1 = TimeDelta * ComputeDelta(Time, CurrentValues); DenseVector k2 = TimeDelta * ComputeDelta(Time+TimeDelta/2d, CurrentValues + k1/2d); DenseVector k3 = TimeDelta * ComputeDelta(Time+TimeDelta/2d, CurrentValues + k2/2d); DenseVector k4 = TimeDelta * ComputeDelta(Time+TimeDelta, CurrentValues + k3); CurrentValues += (k1 + 2d * k2 + 2d * k3 + k4) / 6d; // Advance time Time += TimeDelta; // Trigger update if (OnStep != null) OnStep(Time); #if !DEBUG } catch(Exception ex) { State = SimulationRunState.Error; Logger.AddMessage(LogEntryType.Error, "Exception in dynamics module at " + ex.Source + ", message = " + ex.Message + "\n" + ex.StackTrace); return; } #endif } Finish(); }
/// <summary> /// Stops a simulation /// </summary> public void Stop() { State = SimulationRunState.Stopped; if(OnStop!=null) OnStop(); }