public void InitSystemParams(double[] _parameters, ChemicalComposition _composition) { this.star_densityMul = _parameters[0]; this.starRadius = _parameters[1]; this.starRelativeMass = _parameters[2]; this.composition = _composition; }
public Asteroid(ChemicalComposition _chemical, double radius_Km, double distance_from_star) { this.asteroidRadius = radius_Km; this.asteroidCore = new Core(); body_composition = _chemical; this.distance_from_star = distance_from_star; this.name = this.generate_planet_name(); }
public Planet(ChemicalComposition _chemical, double radius_Km, double distance_from_star) { this.planetRadius = radius_Km; this.planetCore = new Core(); this.planetClass = new PlanetClass("Metallic_Planet"); body_composition = _chemical; this.name = generate_planet_name(); this.distance_from_star = distance_from_star; }
public ChemicalComposition getCompositionFromElements(List <ChemicalElement> _elements) { ChemicalComposition newComposition = new ChemicalComposition(); for (int n = 0; n < _elements.Count; n++) { newComposition.addElementToComposition(_elements[n], this.get_percentage_per_element(_elements[n])); } return(newComposition); }
private void initAtmoSphere(Boolean _isBlackBody = true, int iterations = 10) { double R, T, M, m; R = 8.314462618; T = this.Surface_temperature; ChemicalComposition composition = new ChemicalComposition(); double escapevelocity = Math.Pow((2 * ParametriUtente.Science.G * this.mass) / (this.planetRadius * 1000), (1.0 / 2.0)); ChemicalElement element = null; for (int i = 0; i < 3; i++) { ChemicalElement local_element = this.body_composition.getRandomElement_PerType(ElementState.Gas); if ((element != null && element.name.Equals(local_element.name)) || (local_element == null)) { continue; } element = local_element; double percentage = this.body_composition.get_percentage_per_element(element) / 100; if (composition.getElementFromName(element.name) == null) { composition.addElementToComposition(element, percentage); } m = element.mass / 1000; M = m; double meanVelocityForElement = Math.Pow((2 * R * T) / M, (1.0 / 2.0)); if (meanVelocityForElement > escapevelocity) { composition.removeElementFromComposition(element, percentage); this.body_composition.removeElementFromComposition(element, percentage); } } //prendi la lista di gas //scegli 3 gas // sqrt(2*R*T/M) dove R = gas constant T = Temperature K e M = mass dell'elemento/1000 if (composition.elements_percentage_list.Count > 0) { hasAtmosphere = true; } this.applyChemicalBonds(); }
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)); } } }
public void applyChemicalBonds() { Random random = new Random(); List <ChemicalElement> chemicalElements = this.body_composition.get_elements(); List <ChemicalElement> chosenOnes = new List <ChemicalElement>(); List <int> chosenIndexes = new List <int>(); int elementToCompositeRatio = 1000000; double compositeMass = this.planetMass / elementToCompositeRatio; List <ChemicalElement> generatedElements = new List <ChemicalElement>(); int numberOfElements = chemicalElements.Count(); ChemicalComposition composites = ChemicalEngine.generateComposites(1, this.body_composition); this.body_composition.mergeCompositions(composites); }
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; }
public void createStarSystem() { int supportedPlanets; double habitableZone_min; double habitableZone_max; double jupMass_EarthRadii = 11.209; double multiplierFactor = 1; double radiiMultiplierFactor = 1; double asteroidBeltDistanceMax = 0.0, asteroidBeltDistanceMin = 0.0; int[] supportedAsteroids = new int[] { 100, 2000 }; Random_Extension randomSeed = new Random_Extension(); this.createStarCenter(); //This is measured in AU habitableZone_min = Math.Sqrt(this.stars.getRelLuminosity() / 1.1); habitableZone_max = Math.Sqrt((this.stars.getRelLuminosity() / 0.53)); //everything beyond habitableZone_max has (should have) less than 0° surface temp and be either rocky(frozen) or gas giant //everything beyond habitableZone_min has (should have) more than 40° surfacete temp and can be only a rocky barren planet. randomSeed = new Random_Extension(); asteroidBeltDistanceMax = randomSeed.NextDouble(habitableZone_min * 0.3, habitableZone_max * 10) + ((habitableZone_max - habitableZone_min) / 2); asteroidBeltDistanceMin = asteroidBeltDistanceMax - (habitableZone_max - habitableZone_min); Double radii; int c = 0; Double distance = 0; multiplierFactor = 5; c = 0; while (c < maxSupportedPlanets) { radii = randomSeed.NextDouble() * ((jupMass_EarthRadii * radiiMultiplierFactor) - 0.5) + 0.5; c++; if (radii > 10) { radiiMultiplierFactor = 0.7; } if (c >= (int)(this.maxSupportedPlanets / 2)) { multiplierFactor = 2; } distance = (randomSeed.NextDouble() * ((multiplierFactor * habitableZone_max) - 0.1) + (0.1)); ChemicalComposition chemicalComposition; if (distance > habitableZone_max) { //more chances of a cold gas giant lesser chance of a cold icy planet int planetType = randomSeed.Next(1, 5); if (planetType < 2) { chemicalComposition = new ChemicalComposition(DataEngine.rockyPlanetSeed , SimulationEngine.generateNPercentages(DataEngine.rockyPlanetSeed.Count)); //icy } else { chemicalComposition = new ChemicalComposition(DataEngine.gasPlanetSeed , SimulationEngine.generateNPercentages(DataEngine.gasPlanetSeed.Count)); //gas giant } } else if (distance < habitableZone_min) { //more chances of hot small-to-medium rocky-metallic planet int planetType = randomSeed.Next(1, 5); if (planetType < 2) { chemicalComposition = new ChemicalComposition(DataEngine.rockyPlanetSeed , SimulationEngine.generateNPercentages(DataEngine.rockyPlanetSeed.Count)); if (radii > 5) { radii = radii / (randomSeed.Next(2, 5)); } //rocky with atmosphere } else { chemicalComposition = new ChemicalComposition(DataEngine.rockyPlanetSeed , SimulationEngine.generateNPercentages(DataEngine.rockyPlanetSeed.Count)); //rocky without atmosphere } } else { //slight more chances of a planet with liquid H2O int planetType = randomSeed.Next(1, 5); if (planetType < 2) { chemicalComposition = new ChemicalComposition(DataEngine.rockyPlanetSeed , SimulationEngine.generateNPercentages(DataEngine.rockyPlanetSeed.Count)); //generic rocky planet } else { chemicalComposition = new ChemicalComposition(DataEngine.ironPlanetSeed , SimulationEngine.generateNPercentages(DataEngine.ironPlanetSeed.Count)); //h20 } } Planet createdPlanet; if (radii < 9) { createdPlanet = SimulationEngine.createPlanet(chemicalComposition, radii, distance); } else { createdPlanet = SimulationEngine.createGasGiant(chemicalComposition, radii, distance); } this.planets.Add(createdPlanet); c++; } int numberOfAsteroid = randomSeed.Next(supportedAsteroids[0], supportedAsteroids[1]); for (int i = 0; i < numberOfAsteroid; i++) { ChemicalComposition chemicalComposition = null; chemicalComposition = new ChemicalComposition(DataEngine.carbonAsteroidSeed, SimulationEngine.generateNPercentages(DataEngine.carbonAsteroidSeed.Count, 50)); int seedGen = randomSeed.Next(1, 20); if (seedGen < 19 && seedGen > 15) { chemicalComposition = new ChemicalComposition(DataEngine.siliconAsteroidSeed, SimulationEngine.generateNPercentages(DataEngine.carbonAsteroidSeed.Count, 50)); } else { chemicalComposition = new ChemicalComposition(DataEngine.carbonAsteroidSeed, SimulationEngine.generateNPercentages(DataEngine.carbonAsteroidSeed.Count, 50)); } int radius_Km = randomSeed.Next(1, 500); double relMassSeed = 0.0004; relMassSeed = relMassSeed / (500 % radius_Km); Asteroid asteroid = new Asteroid(chemicalComposition, radius_Km, randomSeed.NextDouble(asteroidBeltDistanceMin, asteroidBeltDistanceMax)); asteroid.initAsteroid(1, relMassSeed); this.asteroidBelt.Add(asteroid); } Console.WriteLine("AU min: " + habitableZone_min + " \n \tAU max: " + habitableZone_max); }