public Atmosphere(ChemicalComposition _composition)
 {
     foreach (ChemicalElement element in _composition.get_elements())
     {
         if (Atmosphere.GreenhouseGases.greenHouseGases.Where(x => x.Equals(element.name,
                                                                            StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault() != null)
         {
             greenHouseComposition.addElementToComposition(element, _composition.get_percentage_per_element(element));
         }
         else
         {
             non_greenHouseComposition.addElementToComposition(element, _composition.get_percentage_per_element(element));
         }
     }
 }
Example #2
0
        public void initStar(double _densityMul = 1.0, double rel_mass = 1.0, List <double> percentage = null)
        {
            ChemicalComposition chemicalComposition = new ChemicalComposition(this.stellarCompositionMats, percentage);

            this.starComposition = chemicalComposition;
            elementsDistribution = percentage;
            NumberFormatInfo nfi        = new NumberFormatInfo();
            Random_Extension randomSeed = new Random_Extension();

            nfi.NumberDecimalSeparator = ".";
            Function hydrostaticEquilibrium = ParametriUtente.Science.hydrostaticEquilibrium;
            int      randomGenForBlackHoles;
            //mass in grammi / 18.015 = moles
            //ideal gas law
            double molecularWeight = 0.0;
            double sumofElement    = 0.0;

            double pressione;

            this.meanDensity = 0;


            randomGenForBlackHoles = randomSeed.Next(0, 1);



            foreach (ChemicalElement element in starComposition.get_elements())
            {
                double currentElement = starComposition.get_percentage_per_element(element);

                sumofElement    = sumofElement + currentElement;
                molecularWeight = (molecularWeight + (element.mass)
                                   );
            }
            molecularWeight = molecularWeight / sumofElement;

            this.Volume = ((Math.Pow(this.starRadius, 3) * (4.0 / 3.0)) * Math.PI); //km3

            this.mass = rel_mass * ParametriUtente.Science.m_sun;

            this.luminosity = SimulationEngine.getLuminosityFromMass(this.mass);

            this.meanDensity = (this.mass * 1000 / (Math.Pow(10, 15) * Volume)) * _densityMul;


            pressione = ((ParametriUtente.Science.G
                          * mass
                          * (Converter.gcm3_to_kgm3(this.meanDensity)))
                         / (this.starRadius * 1000));

            this.Core_temperature = ((0.84 * Math.Pow(10, -27)) * pressione)
                                    / ((Converter.gcm3_to_kgm3(this.meanDensity))
                                       * (1.380649 * Math.Pow(10, -23)));

            this.Core_temperature = this.Core_temperature * 1.3;


            this.Surface_temperature = SimulationEngine.getTemperatureFromLumRadiusRatio(this.starRadius, this.luminosity);//this.Core_temperature / (2717.203184);//2543.37;

            if (randomGenForBlackHoles == 0)
            {
                this.starRadius      = this.getSchwarzschildRadius();
                this.Volume          = ((Math.Pow(this.starRadius, 3) * (4.0 / 3.0)) * Math.PI); //km3
                this.meanDensity     = (this.mass * 1000 / (Math.Pow(10, 15) * Volume));
                this.Surface_density = this.meanDensity;
                this.Core_density    = this.meanDensity;
            }


            this.setRelativeValues();

            this.InitStarClassification();

            this.finalizeStar();
        }
        public void mergeCompositions(ChemicalComposition _composition)
        {
            if (_composition == null)
            {
                return;
            }
            List <ChemicalElement> toBeMergedElements = _composition.get_elements(), newChemicalElements = new List <ChemicalElement>();
            List <double>          toBeMergedPercentage = _composition.get_percentage();

            List <element_percentage> newcomposition = new List <element_percentage>();
            int    c = 0;
            double perc = 0;
            double totalePerc = 200, addedPerc = 100;

            foreach (ChemicalElement element in toBeMergedElements)
            {
                if (this.getElementFromName(element.name) != null)
                {
                    perc = toBeMergedPercentage.ElementAt(c) + this.get_percentage_per_element(element);
                    newChemicalElements.Add(element);
                }
                else
                {
                    perc = toBeMergedPercentage.ElementAt(c);
                    newChemicalElements.Add(element);
                }

                if (perc > 30)
                {
                    perc = perc / 30;
                }
                addedPerc  = addedPerc + perc;
                totalePerc = 100.0 + perc;
                newcomposition.Add(new element_percentage(element, perc * 100 / totalePerc)
                                   );
                c++;
            }

            c = 0;

            foreach (ChemicalElement element in this.get_elements())
            {
                if (newChemicalElements.Where(x => x.name == element.name).FirstOrDefault() == null)
                {
                    perc = this.get_percentage_per_element(element);
                    newChemicalElements.Add(this.get_elements().ElementAt(c));
                }
                else
                {
                    perc = this.get_percentage_per_element(element);
                    perc = perc + newcomposition.Where(x => x.el.name == element.name).FirstOrDefault().percentage;
                    newcomposition.Remove(newcomposition.Where(x => x.el.name == element.name).FirstOrDefault());
                }

                newcomposition.Add(new element_percentage(element, perc * 100 / addedPerc)
                                   );
                c++;
            }

            this.elements_percentage_list = newcomposition;
        }