Beispiel #1
0
        public static void CalculateShortwaves(PlanetSimulator pSim, Cell cell, WeatherCell[] wCellColumn)
        {
            for (int AltLayer = wCellColumn.Length - 1; AltLayer >= 0; AltLayer--)
            {
                WeatherCell temp = wCellColumn[AltLayer];
                if (AltLayer == pSim.BufferMap.Count - 1) //Is it top layer?
                {
                    float SunriseFactor = (float)(Mathf.Cos(WeatherFunctions.getLatitude(cell) * Mathf.Deg2Rad) +
                                                  Mathf.Cos(getSunlightAngle(pSim, AltLayer, cell) * Mathf.Deg2Rad)) / 2f;
                    //Debug.Log("Sunrise Factor: " + SunriseFactor); //checks out
                    //Do check to see if top layer is in sunlight
                    if (WeatherFunctions.isSunlight(pSim, AltLayer, cell))
                    {
                        float bodyKSun = pSim.bodyKSun * SunriseFactor;
                        //Debug.Log("bodyKSun: " + bodyKSun);
                        temp.SWReflected   = bodyKSun * temp.Albedo;
                        temp.SWTransmitted = bodyKSun * temp.Transmissivity;
                        //Debug.Log(temp.SWTransmitted); //top layer gives real values
                        temp.SWAbsorbed = bodyKSun *
                                          (1 - temp.Albedo - temp.Transmissivity);
                    }
                    //Else, it's danky dark and this is where the sun don't shine
                    else
                    {
                        temp.SWAbsorbed    = 0;
                        temp.SWReflected   = 0;
                        temp.SWTransmitted = 0;
                    }
                }
                else if (AltLayer == 0) //Is it bottom layer? No transmit
                {
                    temp.SWReflected   = wCellColumn[AltLayer + 1].SWTransmitted * temp.Albedo;
                    temp.SWTransmitted = 0f;
                    temp.SWAbsorbed    = wCellColumn[AltLayer + 1].SWTransmitted *
                                         (1 - temp.Albedo);

                    //Debug.Log(pSim.BufferMap[AltLayer +1][cell].SWTransmitted); //Gives 0
                }
                else //it's middle layers
                {
                    temp.SWReflected   = wCellColumn[AltLayer + 1].SWTransmitted * temp.Albedo;
                    temp.SWTransmitted = wCellColumn[AltLayer + 1].SWTransmitted * temp.Transmissivity;
                    temp.SWAbsorbed    = wCellColumn[AltLayer + 1].SWTransmitted *
                                         (1 - temp.Albedo - temp.Transmissivity);

                    //Debug.Log("Layer: "+ AltLayer + ", " + pSim.BufferMap[pSim.LiveMap.Count-1][cell].SWTransmitted); //gives 0
                }
                wCellColumn[AltLayer] = temp;
            }
        }
Beispiel #2
0
 public static float calculateEmissivity(PlanetSimulator pSim, int AltLayer, Cell cell)
 {
     if (pSim.LiveMap[0][cell].isOcean)
     {
         return(0.96f);
     }
     else if (WeatherFunctions.getLatitude(cell) > 60 || WeatherFunctions.getLatitude(cell) < -60 && pSim.LiveMap[0][cell].isOcean == false)
     {
         return(0.97f);
     }
     else
     {
         return(0.92f);
     }
 }
Beispiel #3
0
        internal static double atmoThermalConductivity = 0.024; //W/m-K



        public static void InitShortwaves(PlanetSimulator pSim, Cell cell)
        {
            //Debug.Log("Init shortwaves");
            for (int index = pSim.LiveMap.Count - 1; index > 0; index--)
            {
                WeatherCell temp = pSim.BufferMap[index][cell];
                if (index == pSim.LiveMap.Count - 1) //Is it top layer?
                {
                    float SunriseFactor = (float)(Mathf.Cos(WeatherFunctions.getLatitude(cell) * Mathf.Deg2Rad) +
                                                  Mathf.Cos(getSunlightAngle(pSim, index, cell) * Mathf.Deg2Rad)) / 2f;
                    //check for sunlight
                    if (WeatherFunctions.isSunlight(pSim, index, cell))
                    {
                        float bodyKSun = pSim.bodyKSun * SunriseFactor;
                        temp.SWReflected   = bodyKSun * temp.Albedo;
                        temp.SWTransmitted = bodyKSun * temp.Transmissivity;
                        temp.SWAbsorbed    = bodyKSun *
                                             (1 - temp.Albedo - temp.Transmissivity);
                    }
                    else
                    {
                        temp.SWAbsorbed    = 0f;
                        temp.SWReflected   = 0f;
                        temp.SWTransmitted = 0f;
                    }
                }
                else if (index == 0) //is it bottom layer? No transmit
                {
                    temp.SWReflected   = pSim.BufferMap[index + 1][cell].SWTransmitted * temp.Albedo;
                    temp.SWTransmitted = 0f;
                    temp.SWAbsorbed    = pSim.BufferMap[index + 1][cell].SWTransmitted *
                                         (1 - temp.Albedo - temp.Transmissivity);
                }
                else
                {
                    temp.SWReflected   = pSim.BufferMap[index + 1][cell].SWTransmitted * temp.Albedo;
                    temp.SWTransmitted = pSim.BufferMap[index + 1][cell].SWTransmitted * temp.Transmissivity;
                    temp.SWAbsorbed    = pSim.BufferMap[index + 1][cell].SWTransmitted *
                                         (1 - temp.Albedo - temp.Transmissivity);
                }
                pSim.BufferMap[index][cell] = temp;
            }
        }
        public static Vector3 CalculateWindVector(PlanetSimulator pSim, int AltLayer, Cell cell)
        {
            //Debug.Log("Calcing wind vector");
            Vector3 resultant = Vector3.zero;

            foreach (Cell neighbour in cell.GetNeighbors(pSim.level))
            {
                float deltaPressure = pSim.LiveMap[AltLayer][cell].Pressure - pSim.LiveMap[AltLayer][neighbour].Pressure;

                Vector3 cellVector = cell.Position - neighbour.Position;

                float neighbourDistance = cellVector.magnitude;
                cellVector.Normalize();
                if (deltaPressure == 0f)
                {
                    continue;
                }

                float acc = (-1 / pSim.LiveMap[AltLayer][cell].Density) * (deltaPressure / neighbourDistance);

                //v = a * sqrt(2d/a)
                float windSpeed = acc * Mathf.Sqrt((2 * neighbourDistance) / Mathf.Abs(acc));

                //divide by 2 because opposite shit. Trust me, it is.
                Vector3 windVector = new Vector3(cellVector.x * windSpeed / 2f, cellVector.y * windSpeed / 2f, cellVector.z * windSpeed / 2f);

                //Apply Coriolis to windVector
                Vector3 corAcc = 2 * Vector3.Cross(windVector, pSim.angularVelocity + new Vector3(0f, Mathf.Cos(WeatherFunctions.getLatitude(cell)), Mathf.Sin(WeatherFunctions.getLatitude(cell))));

                windVector = windVector + corAcc;
                resultant += windVector;
            }
            //Start work on upper cell and lower cell
            if (AltLayer + 1 <= pSim.LiveMap.Count - 1)
            {
                float   deltaPressure1 = pSim.LiveMap[AltLayer][cell].Pressure - pSim.LiveMap[AltLayer + 1][cell].Pressure;
                Vector3 cellVector     = cell.Position - (cell.Position * 1.25f);

                float neighbourDistance = cellVector.magnitude;
                cellVector.Normalize();
                if (deltaPressure1 == 0f)
                {
                }
                else
                {
                    float acc = (-1 / pSim.LiveMap[AltLayer][cell].Density) * (deltaPressure1 / neighbourDistance);

                    //v = a * sqrt(2d/a)
                    float windSpeed = acc * Mathf.Sqrt((2 * neighbourDistance) / Mathf.Abs(acc));

                    //divide by 2 because opposite shit. Trust me, it is.
                    Vector3 windVector = new Vector3(cellVector.x * windSpeed / 2f, cellVector.y * windSpeed / 2f, cellVector.z * windSpeed / 2f);

                    //Apply Coriolis to windVector
                    Vector3 corAcc = 2 * Vector3.Cross(windVector, pSim.angularVelocity + new Vector3(0f, Mathf.Cos(WeatherFunctions.getLatitude(cell)), Mathf.Sin(WeatherFunctions.getLatitude(cell))));

                    windVector = windVector + corAcc;
                    resultant += windVector;
                }
            }
            if (AltLayer - 1 >= 0)
            {
                float   deltaPressure1 = pSim.LiveMap[AltLayer][cell].Pressure - pSim.LiveMap[AltLayer - 1][cell].Pressure;
                Vector3 cellVector     = cell.Position - (cell.Position * -0.75f);

                float neighbourDistance = cellVector.magnitude;
                cellVector.Normalize();
                if (deltaPressure1 == 0f)
                {
                }
                else
                {
                    float acc = (-1 / pSim.LiveMap[AltLayer][cell].Density) * (deltaPressure1 / neighbourDistance);

                    //v = a * sqrt(2d/a)
                    float windSpeed = acc * Mathf.Sqrt((2 * neighbourDistance) / Mathf.Abs(acc));

                    //divide by 2 because opposite shit. Trust me, it is.
                    Vector3 windVector = new Vector3(cellVector.x * windSpeed / 2f, cellVector.y * windSpeed / 2f, cellVector.z * windSpeed / 2f);

                    //Apply Coriolis to windVector
                    Vector3 corAcc = 2 * Vector3.Cross(windVector, pSim.angularVelocity + new Vector3(0f, Mathf.Cos(WeatherFunctions.getLatitude(cell)), Mathf.Sin(WeatherFunctions.getLatitude(cell))));

                    windVector = windVector + corAcc;
                    resultant += windVector;
                }
            }

            return(resultant);
        }