Example #1
0
        /// <summary>
        /// Initializes all simulations cells in Non-Raster mode
        /// </summary>
        /// <param name="iteration">The current iteration</param>
        /// <remarks></remarks>
        private void InitializeCellsNonRasterNoCalcFromDist(int iteration)
        {
            Debug.Assert(!this.IsSpatial);
            Debug.Assert(this.m_Cells.Count > 0);

#if DEBUG
            Dictionary <int, Cell> dict = new Dictionary <int, Cell>();
#endif

            InitialConditionsDistributionCollection icds = this.m_InitialConditionsDistributionMap.GetICDs(iteration);
            double sumOfRelativeAmountForIteration       = CalcSumOfRelativeAmount(iteration);

            foreach (Cell c in this.m_Cells)
            {
                double Rand = this.m_RandomGenerator.GetNextDouble();
                double CumulativeProportion = 0.0;

                foreach (InitialConditionsDistribution icd in icds)
                {
                    CumulativeProportion += (icd.RelativeAmount / sumOfRelativeAmountForIteration);

                    if (Rand < CumulativeProportion)
                    {
#if DEBUG
                        dict.Add(c.CellId, c);
#endif

                        Cell tempVar = c;
                        this.InitializeCellNonRaster(ref tempVar, icd, iteration);
                        this.PostInitializeCellNonRaster(c, iteration);

                        break;
                    }
                }
            }

#if DEBUG
            Debug.Assert(dict.Count == this.m_Cells.Count);
#endif

            CellsInitialized?.Invoke(this, new CellEventArgs(null, iteration, this.m_TimestepZero));
        }
Example #2
0
        /// <summary>
        /// Initializes all simulations cells in Non-Raster mode
        /// </summary>
        /// <param name="iteration">The current iteration</param>
        /// <remarks></remarks>
        private void InitializeCellsNonRasterCalcFromDist(int iteration)
        {
            // Fetch the number of cells from the NS IC setting
            DataRow drrc     = this.ResultScenario.GetDataSheet(Strings.DATASHEET_NSIC_NAME).GetDataRow();
            int     numCells = Convert.ToInt32(drrc[Strings.DATASHEET_NSIC_NUM_CELLS_COLUMN_NAME], CultureInfo.InvariantCulture);

            Debug.Assert(!this.IsSpatial);
            Debug.Assert(this.m_Cells.Count > 0);

            InitialConditionsDistributionCollection icds = this.m_InitialConditionsDistributionMap.GetICDs(iteration);
            double sumOfRelativeAmountForIteration       = CalcSumOfRelativeAmount(iteration);

            int CellIndex = 0;

#if DEBUG
            Dictionary <int, Cell> dict = new Dictionary <int, Cell>();
#endif
            bool ExceededNumCells = false;

            foreach (InitialConditionsDistribution icd in icds)
            {
                if (ExceededNumCells)
                {
                    break;
                }

                // DEVNOTE:To support multiple iterations, use relativeAmount / sum For Iteration as scale of total number of cells.
                // Number of cells determined by 1st iteration specified. Otherwise, there's too much likelyhood that Number of cells
                //will vary per iteration, which we can't/won't support.

                double Rounded        = Math.Round(icd.RelativeAmount / sumOfRelativeAmountForIteration * numCells);
                int    numCellsForICD = Convert.ToInt32(Rounded);

                for (int i = 0; i < numCellsForICD; i++)
                {
                    Cell c = this.Cells[CellIndex];

#if DEBUG
                    dict.Add(c.CellId, c);
#endif

                    this.InitializeCellNonRaster(ref c, icd, iteration);
                    this.PostInitializeCellNonRaster(c, iteration);

                    CellIndex += 1;

                    if (CellIndex >= this.Cells.Count)
                    {
                        ExceededNumCells = true;
                        break;
                    }
                }
            }

#if DEBUG
            Debug.Assert(dict.Count == this.m_Cells.Count);
            Debug.Assert(CellIndex == this.Cells.Count);
#endif

            CellsInitialized?.Invoke(this, new CellEventArgs(null, iteration, this.m_TimestepZero));
        }