Пример #1
0
            //Function
            public bool VerifyReaction(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;
                if (temp == 0)
                    return false;

                return true;
            }
Пример #2
0
        public static void MatterPhyCollision(Matter m1, Matter m2)
        {
            //If not matching but m1 can absorb m2
            if (m2._myType.IsStackable && m1._myType.IsPermeable && m1.TotalMass * _naturalAbsorbtionRation >= m2.TotalMass)
            {
                m1.AbsorbMatter(m2);
                return;
            }
            //Handle complementary case of above
            else if (m1._myType.IsStackable && m2._myType.IsPermeable && m1.TotalMass * _naturalAbsorbtionRation >= m2.TotalMass)
            {
                m2.AbsorbMatter(m1);
                return;
            }
            else if (m1.TotalMass + m2.TotalMass < 1500)
            {
                //If matchign types
                if (m1.TypeMatches(m2))
                {
                    m1.AbsorbMatter(m2);
                    return;
                }

                //If not matching but m1 can absorb m2
                if (m2._myType.IsStackable && m1._myType.IsPermeable)
                {
                    m1.AbsorbMatter(m2);
                    return;
                }

                //Handle complementary case of above
                if (m1._myType.IsStackable && m2._myType.IsPermeable)
                {
                    m2.AbsorbMatter(m1);
                    return;
                }
            }
            else
                Matter.MassNeighborEqualize(m1, m2);

            Matter.HeatNeighborEqualize(m1, m2);
        }
Пример #3
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;
            }