public static double SH(int database, float altitude, float temperature) //Mean mass of molecule Mm = M * Na (Molar mass * Avogadro constant) = M * UGC/kb (Molar mass * UniversalGasConstant / Boltzmann constant) //ScaleHeight SH = R*T/g = Kb*T/(Mm*g) (https://en.wikipedia.org/wiki/Scale_height) = UGC * T / (M * g) //ScaleHeight = UniversalGasConstant * Temperature / (AtmosphereMolarMass * gravity(altitude)) //NOTE: PD.SH_correction is applied to have the resulting pressure curve match on average with the pressure curve in KSP { PlanetData PD = WeatherDatabase.PlanetaryData[database]; return(CellUpdater.UGC * PD.SH_correction / PD.atmoData.M / (float)CellUpdater.G(PD.index, altitude) * temperature); }
private static List <KWSCellMap <WeatherCell> > InitCalcs(PlanetData PD) { List <KWSCellMap <WeatherCell> > tempMap = new List <KWSCellMap <WeatherCell> >(); for (int i = 0; i < PD.layers; i++) { tempMap.Add(new KWSCellMap <WeatherCell>(PD.gridLevel)); } float basePressure = (float)FlightGlobals.getStaticPressure(0, PD.body) * 1000; for (int AltLayer = 0; AltLayer < PD.layers; AltLayer++) { foreach (Cell cell in Cell.AtLevel(PD.gridLevel)) { WeatherCell wCell = new WeatherCell(); wCell.temperature = GetInitTemperature(PD, AltLayer, cell); wCell.TempChange = 0; if (AltLayer == 0) { wCell.CCN = 1; wCell.pressure = basePressure; wCell.relativeHumidity = PD.biomeDatas[WeatherFunctions.GetBiome(PD.index, cell)].FLC * 0.85f; //* wCell.temperature / 288.15f } else { wCell.CCN = 0; wCell.pressure = (float)(tempMap[AltLayer - 1][cell].pressure * Math.Exp(-WeatherFunctions.GetDeltaLayerAltitude(PD.index, cell) / (CellUpdater.UGC * PD.SH_correction / PD.atmoData.M / CellUpdater.G(PD.index, AltLayer * WeatherFunctions.GetDeltaLayerAltitude(PD.index, cell)) * tempMap[AltLayer - 1][cell].temperature))); wCell.relativeHumidity = (PD.biomeDatas[WeatherFunctions.GetBiome(PD.index, cell)].FLC * wCell.temperature / 288.15f) * 0.4f; } wCell.windVector = new Vector3(0f, 0f, 0f); wCell.flowPChange = 0; tempMap[AltLayer][cell] = wCell; } } return(tempMap); }
private static List <KWSCellMap <WeatherCell> > InitStratoCalcs(PlanetData PD) { List <KWSCellMap <WeatherCell> > tempMap = new List <KWSCellMap <WeatherCell> >(); for (int i = 0; i < PD.stratoLayers; i++) { tempMap.Add(new KWSCellMap <WeatherCell>(PD.gridLevel)); } for (int layer = 0; layer < PD.stratoLayers; layer++) { foreach (Cell cell in Cell.AtLevel(PD.gridLevel)) { WeatherCell wCell = new WeatherCell(); wCell.CCN = 0; wCell.temperature = GetInitTemperature(PD, layer + layers, cell); wCell.TempChange = 0; if (layer == 0) { wCell.pressure = (float)(PD.LiveMap[layers - 1][cell].pressure * Math.Exp(-WeatherFunctions.GetDeltaLayerAltitude(PD.index, cell) / (CellUpdater.UGC * PD.SH_correction / PD.atmoData.M / CellUpdater.G(PD.index, (layers + layer) * WeatherFunctions.GetDeltaLayerAltitude(PD.index, cell)) * PD.LiveMap[layers - 1][cell].temperature))); } else { wCell.pressure = (float)(tempMap[layer - 1][cell].pressure * Math.Exp(-WeatherFunctions.GetDeltaLayerAltitude(PD.index, cell) / (CellUpdater.UGC * PD.SH_correction / PD.atmoData.M / CellUpdater.G(PD.index, (layers + layer) * WeatherFunctions.GetDeltaLayerAltitude(PD.index, cell)) * tempMap[layer - 1][cell].temperature))); } wCell.relativeHumidity = 0; wCell.windVector = new Vector3(0f, 0f, 0f); tempMap[layer][cell] = wCell; } } return(tempMap); }