/// <summary>
        /// Calculates the cross extinction.
        /// </summary>
        /// <param name="parameters">The parameters.</param>
        /// <returns>The simulation results.</returns>
        public SimulationResultDictionary CalculateCrossExtinction(SimulationParameters parameters)
        {
            var result = new SimulationResultDictionary();

            var partitions = Partitioner.Create(parameters.Spectrum).GetPartitions(Environment.ProcessorCount);

            var concurent = new ConcurrentDictionary <SpectrumUnit, SimulationResult>();

            var tasks = partitions
                        .Select(partition => Task.Run(() =>
            {
                using (partition)
                {
                    var polarization = this.initPolarization(parameters);

                    while (partition.MoveNext())
                    {
                        concurent.TryAdd(partition.Current, this.CalculateSingleDDA(partition.Current, parameters, polarization));
                    }
                }
            }))
                        .ToArray();

            Task.WaitAll(tasks);

            foreach (var keyvalue in concurent.OrderBy(pair => pair.Key))
            {
                result.Add(keyvalue.Key, keyvalue.Value);
            }

            return(result);
        }
Example #2
0
        /// <summary>
        /// Converts IEnumerable to the simulation result dictionary.
        /// </summary>
        /// <param name="spectrum">The spectrum.</param>
        /// <param name="selector">The selector.</param>
        /// <returns>The new instance of SimulationResultDictionary.</returns>
        public static SimulationResultDictionary ToSimulationResult(
            this IEnumerable <SpectrumUnit> spectrum,
            Func <SpectrumUnit, SimulationResult> selector)
        {
            var result = new SimulationResultDictionary();

            foreach (SpectrumUnit freq in spectrum)
            {
                result.Add(freq, selector(freq));
            }
            return(result);
        }