Exemple #1
0
    void updateColumnData()
    {
        float fluxLeft;
        float fluxRight;
        float fluxTop;
        float fluxBottom;
        float K;
        float volumeChange;

        Flux[,] tempFlux        = new Flux[numberVertices, numberVertices];
        float[,] oldWaterHeight = new float[numberVertices, numberVertices];

        // Calculate and store new flux values for each vertex in a temporary array
        for (int x = 0; x < numberVertices; x++)
        {
            for (int y = 0; y < numberVertices; y++)
            {
                Flux outFlux = calculateOutflowFlux(x, y);

                if (outFlux.getLeft() != 0 || outFlux.getRight() != 0 || outFlux.getTop() != 0 || outFlux.getBottom() != 0)
                {
                    K = Mathf.Min(1, waterHeight[x, y] * gridLength * gridWidth / ((outFlux.getLeft() + outFlux.getRight() + outFlux.getTop() + outFlux.getBottom()) * time));
                }
                else
                {
                    K = 0;
                }

                fluxLeft   = K * outFlux.getLeft();
                fluxRight  = K * outFlux.getRight();
                fluxTop    = K * outFlux.getTop();
                fluxBottom = K * outFlux.getBottom();

                tempFlux[x, y] = new Flux(fluxLeft, fluxRight, fluxTop, fluxBottom);
            }
        }

        // Replace old flux values with new ones from temporary array
        for (int x = 0; x < numberVertices; x++)
        {
            for (int y = 0; y < numberVertices; y++)
            {
                outflowFlux[x, y] = tempFlux[x, y];
            }
        }

        // Use fluxes to change height of each vertex
        for (int x = 0; x < numberVertices; x++)
        {
            for (int y = 0; y < numberVertices; y++)
            {
                Flux inflowFlux = calculateInflowFlux(x, y);

                volumeChange         = time * ((inflowFlux.getLeft() + inflowFlux.getRight() + inflowFlux.getTop() + inflowFlux.getBottom()) - (outflowFlux[x, y].getLeft() + outflowFlux[x, y].getRight() + outflowFlux[x, y].getTop() + outflowFlux[x, y].getBottom()));
                oldWaterHeight[x, y] = waterHeight[x, y];
                waterHeight[x, y]    = waterHeight[x, y] + (volumeChange / (gridLength * gridWidth));
            }
        }

        // Calculate velocity vector for each vertex
        for (int x = 0; x < numberVertices; x++)
        {
            for (int y = 0; y < numberVertices; y++)
            {
                float avgWaterAmountX;
                float avgWaterAmountY;
                float u;
                float v;
                float avgWaterHeight = (oldWaterHeight[x, y] + waterHeight[x, y]) / 2;
                Flux  inflowFlux     = calculateInflowFlux(x, y);

                avgWaterAmountX = (inflowFlux.getTop() - outflowFlux[x, y].getTop() + outflowFlux[x, y].getBottom() - inflowFlux.getBottom()) / 2;
                avgWaterAmountY = (inflowFlux.getLeft() - outflowFlux[x, y].getLeft() + outflowFlux[x, y].getRight() - inflowFlux.getRight()) / 2;

                u = avgWaterAmountX / (avgWaterHeight * gridWidth);
                v = avgWaterAmountY / (avgWaterHeight * gridLength);
                velocity[x, y] = new Vector2(u, v);
            }
        }

        // Calculate Erosion/Deposition

        // Calculate Sediment Transport

        // Calculate Evaporation
        for (int x = 0; x < numberVertices; x++)
        {
            for (int y = 0; y < numberVertices; y++)
            {
                waterHeight[x, y] = waterHeight[x, y] * (1 - Ke * time);
                scaleWater(x, y);
            }
        }
    }