コード例 #1
0
            public MatterChunk(Matter parMatter, ElementType newType, int elementUnits)
            {
                this.MyType = newType;

                if (parMatter.ElementUnits - elementUnits <= 0)
                {
                    elementUnits = parMatter.ElementUnits;
                    //throw new Exception("unhandled invalid mass");
                    parMatter.NeedsRemoval = true;
                }

                parMatter.ElementUnits -= elementUnits;
                this.ElementUnits = elementUnits;

                var percSplit = (1.0 * elementUnits / (elementUnits + parMatter.ElementUnits));
                this.MyHeat = parMatter.ReleaseHeat((int)(percSplit * parMatter.ElementHeat));
                this.MyCharge = new Energy();
            }
コード例 #2
0
            public virtual bool React(Matter m)
            {
                //Make sure matter is reactant, otherwise set reversed
                var reversed = false;
                if (this._reversible && m.TypeMatches(this._product))
                    reversed = true;

                //If not reversed and m does not equal reactant, throw exception
                if (!m.TypeMatches(this._reactant) && !reversed)
                    throw new Exception("Matter Object provided does not satisfy given conditions");

                //Get Probability of states
                var temp = 1.0 * m.ElementHeat / m.TotalMass;
                var parts = m.ElementUnits;
                if (temp == 0 || parts == 0)
                    return false;

                //Create Vars
                var muparts = 0;
                var muNparts = 0;
                Matter.ElementType toElement;

                //Handle Case If reversed for muEnergy
                if (reversed)
                {
                    muparts = this._product.Mu;
                    muNparts = this._reactant.Mu;
                    toElement = this._reactant;
                }
                else
                {
                    muparts = this._reactant.Mu;
                    muNparts = this._product.Mu;
                    toElement = this._product;
                }

                var reactKR = Math.Exp((muparts - (muNparts + this._activationEnergy)) / temp);

                if (parts == 0)
                {
                    int a = 7; int b = 3; int c = a / b;
                }

                parts--;
                var ReactionRate = temp * parts * reactKR;

                //If State is greater thanequalto one, then create x amount of new state
                if (ReactionRate > 1)// || StateMuNew >= 1)
                {
                    if (this._reactant.MyName == "DNA")
                    {
                        int a = 7; int b = 3; int c = a / b;
                    }

                    ///////////////////////
                    //Add DATA
                    if (m.Owner != null)
                        m.Owner.MySimulator.MyData.AddData("ReactionRate", ReactionRate);
                    else
                        m.MySimulator.MyData.AddData("ReactionRate", ReactionRate);
                    //////////////////////

                    var enDif = muparts - muNparts;
                    var amt = (int)ReactionRate;

                    if (enDif > 0 && enDif * amt > m.ElementHeat)
                        return false;

                    if (amt > parts)
                        amt = parts;
                    //var amt = (int)StateMuNew;
                    var newChunk = new Matter.MatterChunk(m, toElement, amt);

                    //Handle heat
                    if (enDif < 0)
                        m.ReleaseHeat(amt * Math.Abs(enDif));
                    else if (enDif > 0)
                        m.AbsorbHeat(amt * enDif);
                    else
                        throw new Exception("EnDif is zero or did not interact with environment");
                    var nm = m.AbsorbChunk(newChunk);

                    if (!m.NeedsRemoval && !m.IsRemoved)
                        Matter.HeatNeighborEqualize(nm, m);

                    if (m.IsElementEmpty())
                        m.DegenerateExistence();
                }

                return false;
            }