Example #1
0
        private BatchProblemNoDiffusion CreateExampleOne()
        {
            //components
            var componentList = new List <Component>();

            componentList.Add(new Component("A", "A"));
            componentList.Add(new Component("B", "B"));

            // define partial reactions
            var ListReaction1LHS = new List <ReactionElement>();
            var ListReaction1RHS = new List <ReactionElement>();

            ListReaction1LHS.Add(new ReactionElement(componentList[0], 1));
            ListReaction1RHS.Add(new ReactionElement(componentList[1], 1));

            var Reaction1 = new ElementaryReaction(ListReaction1LHS, ListReaction1RHS, 250000, 50000, 125000, 52000);

            //make globalreaction
            List <ElementaryReaction> reactionList = new List <ElementaryReaction> {
                Reaction1
            };
            var GlobalReaction = new GlobalReaction(reactionList);

            var returnproblem = new BatchProblemNoDiffusion(1000.0, 10, GlobalReaction);

            returnproblem.InitialConcentration = new Dictionary <Component, double>(new Component.EqualityComparer());

            return(returnproblem);
        }
Example #2
0
        private static BatchProblemNoDiffusion CreateProblem()
        {
            var componentList = MakeComponents();

            // define partial reactions
            //B + E -> P
            var ListReaction1LHS = new List <ReactionElement>();
            var ListReaction1RHS = new List <ReactionElement>();

            ListReaction1LHS.Add(new ReactionElement(componentList[1].Copy(), 1));
            ListReaction1LHS.Add(new ReactionElement(componentList[4].Copy(), 1));
            ListReaction1RHS.Add(new ReactionElement(componentList[5].Copy(), 1));

            var Reaction1 = new ElementaryReaction(ListReaction1LHS, ListReaction1RHS, 250000, 60000, 62500, 76000);

            //B + A -> BA
            var ListReaction2LHS = new List <ReactionElement>();
            var ListReaction2RHS = new List <ReactionElement>();

            ListReaction2LHS.Add(new ReactionElement(componentList[1].Copy(), 1));
            ListReaction2LHS.Add(new ReactionElement(componentList[0].Copy(), 1));
            ListReaction2RHS.Add(new ReactionElement(componentList[6].Copy(), 1));

            var Reaction2 = new ElementaryReaction(ListReaction2LHS, ListReaction2RHS, 250000, 50000, 125000, 22000);

            //BA + E => P + A
            var ListReaction3LHS = new List <ReactionElement>();
            var ListReaction3RHS = new List <ReactionElement>();

            ListReaction3LHS.Add(new ReactionElement(componentList[6].Copy(), 1));
            ListReaction3LHS.Add(new ReactionElement(componentList[4].Copy(), 1));
            ListReaction3RHS.Add(new ReactionElement(componentList[5].Copy(), 1));
            ListReaction3RHS.Add(new ReactionElement(componentList[0].Copy(), 1));

            var Reaction3 = new ElementaryReaction(ListReaction3LHS, ListReaction3RHS, 300000, 18000, 150000, 64000);

            //dummy reaction C + D => P

            var ListReaction4LHS = new List <ReactionElement>();
            var ListReaction4RHS = new List <ReactionElement>();

            ListReaction4LHS.Add(new ReactionElement(componentList[2].Copy(), 1));
            ListReaction4LHS.Add(new ReactionElement(componentList[3].Copy(), 1));
            ListReaction4RHS.Add(new ReactionElement(componentList[5].Copy(), 1));

            var Reaction4 = new ElementaryReaction(ListReaction4LHS, ListReaction4RHS, 0, 1000000, 0, 1000000);

            //make globalreaction
            List <ElementaryReaction> reactionList = new List <ElementaryReaction> {
                Reaction1, Reaction2, Reaction3, Reaction4
            };
            var GlobalReaction = new GlobalReaction(reactionList);

            return(new BatchProblemNoDiffusion(1000.0, 10, GlobalReaction));
        }
        public Dictionary <Component, double> UpdateConcentration(ElementaryReaction reaction, Dictionary <Component, double> currentConcentration, double currentTemperature, double timestep)
        {
            var returnDictionary = new Dictionary <Component, double>(new Component.EqualityComparer());

            //calculate rate
            double prodConcentration = 1.0;

            foreach (var reactionElement in reaction.LeftHandSide)
            {
                prodConcentration = prodConcentration * Math.Pow(currentConcentration[reactionElement.ReactionComponent], reactionElement.Power);
            }
            var forwardRate = reaction.ForwardRateCoefficient(currentTemperature) * prodConcentration * timestep;

            prodConcentration = 1.0;
            foreach (var reactionElement in reaction.RightHandSide)
            {
                prodConcentration = prodConcentration * Math.Pow(currentConcentration[reactionElement.ReactionComponent], reactionElement.Power);
            }
            var backwardRate = reaction.BackwardRateCoefficient(currentTemperature) * prodConcentration * timestep;

            //calculate concentration changes associated to rates
            foreach (var element in reaction.LeftHandSide)
            {
                if (!returnDictionary.ContainsKey(element.ReactionComponent))
                {
                    returnDictionary.Add(element.ReactionComponent.Copy(), (backwardRate - forwardRate) * element.Power);
                }
                else
                {
                    returnDictionary[element.ReactionComponent] += (backwardRate - forwardRate) * element.Power;
                }
            }

            foreach (var element in reaction.RightHandSide)
            {
                if (!returnDictionary.ContainsKey(element.ReactionComponent))
                {
                    returnDictionary.Add(element.ReactionComponent.Copy(), (-backwardRate + forwardRate) * element.Power);
                }
                else
                {
                    returnDictionary[element.ReactionComponent] += (-backwardRate + forwardRate) * element.Power;
                }
            }

            return(returnDictionary);
        }
Example #4
0
        public static BatchProblemNoDiffusion CreateExample()
        {
            var componentList = MakeComponents();

            // define partial reactions
            var ListReaction1LHS = new List <ReactionElement>();
            var ListReaction1RHS = new List <ReactionElement>();

            ListReaction1LHS.Add(new ReactionElement(componentList[0], 1));
            ListReaction1RHS.Add(new ReactionElement(componentList[1], 1));

            var Reaction1 = new ElementaryReaction(ListReaction1LHS, ListReaction1RHS, 250000, 50000, 125000, 52000);

            //make globalreaction
            List <ElementaryReaction> reactionList = new List <ElementaryReaction> {
                Reaction1
            };
            var GlobalReaction = new GlobalReaction(reactionList);

            return(new BatchProblemNoDiffusion(1000.0, 10, GlobalReaction));
        }
Example #5
0
        private BatchProblemNoDiffusion CreateExampleTwo()
        {
            //components
            var componentList = new List <Component>();

            componentList.Add(new Component("A", "A"));
            componentList.Add(new Component("B", "B"));
            componentList.Add(new Component("C", "C"));

            // define partial reactions
            var ListReaction1LHS = new List <ReactionElement>();
            var ListReaction1RHS = new List <ReactionElement>();

            ListReaction1LHS.Add(new ReactionElement(componentList[0], 1));
            ListReaction1RHS.Add(new ReactionElement(componentList[1], 1));

            var Reaction1 = new ElementaryReaction(ListReaction1LHS, ListReaction1RHS, 250000, 40000, 125000, 42000);

            var ListReaction2LHS = new List <ReactionElement>();
            var ListReaction2RHS = new List <ReactionElement>();

            ListReaction2LHS.Add(new ReactionElement(componentList[1], 1));
            ListReaction2RHS.Add(new ReactionElement(componentList[2], 1));

            var Reaction2 = new ElementaryReaction(ListReaction2LHS, ListReaction2RHS, 220000, 51000, 0, 52000);

            //make globalreaction
            List <ElementaryReaction> reactionList = new List <ElementaryReaction> {
                Reaction1, Reaction2
            };
            var GlobalReaction = new GlobalReaction(reactionList);

            var returnproblem = new BatchProblemNoDiffusion(1000.0, 10, GlobalReaction);

            return(returnproblem);
        }