Пример #1
0
        public void TestReactionSet2()
        {
            SpeciesDescription info1;
            Species            reactant1;

            CreateSpeciesInfoAndSpecies("reactant1", 10, out info1, out reactant1);
            SpeciesDescription info2;
            Species            reactant2;

            CreateSpeciesInfoAndSpecies("reactant2", 40, out info2, out reactant2);
            SpeciesDescription info3;
            Species            product1;

            CreateSpeciesInfoAndSpecies("product1", 90, out info3, out product1);
            SpeciesDescription info4;
            Species            reactant3;

            CreateSpeciesInfoAndSpecies("reactant3", 1, out info4, out reactant3);
            SpeciesDescription info5;
            Species            reactant4;

            CreateSpeciesInfoAndSpecies("reactant4", 2, out info5, out reactant4);
            SpeciesDescription info6;
            Species            product2;

            CreateSpeciesInfoAndSpecies("product2", 3, out info6, out product2);

            const double rate1 = 2.0;
            const double rate2 = 3.0;

            Reaction reaction1 = CreateReaction(info1, reactant1, info2, reactant2, info3, product1, rate1);
            Reaction reaction2 = CreateReaction(info4, reactant3, info5, reactant4, info6, product2, rate2);

            var reactions = new List <Reaction> {
                reaction1, reaction2
            };
            var reactionSet = new ReactionSet(reactions);

            double[] gamma = { 1.5, 2 };
            Assert.AreEqual(9.0, reactionSet.UpdateRates(gamma));
            Assert.AreEqual(3.0, reactionSet.CurrentRates[1]);
            Assert.AreEqual(3.0, reactionSet.PredilectionRates[0]);
            Assert.AreEqual(2, reactionSet.NumReactions);

            reactionSet.FireReaction(0);
            Assert.AreEqual(9, reactant1.Value);
            Assert.AreEqual(39, reactant2.Value);
            Assert.AreEqual(91, product1.Value);

            reactionSet.FireReaction(1);
            Assert.AreEqual(0, reactant3.Value);
            Assert.AreEqual(1, reactant4.Value);
            Assert.AreEqual(4, product2.Value);

            int mu = reactionSet.SelectReaction(reactionSet.CurrentRates.Sum());

            Assert.AreEqual(1, mu);
            mu = reactionSet.SelectReaction(0.0);
            Assert.AreEqual(0, mu);
        }
Пример #2
0
        public void TestReactionSet1()
        {
            SpeciesDescription info1;
            Species            reactant1;

            CreateSpeciesInfoAndSpecies("reactant1", 10, out info1, out reactant1);
            SpeciesDescription info2;
            Species            reactant2;

            CreateSpeciesInfoAndSpecies("reactant2", 40, out info2, out reactant2);
            SpeciesDescription info3;
            Species            product1;

            CreateSpeciesInfoAndSpecies("product1", 90, out info3, out product1);

            const double rate1     = 2.0;
            Reaction     reaction1 = CreateReaction(info1, reactant1, info2, reactant2, info3, product1, rate1);

            Assert.AreEqual(reaction1.Reactants[0], reactant1);
            Assert.AreEqual(reaction1.Reactants[1], reactant2);
            Assert.AreEqual(reaction1.Products[0], product1);

            var reactions = new List <Reaction> {
                reaction1
            };
            var reactionSet1 = new ReactionSet(reactions);

            Assert.AreEqual(reactionSet1.Reactions[0].Name, reactions[0].Name);

            double[] gamma = { 2.0 };
            Assert.AreEqual(4.0, reactionSet1.UpdateRates(gamma));
            Assert.AreEqual(4.0, reactionSet1.PredilectionRates[0]);
            Assert.AreEqual(2.0, reactionSet1.CurrentRates[0]);
            Assert.AreEqual(1, reactionSet1.NumReactions);

            reactionSet1.FireReaction(0);
            Assert.AreEqual(9, reactant1.Value);
            Assert.AreEqual(39, reactant2.Value);
            Assert.AreEqual(91, product1.Value);

            reactionSet1.FireReaction(0);
            Assert.AreEqual(8, reactant1.Value);
            Assert.AreEqual(38, reactant2.Value);
            Assert.AreEqual(92, product1.Value);
        }