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); } } } }
public void Initialize() { foreach (ConfigNode node in GameDatabase.Instance.GetConfigNodes("DRE_ATM_GAS_SPECIES")) { foreach (ConfigNode gasSpeciesNode in node.GetNodes("GAS_SPECIES")) { if (gasSpeciesNode.GetValue("id") == this.id) { Debug.Log("Loading '" + id + "' data"); ConfigNode thisNode = gasSpeciesNode; degFreedomLowTemp = int.Parse(thisNode.GetValue("degFreedomLowTemp")); degFreedomHighTemp = int.Parse(thisNode.GetValue("degFreedomHighTemp")); tempLowDegFreedom = float.Parse(thisNode.GetValue("tempLowDegFreedom")); tempHighDegFreedom = float.Parse(thisNode.GetValue("tempHighDegFreedom")); tempBeginDecomposition = float.Parse(thisNode.GetValue("tempBeginDecomposition")); tempEndDecomposition = float.Parse(thisNode.GetValue("tempEndDecomposition")); float molecularMass = float.Parse(thisNode.GetValue("molecularMass")); specificGasConstant = UniversalGasConstant / molecularMass; heatOfFormation = float.Parse(thisNode.GetValue("heatOfFormation")) / molecularMass * 1000000; decompositionSpeciesWithFraction = new Dictionary <DREAtmosphericGasSpecies, float>(); foreach (ConfigNode decompositionGasSpeciesNode in thisNode.GetNodes("DECOMPOSITION_SPECIES")) { DREAtmosphericGasSpecies decompositionSpecies = DREAtmDataOrganizer.idOrganizedListOfGasSpecies[decompositionGasSpeciesNode.GetValue("id")]; float massFraction = float.Parse(decompositionGasSpeciesNode.GetValue("massFraction")); decompositionSpeciesWithFraction.Add(decompositionSpecies, massFraction); } break; } } } CpLowTemp = ((float)degFreedomLowTemp * 0.5f + 1f) * specificGasConstant; CpHighTemp = ((float)degFreedomHighTemp * 0.5f + 1f) * specificGasConstant; float tmp = tempLowDegFreedom - tempHighDegFreedom; tmp = tmp * tmp * tmp; tmp = 1 / tmp; tmp *= (CpHighTemp - CpLowTemp); constantsCpCurve[0] = 2f * tmp; constantsCpCurve[1] = -3f * (tempLowDegFreedom + tempHighDegFreedom) * tmp; constantsCpCurve[2] = 6f * tempLowDegFreedom * tempHighDegFreedom * tmp; constantsCpCurve[3] = tempLowDegFreedom * tempLowDegFreedom * (tempLowDegFreedom - 3f * tempHighDegFreedom) * tmp + CpLowTemp; tmp = tempBeginDecomposition - tempEndDecomposition; tmp = tmp * tmp * tmp; tmp = 1 / tmp; constantsDecompositionCurve[0] = -2f * tmp; constantsDecompositionCurve[1] = 3f * (tempBeginDecomposition + tempEndDecomposition) * tmp; constantsDecompositionCurve[2] = -6f * tempBeginDecomposition * tempEndDecomposition * tmp; constantsDecompositionCurve[3] = -tempBeginDecomposition * tempBeginDecomposition * (tempBeginDecomposition - 3f * tempEndDecomposition) * tmp + 1f; //Debug.Log("Initialized Gas Species '" + id + "'\n\r"); }
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); } } }