public void runThreadedSimulation(Simulation simulation, ISimulationListener listener) { lock (runningSimulations) { bool contains = false; foreach (SimulatorThread s in runningSimulations) { if (s.simulation == simulation) { contains = true; break; } } if (!contains) { simulation.setSimulationListener(listener); //start a thread for the simulation and return SimulatorThread threadTarget = new SimulatorThread(simulation); Thread newThread = new Thread(new ThreadStart(threadTarget.run)); threadTarget.runningThread = newThread; runningSimulations.AddLast(threadTarget); newThread.Start(); } } }
/// <summary> /// Constructor for the Simulator /// </summary> /// <param name="name"> /// A <see cref="String"/> /// </param> public Simulation(String name) { this.name = name; this.parameters = new SimulationParameters(); this.SimulationResults = new Results(); this.listener = null; // Seeds the random object this.randomObject = new Random(0); this.snapshotCache = new SnapshotCache(10); this.currentState = null; }
/// <summary> /// Constructor for the Simulator /// </summary> /// <param name="name"> /// A <see cref="String"/> /// </param> public Simulation(String name) { this.name = name; this.parameters = new SimulationParameters(); this.SimulationResults = new Results(); this.listener = null; // Seeds the random object based on the time int seed = Math.Abs((int)(DateTime.Now.Ticks)); System.Console.WriteLine("Seeding simulation random object - seed = "+seed.ToString()); this.randomObject = new Random(seed); this.snapshotCache = new SnapshotCache(10); this.currentState = null; }
public void Init() { if (!initialized) { stepsPerSecond = GetParameter <int>(PARAMETER_STEPS_PER_SECOND, 20); simulationListener = GetParameter <ISimulationListener>(PARAMETER_SIMULATION_LISTENER, null); SimulationTime.simulationTime = fint.zero; SimulationTime.deltaTime = fint.one / fint.CreateFromInt(stepsPerSecond); for (int i = 0; i < componentManagers.Count; i++) { componentManagers[i].InitDependencies(this); } for (int i = 0; i < componentManagers.Count; i++) { componentManagers[i].Init(); } initialized = true; } }
public void setSimulationListener(ISimulationListener listener) { this.listener = listener; }
/// <summary> /// Must be called at the end of a simulation to release the CVODE cell models /// </summary> public void EndSimulation() { this.runningStatus = false; listener = null; this.ReleaseCells(); }