示例#1
0
        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);
        }
示例#2
0
        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]);
        }