/// <summary> /// Change all the parameters of the StellarClass. /// TODO: Add more check to prevent impossible values like Temperature = 1K. Could be by calculating typical distance per components instead of global. /// </summary> /// <remarks> /// This method search for the nearest existing StellarType and then adjust the parameters with the values specified. Right now impossible values are /// allowed, like a star with a 1K Temperature. /// /// TODO: Add more check to prevent impossible values like Temperature = 1K. Could be by calculating typical distance per components instead of global. /// </remarks> /// <param name="mass">The new Mass.</param> /// <param name="lum">The new luminosity.</param> /// <param name="temp">The new Temperature.</param> /// <param name="radius">The new Radius.</param> public void Change(Mass mass, Luminosity lum, Temperature temp, Length radius) { var data = (from row in _types orderby Math.Sqrt((!(lum.Value == 0.0) ? Math.Pow(lum.SolarLuminosities - row.Luminosity, 2.0) : 0.0) + (!(radius.Value == 0.0) ? Math.Pow(radius.SolarRadiuses - row.Radius, 2.0) : 0.0) + (!(mass.Value == 0.0) ? Math.Pow(mass.SolarMasses - row.Mass, 2.0) : 0.0) + (!(temp.Value == 0.0) ? Math.Pow(temp.Kelvins / GlobalConstants.EARTH_SUN_TEMPERATURE - row.Temperature / GlobalConstants.EARTH_SUN_TEMPERATURE, 2.0) : 0.0)) ascending select row).FirstOrDefault(); StellarType st = FromString(data.Type); SpectralClass = st.SpectralClass; LuminosityClass = st.LuminosityClass; SubType = st.SubType; double m = st.Mass.SolarMasses; double l = st.Luminosity.SolarLuminosities; double t = st.Temperature.Kelvins; double r = st.Radius.SolarRadiuses; Mass = !(mass.Value == 0.0) ? mass : Mass.FromSolarMasses(m); Luminosity = !(lum.Value == 0.0) ? lum : Luminosity.FromSolarLuminosities(l); Temperature = !(temp.Value == 0.0) ? temp : Temperature.FromKelvins(t); Radius = !(radius.Value == 0.0) ? radius : Length.FromSolarRadiuses(r); Color = ConvertColor(data.ColorRGB); }
private StellarBody GetTestStar() { return(new Star(Mass.FromSolarMasses(1.0), Luminosity.FromSolarLuminosities(1.0), Duration.FromYears365(1e10)) { Science = new BodyPhysics() }); }
public virtual Luminosity GetLuminosityFromMass(Mass m) { var massRatio = m.SolarMasses; //var massRatio = massRatioParam.SolarMasses; if (massRatio <= 0.6224) { return(Luminosity.FromSolarLuminosities(0.3815 * Math.Pow(massRatio, 2.5185))); } else if (massRatio <= 1.0) { return(Luminosity.FromSolarLuminosities(Math.Pow(massRatio, 4.551))); } else if (massRatio <= 3.1623) { return(Luminosity.FromSolarLuminosities(Math.Pow(massRatio, 4.351))); } else if (massRatio <= 16.0) { return(Luminosity.FromSolarLuminosities(2.7563 * Math.Pow(massRatio, 3.4704))); } else { return(Luminosity.FromSolarLuminosities(42.321 * Math.Pow(massRatio, 2.4853))); } }
public void GetOrbitalZone() { Luminosity luminosity = Luminosity.FromSolarLuminosities(1.0); Length orbitalRadius = Length.FromAstronomicalUnits(1.0); Assert.AreEqual(Env.OrbitalZone(luminosity.SolarLuminosities, orbitalRadius.AstronomicalUnits), _phy.Astronomy.GetOrbitalZone(luminosity, orbitalRadius) ); }
public void GetMinimumIllumination() { Length a = Length.FromAstronomicalUnits(1.0); Luminosity l = Luminosity.FromSolarLuminosities(1.0); Assert.AreEqual(Env.MinimumIllumination(a.AstronomicalUnits, l.SolarLuminosities), _phy.Astronomy.GetMinimumIllumination(a, l).DecimalFractions, LowDelta); }
public void TestSunIllumination() { var phy = new BodyPhysics(); var expectedValue = 1.0; var sunLuminosity = Luminosity.FromSolarLuminosities(1.0); var earthSemiMajorAxis = Length.FromAstronomicalUnits(1.0); Assert.AreEqual(expectedValue, phy.GetMinimumIllumination(earthSemiMajorAxis, sunLuminosity).DecimalFractions); }
public void TestSunEcosphere() { const double expectedValue = 1.0; const double sunLuminosity = 1.0; var phy = new BodyPhysics(); Assert.AreEqual(expectedValue, phy.Astronomy.GetEcosphereRadius(Mass.FromSolarMasses(1.0), Luminosity.FromSolarLuminosities(sunLuminosity)).AstronomicalUnits, 0.0001); }
/// <summary> /// Initializes a new instance of the <see cref="StellarType"/> class. /// </summary> /// <param name="sc">The SpectralClass of the StellarBody.</param> /// <param name="lc">The LuminosityClass of the StellarBody.</param> /// <param name="subType">Type subtype of the StellarBody.</param> public StellarType(SpectralClass sc, LuminosityClass lc, int subType = 0) { SpectralClass = sc; LuminosityClass = lc; SubType = subType; var str = Enum.GetName(typeof(SpectralClass), sc) + SubType.ToString() + (lc != LuminosityClass.O ? Enum.GetName(typeof(LuminosityClass), lc) : ""); var data = (from row in _types where row.Type == str select new { row.Temperature, row.Mass, row.Radius, row.Luminosity, row.ColorRGB }).FirstOrDefault(); Temperature = Temperature.FromKelvins(data.Temperature); Mass = Mass.FromSolarMasses(data.Mass); Luminosity = Luminosity.FromSolarLuminosities(data.Luminosity); Radius = Length.FromKilometers(data.Radius * GlobalConstants.KM_SUN_RADIUS); Color = ConvertColor(data.ColorRGB); }
public void ConversionRoundTrip() { Luminosity watt = Luminosity.FromWatts(1); AssertEx.EqualTolerance(1, Luminosity.FromDecawatts(watt.Decawatts).Watts, DecawattsTolerance); AssertEx.EqualTolerance(1, Luminosity.FromDeciwatts(watt.Deciwatts).Watts, DeciwattsTolerance); AssertEx.EqualTolerance(1, Luminosity.FromFemtowatts(watt.Femtowatts).Watts, FemtowattsTolerance); AssertEx.EqualTolerance(1, Luminosity.FromGigawatts(watt.Gigawatts).Watts, GigawattsTolerance); AssertEx.EqualTolerance(1, Luminosity.FromKilowatts(watt.Kilowatts).Watts, KilowattsTolerance); AssertEx.EqualTolerance(1, Luminosity.FromMegawatts(watt.Megawatts).Watts, MegawattsTolerance); AssertEx.EqualTolerance(1, Luminosity.FromMicrowatts(watt.Microwatts).Watts, MicrowattsTolerance); AssertEx.EqualTolerance(1, Luminosity.FromMilliwatts(watt.Milliwatts).Watts, MilliwattsTolerance); AssertEx.EqualTolerance(1, Luminosity.FromNanowatts(watt.Nanowatts).Watts, NanowattsTolerance); AssertEx.EqualTolerance(1, Luminosity.FromPetawatts(watt.Petawatts).Watts, PetawattsTolerance); AssertEx.EqualTolerance(1, Luminosity.FromPicowatts(watt.Picowatts).Watts, PicowattsTolerance); AssertEx.EqualTolerance(1, Luminosity.FromSolarLuminosities(watt.SolarLuminosities).Watts, SolarLuminositiesTolerance); AssertEx.EqualTolerance(1, Luminosity.FromTerawatts(watt.Terawatts).Watts, TerawattsTolerance); AssertEx.EqualTolerance(1, Luminosity.FromWatts(watt.Watts).Watts, WattsTolerance); }
public void TestLuminosityToSpectral() { var st1 = StellarType.FromLuminosityAndRadius(Luminosity.FromSolarLuminosities(0.16378798), Length.FromSolarRadiuses(0.72014487)); Console.WriteLine(st1.ToString()); Console.WriteLine("Mass = " + st1.Mass); Console.WriteLine("Temperature = " + st1.Temperature); Console.WriteLine("Luminosity = " + st1.Luminosity); Console.WriteLine("Radius = " + st1.Radius); var st2 = StellarType.FromString(st1.ToString()); Console.WriteLine(st2.SpectralClass); Console.WriteLine(st2.LuminosityClass); Console.WriteLine(st2.SubType); Console.WriteLine("Mass = " + st2.Mass); Console.WriteLine("Temperature = " + st2.Temperature); Console.WriteLine("Luminosity = " + st2.Luminosity); Console.WriteLine("Radius = " + st2.Radius); Assert.IsTrue(Math.Abs(st2.Temperature.Kelvins - 4327.0) <= 150.0); }
public void NumberToSolarLuminositiesTest() => Assert.Equal(Luminosity.FromSolarLuminosities(2), 2.SolarLuminosities());
public void TestTemperatureToSpectral() { var st1 = StellarType.FromTemperatureAndLuminosity(Temperature.FromKelvins(4417.3335), Luminosity.FromSolarLuminosities(0.17183004)); Console.WriteLine(st1.ToString()); Console.WriteLine(st1.Temperature); Console.WriteLine(st1.Luminosity); Assert.AreEqual(4417.3335, st1.Temperature.Kelvins); Assert.AreEqual(0.17183004, st1.Luminosity.SolarLuminosities); var st2 = StellarType.FromString(st1.ToString()); Console.WriteLine(st2.Temperature); Console.WriteLine(st2.Luminosity); Assert.IsTrue(Math.Abs(st2.Temperature.Kelvins - 4417.3335) <= 150.0); }
public void TestTemperatureAndLuminosity() { StellarType st = StellarType.FromTemperatureAndLuminosity(Temperature.FromKelvins(20000.0), Luminosity.FromSolarLuminosities(2.0)); Console.WriteLine(st.ToString()); Console.WriteLine(st.Luminosity); Console.WriteLine(st.Mass); Console.WriteLine(st.Temperature); Console.WriteLine(st.Radius); }
public static Luminosity SolarLuminosities <T>(this T value) => Luminosity.FromSolarLuminosities(Convert.ToDouble(value));
/// <summary> /// Give the StellarType given a Temperature. /// </summary> /// <remarks> /// Assume a Luminosity of 0.0 Solar luminosity. /// </remarks> /// <param name="eff_temp">The eff temperature.</param> /// <returns>Nearest StellarType with modified parameters.</returns> public static StellarType FromTemperature(Temperature eff_temp) { return(FromTemperatureAndLuminosity(eff_temp, Luminosity.FromSolarLuminosities(0.0))); }