private void RecordAverageLateralFlowValuesNormalMethod(int timestep)
        {
            Debug.Assert(this.STSimTransformer.IsSpatial);
            Debug.Assert(this.m_CreateAvgSpatialLateralFlowOutput);
            Debug.Assert(!this.m_AvgSpatialLateralFlowOutputAcrossTimesteps);

            foreach (FlowGroup g in this.m_FlowGroups)
            {
                if (!g.OutputFilter.HasFlag(Constants.OutputFilter.AvgSpatial))
                {
                    continue;
                }

                Dictionary <int, double[]> dict = this.m_AvgLateralFlowMap[g.Id];
                double[] Values = dict[timestep];

                foreach (Cell c in this.m_STSimTransformer.Cells)
                {
                    double Amount = 0;
                    int    i      = c.CollectionIndex;

                    foreach (FlowTypeLinkage l in g.FlowTypeLinkages)
                    {
                        SpatialOutputFlowRecord rec = GetLateralOutputFlowDictionary()[l.FlowType.Id];

                        if (rec.HasOutputData)
                        {
                            Amount += rec.Data[i];
                        }
                    }

                    Values[i] += Amount / this.m_TotalIterations;
                }
            }
        }
        private void RecordSpatialLateralFlowOutputData(int timestep, Cell cell, int flowTypeId, double flowAmount)
        {
            bool IsLFOutputTimestep = this.m_STSimTransformer.IsOutputTimestep(
                timestep,
                this.m_LateralFlowOutputTimesteps,
                this.m_CreateLateralFlowOutput);

            bool IsLFAverageOutputTimestep = this.m_STSimTransformer.IsOutputTimestep(
                timestep,
                this.m_AvgSpatialLateralFlowOutputTimesteps,
                this.m_CreateAvgSpatialLateralFlowOutput);

            if (!IsLFOutputTimestep && !IsLFAverageOutputTimestep)
            {
                return;
            }

            if (GetLateralOutputFlowDictionary().ContainsKey(flowTypeId))
            {
                SpatialOutputFlowRecord rec = GetLateralOutputFlowDictionary()[flowTypeId];
                double amt = rec.Data[cell.CollectionIndex];

                if (amt.Equals(Spatial.DefaultNoDataValue))
                {
                    amt = 0;
                }

                amt += (flowAmount / this.m_STSimTransformer.AmountPerCell);

                rec.Data[cell.CollectionIndex] = amt;
                rec.HasOutputData = true;
            }
        }
        private void WriteLateralFlowRasters(int iteration, int timestep)
        {
            Debug.Assert(this.m_IsSpatial);

            foreach (FlowGroup g in this.m_FlowGroups)
            {
                if (!g.OutputFilter.HasFlag(Constants.OutputFilter.Spatial))
                {
                    continue;
                }

                bool AtLeastOne = false;
                StochasticTimeRaster rastOutput = this.STSimTransformer.InputRasters.CreateOutputRaster(RasterDataType.DTDouble);

                foreach (FlowTypeLinkage l in g.FlowTypeLinkages)
                {
                    if (GetLateralOutputFlowDictionary().ContainsKey(l.FlowType.Id))
                    {
                        SpatialOutputFlowRecord rec = GetLateralOutputFlowDictionary()[l.FlowType.Id];

                        if (rec.HasOutputData)
                        {
                            StochasticTimeRaster rastFlowType =
                                this.STSimTransformer.InputRasters.CreateOutputRaster(RasterDataType.DTDouble);

                            double[] arr = rastFlowType.DblCells;

                            foreach (Cell c in this.m_STSimTransformer.Cells)
                            {
                                arr[c.CellId] = rec.Data[c.CollectionIndex];
                            }

                            rastFlowType.ScaleDblCells(l.Value);
                            rastOutput.AddDblCells(rastFlowType);

                            AtLeastOne = true;
                        }
                    }
                }

                if (AtLeastOne)
                {
                    Spatial.WriteRasterData(
                        rastOutput,
                        this.ResultScenario.GetDataSheet(Constants.DATASHEET_OUTPUT_LATERAL_FLOW_GROUP),
                        iteration,
                        timestep,
                        g.Id,
                        Constants.SPATIAL_MAP_LATERAL_FLOW_GROUP_VARIABLE_PREFIX,
                        Constants.DATASHEET_OUTPUT_SPATIAL_FILENAME_COLUMN);
                }
            }
        }
        private void RecordAverageLateralFlowValuesAcrossTimesteps(int timestep)
        {
            Debug.Assert(this.STSimTransformer.IsSpatial);
            Debug.Assert(this.m_CreateAvgSpatialLateralFlowOutput);
            Debug.Assert(this.m_AvgSpatialLateralFlowOutputAcrossTimesteps);

            int timestepKey = this.GetTimestepKeyForCumulativeAverage(timestep, this.m_AvgSpatialLateralFlowOutputTimesteps);

            foreach (FlowGroup g in this.m_FlowGroups)
            {
                if (!g.OutputFilter.HasFlag(Constants.OutputFilter.AvgSpatial))
                {
                    continue;
                }

                Dictionary <int, double[]> dict = this.m_AvgLateralFlowMap[g.Id];
                double[] Values = dict[timestepKey];

                foreach (Cell c in this.m_STSimTransformer.Cells)
                {
                    double Amount = 0;
                    int    i      = c.CollectionIndex;

                    foreach (FlowTypeLinkage l in g.FlowTypeLinkages)
                    {
                        SpatialOutputFlowRecord rec = GetLateralOutputFlowDictionary()[l.FlowType.Id];

                        if (rec.HasOutputData)
                        {
                            Amount += rec.Data[i];
                        }
                    }

                    if ((timestepKey == this.STSimTransformer.MaximumTimestep) && (((timestepKey - this.STSimTransformer.TimestepZero) % this.m_AvgSpatialLateralFlowOutputTimesteps) != 0))
                    {
                        Values[i] += Amount / (double)((timestepKey - this.STSimTransformer.TimestepZero) % this.m_AvgSpatialLateralFlowOutputTimesteps * this.m_TotalIterations);
                    }
                    else
                    {
                        Values[i] += Amount / (double)(this.m_AvgSpatialLateralFlowOutputTimesteps * this.m_TotalIterations);
                    }
                }
            }
        }
Exemple #5
0
        /// <summary>
        /// Gets the lateral output flow dictionary
        /// </summary>
        /// <returns></returns>
        /// <remarks>
        /// We must lazy-load this dictionary because this transformer runs before ST-Sim's
        /// and so the cell data is not there yet.
        /// </remarks>
        private Dictionary <int, SpatialOutputFlowRecord> GetLateralOutputFlowDictionary()
        {
            if (this.m_LateralOutputFlowDict == null)
            {
                this.m_LateralOutputFlowDict = new Dictionary <int, SpatialOutputFlowRecord>();

                foreach (FlowType ft in this.m_FlowTypes)
                {
                    if (ft.OutputFilter.HasFlag(Constants.OutputFilter.Spatial) ||
                        ft.OutputFilter.HasFlag(Constants.OutputFilter.AvgSpatial))
                    {
                        SpatialOutputFlowRecord rec = new SpatialOutputFlowRecord();

                        rec.FlowTypeId    = ft.Id;
                        rec.Data          = new double[this.STSimTransformer.Cells.Count];
                        rec.HasOutputData = false;

                        this.m_LateralOutputFlowDict.Add(ft.Id, rec);
                    }
                }
            }

            return(this.m_LateralOutputFlowDict);
        }