public void TestGenerateTimeSeries() { // simulation MuCell.Model.Simulation simulation = new MuCell.Model.Simulation("simulation1"); // experiment MuCell.Model.Experiment experiment = new MuCell.Model.Experiment("experiment1"); // Hopf model MuCell.Model.SBML.Reader.SBMLReader s = new MuCell.Model.SBML.Reader.SBMLReader("../../UnitTests/smallest.Hopf.level2.xml"); List<MuCell.Model.SBML.Model> models = new List<MuCell.Model.SBML.Model>(); models.Add(s.model); // Cell definition MuCell.Model.CellDefinition celldef1 = new MuCell.Model.CellDefinition("celldef1"); celldef1.addSBMLModel(s.model); experiment.addCellDefinition(celldef1); // Cells List<MuCell.Model.CellInstance> cells = new List<MuCell.Model.CellInstance>(); for(int i=0;i<5;i++) { cells.Add(celldef1.createCell()); } // StateSnapshot for intial state MuCell.Model.StateSnapshot initialState = new MuCell.Model.StateSnapshot(cells); MuCell.Model.Vector3 size = new MuCell.Model.Vector3(1, 1, 1); initialState.SimulationEnvironment = new MuCell.Model.Environment(size); // trime series MuCell.Model.TimeSeries ts1 = new MuCell.Model.TimeSeries("Average X", "X/celldef1", 0.01001d); ts1.Initialize(models, experiment, simulation); MuCell.Model.TimeSeries ts2 = new MuCell.Model.TimeSeries("Total X", "X", 0.01001d); ts2.Initialize(models, experiment, simulation); // Parameters MuCell.Model.SimulationParameters parameters = new MuCell.Model.SimulationParameters(); parameters.TimeSeries.Add(ts1); parameters.TimeSeries.Add(ts2); parameters.InitialState = initialState; parameters.SimulationLength = 0.04004d; parameters.SnapshotInterval = 1; parameters.StepTime = 0.01001d; parameters.RelativeTolerance = 1E-8; parameters.SolverMethod = MuCell.Model.Solver.SolverMethods.RungeKutta; // Simulation simulation.Parameters = parameters; // Start simulation simulation.StartSimulation(); // Now check the results Assert.AreEqual(5, ts1.Series.Count); Assert.AreEqual(5, ts2.Series.Count); double[] ts = ts1.Series.ToArray(); double[] tst = ts2.Series.ToArray(); Assert.AreEqual(2.5d, ts[0]); AssertDouble.AreEqual(rk_x_t1, ts[1]); AssertDouble.AreEqual(rk_x_t2, ts[2]); AssertDouble.AreEqual(rk_x_t3, ts[3]); AssertDouble.AreEqual(rk_x_t4, ts[4]); Assert.AreEqual(5*2.5d, tst[0]); AssertDouble.AreEqual(5*rk_x_t1, tst[1]); AssertDouble.AreEqual(5*rk_x_t2, tst[2]); AssertDouble.AreEqual(5*rk_x_t3, tst[3]); AssertDouble.AreEqual(5*rk_x_t4, tst[4]); }
public void InvalidTimeSeriesEquation() { // simulation MuCell.Model.Simulation simulation = new MuCell.Model.Simulation("simulation1"); // experiment MuCell.Model.Experiment experiment = new MuCell.Model.Experiment("experiment1"); // Hopf model MuCell.Model.SBML.Reader.SBMLReader s = new MuCell.Model.SBML.Reader.SBMLReader("../../UnitTests/smallest.Hopf.level2.xml"); List<MuCell.Model.SBML.Model> models = new List<MuCell.Model.SBML.Model>(); models.Add(s.model); // Cell definition MuCell.Model.CellDefinition celldef1 = new MuCell.Model.CellDefinition("celldef1"); celldef1.addSBMLModel(s.model); experiment.addCellDefinition(celldef1); // Cells List<MuCell.Model.CellInstance> cells = new List<MuCell.Model.CellInstance>(); for(int i=0;i<5;i++) { cells.Add(celldef1.createCell()); } // StateSnapshot for intial state MuCell.Model.StateSnapshot initialState = new MuCell.Model.StateSnapshot(cells); MuCell.Model.Vector3 size = new MuCell.Model.Vector3(1, 1, 1); initialState.SimulationEnvironment = new MuCell.Model.Environment(size); // Parameters simulation.Parameters.InitialState = initialState; simulation.Parameters.SimulationLength = 3; simulation.Parameters.SnapshotInterval = 1; simulation.Parameters.StepTime = 1; // Time series MuCell.Model.TimeSeries ts1 = new MuCell.Model.TimeSeries("Average A", "(A)", 1.0); ts1.Initialize(models, experiment, simulation); }
public void RunHopfSimulationRK(MuCell.Model.SBML.Reader.SBMLReader s) { // Cell definition MuCell.Model.CellDefinition celldef1 = new MuCell.Model.CellDefinition("celldef1"); celldef1.addSBMLModel(s.model); // Cells List<MuCell.Model.CellInstance> cells = new List<MuCell.Model.CellInstance>(); MuCell.Model.CellInstance cell1 = celldef1.createCell(); cells.Add(cell1); // StateSnapshot for intial state MuCell.Model.StateSnapshot initialState = new MuCell.Model.StateSnapshot(cells); MuCell.Model.Vector3 size = new MuCell.Model.Vector3(1, 1, 1); initialState.SimulationEnvironment = new MuCell.Model.Environment(size); // Parameters MuCell.Model.SimulationParameters parameters = new MuCell.Model.SimulationParameters(); parameters.InitialState = initialState; parameters.SimulationLength = 0.01001d; parameters.SnapshotInterval = 2; parameters.StepTime = 0.01001d; parameters.SolverMethod = MuCell.Model.Solver.SolverMethods.RungeKutta; // Simulation MuCell.Model.Simulation simulation = new MuCell.Model.Simulation("simulation1"); simulation.Parameters = parameters; // Assert that is not complete at all Assert.AreEqual(0.0d, simulation.SimulationProgress()); // Test the initial conditions Assert.AreEqual(1.0d, cell1.getSpeciesAmount("A")); Assert.AreEqual(2.5d, cell1.getSpeciesAmount("X")); Assert.AreEqual(2.5d, cell1.getSpeciesAmount("Y")); Assert.AreEqual(2.5d, cell1.getSpeciesAmount("Z")); Assert.AreEqual(0.0d, cell1.getSpeciesAmount("_void_")); // Start simulation simulation.StartSimulation(); // Assert that is complete Assert.AreEqual(1.0d, simulation.SimulationProgress()); // Test the results (test generated from the Python model) AssertDouble.AreEqual(1.0d, cell1.getSpeciesAmount("A")); AssertDouble.AreEqual(rk_x_t1, cell1.getSpeciesAmount("X")); AssertDouble.AreEqual(rk_y_t1, cell1.getSpeciesAmount("Y")); AssertDouble.AreEqual(rk_z_t1, cell1.getSpeciesAmount("Z")); Assert.AreEqual(0.0d, cell1.getSpeciesAmount("_void_")); // Make the simulation run a bit longer parameters.SimulationLength = 0.02002; simulation.UnPauseSimulation(); AssertDouble.AreEqual(1.0d, cell1.getSpeciesAmount("A")); AssertDouble.AreEqual(rk_x_t2, cell1.getSpeciesAmount("X")); AssertDouble.AreEqual(rk_y_t2, cell1.getSpeciesAmount("Y")); AssertDouble.AreEqual(rk_z_t2, cell1.getSpeciesAmount("Z")); Assert.AreEqual(0.0d, cell1.getSpeciesAmount("_void_")); // Make the simulation run a bit longer parameters.SimulationLength = 0.03003; simulation.UnPauseSimulation(); AssertDouble.AreEqual(1.0d, cell1.getSpeciesAmount("A")); AssertDouble.AreEqual(rk_x_t3, cell1.getSpeciesAmount("X")); AssertDouble.AreEqual(rk_y_t3, cell1.getSpeciesAmount("Y")); AssertDouble.AreEqual(rk_z_t3, cell1.getSpeciesAmount("Z")); Assert.AreEqual(0.0d, cell1.getSpeciesAmount("_void_")); }