Ejemplo n.º 1
0
 public static float GetGasConstant(CelestialBody body)
 {
     if ((object)body == null)
     {
         return(0f);
     }
     if (bodyOrganizedListOfAtmospheres.ContainsKey(body))
     {
         DREAtmosphereComposition atmosphere = bodyOrganizedListOfAtmospheres[body];
         return(atmosphere.gasConstant);
     }
     return(287.103f);
 }
Ejemplo n.º 2
0
 public static float GetSpecHeatRatio(CelestialBody body)
 {
     if ((object)body == null)
     {
         return(0f);
     }
     if (bodyOrganizedListOfAtmospheres.ContainsKey(body))
     {
         DREAtmosphereComposition atmosphere = bodyOrganizedListOfAtmospheres[body];
         return(atmosphere.specHeatRatio);
     }
     return(1.4f);
 }
Ejemplo n.º 3
0
 public static void CalculateNewTemperatureCurve(object o)
 {
     try
     {
         tempCurveDataContainer   container  = (tempCurveDataContainer)o;
         DREAtmosphereComposition atmosphere = bodyOrganizedListOfAtmospheres[container.body];
         //Debug.Log("Beginning Temperature Curve Calculation");
         Curves result = atmosphere.TemperatureAsFunctionOfVelocity(100, 5, atmosphere.maxSimVelocity);
         container.callingCurve.protoTempCurve  = result.temp;
         container.callingCurve.protoVelCpCurve = result.cp;
         container.callingCurve.referenceTemp   = GetReferenceTemp(container.body);
         if (container.dumpToText)
         {
             container.callingCurve.DumpToText(5, container.body);
         }
     }
     catch (Exception e)
     {
         Debug.LogError("DRE Exception in Temperature Curve Calculation: " + e.StackTrace);
     }
 }
Ejemplo n.º 4
0
        public static void LoadConfigNodes()
        {
            idOrganizedListOfGasSpecies    = new Dictionary <string, DREAtmosphericGasSpecies>();
            bodyOrganizedListOfAtmospheres = new Dictionary <CelestialBody, DREAtmosphereComposition>();
            foreach (ConfigNode node in GameDatabase.Instance.GetConfigNodes("DRE_ATM_GAS_SPECIES"))
            {
                foreach (ConfigNode gasSpeciesNode in node.GetNodes("GAS_SPECIES"))
                {
                    string id = gasSpeciesNode.GetValue("id");
                    DREAtmosphericGasSpecies newSpecies = new DREAtmosphericGasSpecies(id);

                    idOrganizedListOfGasSpecies.Add(id, newSpecies);
                }
            }
            foreach (KeyValuePair <string, DREAtmosphericGasSpecies> pair in idOrganizedListOfGasSpecies)
            {
                pair.Value.Initialize();
            }

            DREAtmosphereComposition defaultOxygenatedRocky   = new DREAtmosphereComposition(),
                                     defaultUnoxygenatedRocky = new DREAtmosphereComposition(),
                                     defaultGasGiant          = new DREAtmosphereComposition();

            float gasGiantRadius = 3000;

            foreach (ConfigNode node in GameDatabase.Instance.GetConfigNodes("DRE_ATM_COMPOSITIONS"))
            {
                foreach (ConfigNode atmNode in node.GetNodes("ATM_COMPOSITION"))
                {
                    DREAtmosphereComposition newComposition = new DREAtmosphereComposition();

                    newComposition.gasSpeciesAndMassFractions = new Dictionary <DREAtmosphericGasSpecies, float>();

                    foreach (ConfigNode gasSpeciesNode in atmNode.GetNodes("GAS_SPECIES"))
                    {
                        DREAtmosphericGasSpecies decompositionSpecies = DREAtmDataOrganizer.idOrganizedListOfGasSpecies[gasSpeciesNode.GetValue("id")];

                        float massFraction = float.Parse(gasSpeciesNode.GetValue("massFraction"));
                        newComposition.gasSpeciesAndMassFractions.Add(decompositionSpecies, massFraction);
                    }

                    newComposition.referenceTemperature = float.Parse(atmNode.GetValue("referenceTemperature"));
                    newComposition.maxSimVelocity       = float.Parse(atmNode.GetValue("maxSimVelocity"));

                    string bodyName = atmNode.GetValue("bodyName");
                    if (!FARFound)
                    {
                        GetFARNode();
                    }

                    for (int idx = 0; idx < FlightGlobals.Bodies.Count; idx++)
                    {
                        CelestialBody body = FlightGlobals.Bodies[idx];
                        if (body.name == bodyName)
                        {
                            bool found = false;
                            if ((object)FARAeroData != null)
                            {
                                foreach (ConfigNode bodyNode in FARAeroData.nodes)
                                {
                                    if (int.Parse(bodyNode.GetValue("index")) == idx)
                                    {
                                        found = true;
                                        float ftmp;
                                        if (bodyNode.HasValue("specHeatRatio"))
                                        {
                                            float.TryParse(bodyNode.GetValue("specHeatRatio"), out ftmp);
                                            newComposition.specHeatRatio = ftmp;
                                        }
                                        if (bodyNode.HasValue("gasMolecularWeight"))
                                        {
                                            float.TryParse(bodyNode.GetValue("gasMolecularWeight"), out ftmp);
                                            newComposition.gasConstant = (float)((double)(DREAtmosphericGasSpecies.UniversalGasConstant) / (double)(ftmp));
                                        }
                                    }
                                }
                            }
                            if (!found)
                            {
                                double weight = 0f;
                                double gamma  = 0;
                                foreach (KeyValuePair <DREAtmosphericGasSpecies, float> kvp in newComposition.gasSpeciesAndMassFractions)
                                {
                                    weight += kvp.Key.GetMolecularMass() * kvp.Value;
                                    double Cp = kvp.Key.CalculateCp(newComposition.referenceTemperature);
                                    gamma += (Cp / (Cp - (double)kvp.Key.GetSpecificGasConstant())) * (double)kvp.Value;
                                }
                                newComposition.gasConstant   = (float)((double)(DREAtmosphericGasSpecies.UniversalGasConstant) / weight);
                                newComposition.specHeatRatio = (float)gamma;
                            }
                            bodyOrganizedListOfAtmospheres.Add(body, newComposition);
                            break;
                        }
                    }

                    if (bodyName == "defaultOxygenatedRocky")
                    {
                        defaultOxygenatedRocky = newComposition;
                    }
                    else if (bodyName == "defaultUnoxygenatedRocky")
                    {
                        defaultUnoxygenatedRocky = newComposition;
                    }
                    else if (bodyName == "defaultGasGiant")
                    {
                        defaultGasGiant = newComposition;
                    }
                }
                gasGiantRadius = float.Parse(node.GetValue("gasGiantRadius"));
            }

            foreach (CelestialBody body in FlightGlobals.Bodies)
            {
                if (!bodyOrganizedListOfAtmospheres.ContainsKey(body))
                {
                    if (body.Radius > gasGiantRadius)
                    {
                        bodyOrganizedListOfAtmospheres.Add(body, defaultGasGiant);
                    }
                    else if (body.atmosphereContainsOxygen)
                    {
                        bodyOrganizedListOfAtmospheres.Add(body, defaultOxygenatedRocky);
                    }
                    else
                    {
                        bodyOrganizedListOfAtmospheres.Add(body, defaultUnoxygenatedRocky);
                    }
                }
            }
        }
Ejemplo n.º 5
0
        public static float GetReferenceTemp(CelestialBody body)
        {
            DREAtmosphereComposition atmosphere = bodyOrganizedListOfAtmospheres[body];

            return(atmosphere.referenceTemperature);
        }
Ejemplo n.º 6
0
        public static void LoadConfigNodes()
        {
            idOrganizedListOfGasSpecies = new Dictionary<string, DREAtmosphericGasSpecies>();
            bodyOrganizedListOfAtmospheres = new Dictionary<CelestialBody, DREAtmosphereComposition>();
            foreach (ConfigNode node in GameDatabase.Instance.GetConfigNodes("DRE_ATM_GAS_SPECIES"))
            {
                foreach (ConfigNode gasSpeciesNode in node.GetNodes("GAS_SPECIES"))
                {
                    string id = gasSpeciesNode.GetValue("id");
                    DREAtmosphericGasSpecies newSpecies = new DREAtmosphericGasSpecies(id);

                    idOrganizedListOfGasSpecies.Add(id, newSpecies);
                }
            }
            foreach (KeyValuePair<string, DREAtmosphericGasSpecies> pair in idOrganizedListOfGasSpecies)
                pair.Value.Initialize();

            DREAtmosphereComposition defaultOxygenatedRocky = new DREAtmosphereComposition(),
                defaultUnoxygenatedRocky = new DREAtmosphereComposition(),
                defaultGasGiant = new DREAtmosphereComposition();

            float gasGiantRadius = 3000;

            foreach (ConfigNode node in GameDatabase.Instance.GetConfigNodes("DRE_ATM_COMPOSITIONS"))
            {
                foreach (ConfigNode atmNode in node.GetNodes("ATM_COMPOSITION"))
                {
                    DREAtmosphereComposition newComposition = new DREAtmosphereComposition();

                    newComposition.gasSpeciesAndMassFractions = new Dictionary<DREAtmosphericGasSpecies, float>();

                    foreach (ConfigNode gasSpeciesNode in atmNode.GetNodes("GAS_SPECIES"))
                    {
                        DREAtmosphericGasSpecies decompositionSpecies = DREAtmDataOrganizer.idOrganizedListOfGasSpecies[gasSpeciesNode.GetValue("id")];

                        float massFraction = float.Parse(gasSpeciesNode.GetValue("massFraction"));
                        newComposition.gasSpeciesAndMassFractions.Add(decompositionSpecies, massFraction);
                    }

                    newComposition.referenceTemperature = float.Parse(atmNode.GetValue("referenceTemperature"));
                    newComposition.maxSimVelocity = float.Parse(atmNode.GetValue("maxSimVelocity"));

                    string bodyName = atmNode.GetValue("bodyName");
                    if (!FARFound)
                        GetFARNode();

                    for(int idx = 0; idx < FlightGlobals.Bodies.Count; idx++)
                    {
                        CelestialBody body = FlightGlobals.Bodies[idx];
                        if(body.name == bodyName)
                        {
                            bool found = false;
                            if ((object)FARAeroData != null)
                            {
                                foreach(ConfigNode bodyNode in FARAeroData.nodes)
                                {
                                    if(int.Parse(bodyNode.GetValue("index")) == idx)
                                    {
                                        found = true;
                                        float ftmp;
                                        if(bodyNode.HasValue("specHeatRatio"))
                                        {
                                            float.TryParse(bodyNode.GetValue("specHeatRatio"), out ftmp);
                                            newComposition.specHeatRatio = ftmp;
                                        }
                                        if (bodyNode.HasValue("gasMolecularWeight"))
                                        {
                                            float.TryParse(bodyNode.GetValue("gasMolecularWeight"), out ftmp);
                                            newComposition.gasConstant = (float)((double)(DREAtmosphericGasSpecies.UniversalGasConstant) / (double)(ftmp));
                                        }
                                    }
                                }
                            }
                            if (!found)
                            {
                                double weight = 0f;
                                double gamma = 0;
                                foreach (KeyValuePair<DREAtmosphericGasSpecies, float> kvp in newComposition.gasSpeciesAndMassFractions)
                                {
                                    weight += kvp.Key.GetMolecularMass() * kvp.Value;
                                    double Cp = kvp.Key.CalculateCp(newComposition.referenceTemperature);
                                    gamma += (Cp / (Cp - (double)kvp.Key.GetSpecificGasConstant())) * (double)kvp.Value;
                                }
                                newComposition.gasConstant = (float)((double)(DREAtmosphericGasSpecies.UniversalGasConstant) / weight);
                                newComposition.specHeatRatio = (float)gamma;

                            }
                            bodyOrganizedListOfAtmospheres.Add(body, newComposition);
                            break;
                        }
                    }

                    if (bodyName == "defaultOxygenatedRocky")
                        defaultOxygenatedRocky = newComposition;
                    else if (bodyName == "defaultUnoxygenatedRocky")
                        defaultUnoxygenatedRocky = newComposition;
                    else if (bodyName == "defaultGasGiant")
                        defaultGasGiant = newComposition;
                }
                gasGiantRadius = float.Parse(node.GetValue("gasGiantRadius"));
            }

            foreach(CelestialBody body in FlightGlobals.Bodies)
            {
                if(!bodyOrganizedListOfAtmospheres.ContainsKey(body))
                {
                    if (body.Radius > gasGiantRadius)
                        bodyOrganizedListOfAtmospheres.Add(body, defaultGasGiant);
                    else if(body.atmosphereContainsOxygen)
                        bodyOrganizedListOfAtmospheres.Add(body, defaultOxygenatedRocky);
                    else
                        bodyOrganizedListOfAtmospheres.Add(body, defaultUnoxygenatedRocky);
                }
            }
        }