Ejemplo n.º 1
0
        public override bool PerformTimeStep()
        {
            //get inputs
            ScalarSet inStage = (ScalarSet)this.GetValues(_inStageQuantity, _inStageElementSet);

            double[]  stage    = inStage.data;
            ScalarSet inExcess = (ScalarSet)this.GetValues(_inExcessQuantity, _inExcessElementSet);

            double[] excess = inExcess.data;


            //transform stage into flow
            double[] flow = _engine.Stage2Flow(stage, _h, this.GetTimeStep());

            //initialize excess, if no values were found
            if (excess.Length != _h.Length)
            {
                excess = new double[_h.Length];
            }

            //set the source term equal to the flow into/out-of the floodplain
            double[] b = flow;

            //--- Calculate Heads ---

            //set the head equal to the head from the previous timestep
            _discretization.Head = _h;

            //create stiffness and source matrices
            _discretization.CreateStiffness(stage, excess, _discretization.Head, b, 0);

            //perform SOR to get first approximation of head
            h1 = _engine.SuccessiveOverRelaxation(_discretization.A, _discretization.q);

            //if any head values are negative, set them to zero
            for (int i = 0; i <= h1.Length - 1; i++)
            {
                if (h1[i] < 0)
                {
                    h1[i] = 0;
                }
            }

            double[,] AA = _discretization.A;
            double[] qq = _discretization.q;

            //reset A and q to zero
            Array.Clear(_discretization.A, 0, _discretization.A.Length);
            Array.Clear(_discretization.q, 0, _discretization.q.Length);

            //create stiffness and source matrices again using the initial stage and excess, but with the heads calculated in the previous iteration
            _discretization.CreateStiffness(stage, excess, h1, b, 1);

            //perform SOR to get first approximation of head
            h1 = _engine.SuccessiveOverRelaxation(_discretization.A, _discretization.q);

            //if any head values are negative, set them to zero
            for (int i = 0; i <= h1.Length - 1; i++)
            {
                if (h1[i] < 0)
                {
                    h1[i] = 0;
                }
            }

            //save these head values for the next time step
            _h = h1;

            //this.SetValues(_outExcessQuantity, _outExcessElementSet, new ScalarSet(_discretization.q));
            this.SetValues(_outExcessQuantity, _outExcessElementSet, new ScalarSet(_h));

            //reset A and q to zero
            Array.Clear(_discretization.A, 0, _discretization.A.Length);
            Array.Clear(_discretization.q, 0, _discretization.q.Length);

            return(true);
        }