コード例 #1
0
        /// <summary>
        ///     Initializes an instance of the <see cref="Shell" /> class.
        /// </summary>
        /// <param name="symbol">The unique symbol for the shell.</param>
        /// <param name="electrons">The initial amount of electrons.</param>
        public Shell(char symbol, int electrons)
        {
            Symbol      = symbol;
            EnergyLevel = Index + 1;

            Subshell s = new Subshell(Symbol, 's', 2),
                     p = new Subshell(Symbol, 'p', 6),
                     d = new Subshell(Symbol, 'd', 10),
                     f = new Subshell(Symbol, 'f', 14);

            Subshells = new List <Subshell> {
                s
            };

            if ((Index >= 1) && (electrons > s.Capacity))
            {
                Subshells.Add(p);
            }

            if ((Index >= 2) && (electrons > p.Capacity))
            {
                Subshells.Add(d);
            }

            if ((Index >= 3) && (electrons > d.Capacity))
            {
                Subshells.Add(f);
            }
        }
コード例 #2
0
        /// <summary>
        /// Populates the current <see cref="ShellConfiguration"/> instance.
        /// </summary>
        public void Populate()
        {
            int left = Element.Electrons;

            for (var i = 0; i < ChemistryUtils.EnergyLevelConfiguration.Count; i++)
            {
                if (left == 0)
                {
                    break;
                }

                KeyValuePair <char, char[]> pair = ChemistryUtils.EnergyLevelConfiguration.ToList()[i];
                Shell shell = this[pair.Key];

                for (int x = 0; x < pair.Value.Length; x++)
                {
                    if (left == 0)
                    {
                        break;
                    }

                    Subshell subshell = shell[pair.Value[x]];

                    if (subshell.Electrons > 0)
                    {
                        continue;
                    }

                    if (left - subshell.Capacity < 0)
                    {
                        subshell.Populate(left);
                        left = 0;
                    }
                    else
                    {
                        subshell.Populate(subshell.Capacity);
                        left -= subshell.Capacity;
                    }

                    int stepsDown = x;
                    for (int z = 0; z < stepsDown; z++)
                    {
                        if (left == 0)
                        {
                            break;
                        }

                        Subshell diagonal = Shells.ToList()[i + z + 1].Subshells[x - (z + 1)];
                        if (left - diagonal.Capacity < 0)
                        {
                            diagonal.Populate(left);
                            left = 0;
                        }
                        else
                        {
                            diagonal.Populate(diagonal.Capacity);
                            left -= diagonal.Capacity;
                        }
                    }
                }
            }

            foreach (var shell in Shells.ToArray())
            {
                foreach (var subshell in shell.Subshells.ToArray())
                {
                    if (subshell.Electrons == 0)
                    {
                        shell.Subshells.Remove(subshell);
                    }
                }

                if (shell.Electrons == 0)
                {
                    Shells.Remove(shell);
                }
            }
        }