Ejemplo n.º 1
0
        private void DrawNeutronMeanFreePathAndMeanPath(List <Neutron> neutrons)
        {
            SimulateBatchMeanFreePathPlotModel.Series.Clear();
            SimulateBatchMeanPathPlotModel.Series.Clear();
            SimulateBatchDistributionPlotModel.Series.Clear();

            var meanFreePathSeries = new LineSeries
            {
                StrokeThickness             = 2,
                MarkerSize                  = 0,
                MarkerStroke                = OxyColors.Black,
                MarkerType                  = MarkerType.Circle,
                CanTrackerInterpolatePoints = false,
                //Title = @"Practical mean free path",
                Smooth = false,
            };
            var freePathSeries = new LineSeries
            {
                StrokeThickness             = 2,
                MarkerSize                  = 0,
                MarkerStroke                = OxyColors.Black,
                MarkerType                  = MarkerType.Circle,
                CanTrackerInterpolatePoints = false,
                //Title = @"Theoretical mean free path",
                Smooth = false,
            };
            var meanPathSeries = new LineSeries
            {
                StrokeThickness             = 2,
                MarkerSize                  = 0,
                MarkerStroke                = OxyColors.Black,
                MarkerType                  = MarkerType.Circle,
                CanTrackerInterpolatePoints = false,
                //Title = @"Practical mean path",
                Smooth = false,
            };
            var pathSeries = new LineSeries
            {
                StrokeThickness             = 2,
                MarkerSize                  = 0,
                MarkerStroke                = OxyColors.Black,
                MarkerType                  = MarkerType.Circle,
                CanTrackerInterpolatePoints = false,
                //Title = @"Theoretical free path",
                Smooth = false,
            };
            var neutronsDistributionSeries            = new BarSeries();
            var neutronsDistributionSeriesTheoretical = new LineSeries
            {
                StrokeThickness             = 2,
                MarkerSize                  = 0,
                CanTrackerInterpolatePoints = false,
                Smooth = true,
            };

            var i = 0;
            var maxMeanFreePath     = 0d;
            var minMeanFreePath     = 0d;
            var maxMeanPath         = 0d;
            var minMeanPath         = 0d;
            var totalSteps          = 0L;
            var totalPath           = 0d;
            var theoreticalFreePath = 1 / Enviroment.SigmaS;
            var theoreticalPath     = 1 / Enviroment.SigmaA;
            var r = 0d;
            var neutronDistanceList = new List <double>(neutrons.Count);

            freePathSeries.Points.Add(new DataPoint(i, theoreticalFreePath));
            pathSeries.Points.Add(new DataPoint(i, theoreticalPath));
            neutrons.ForEach(neutron =>
            {
                ++i;
                totalSteps  += neutron.FreePathLength.Count - 1;
                totalPath   += neutron.PathLength;
                var distance = neutron.CollisionPoint[neutron.CollisionPoint.Count - 1].DistanceTo(neutron.CollisionPoint[0]);
                neutronDistanceList.Add(distance);
                if (distance > r)
                {
                    r = distance;
                }
                var meanFreePath = totalPath / totalSteps;
                if (meanFreePath > maxMeanFreePath)
                {
                    maxMeanFreePath = meanFreePath;
                }
                else if (meanFreePath < minMeanFreePath)
                {
                    minMeanFreePath = meanFreePath;
                }
                var meanPath = totalPath / i;
                if (meanPath > maxMeanPath)
                {
                    maxMeanPath = meanFreePath;
                }
                else if (meanPath < minMeanPath)
                {
                    minMeanPath = meanPath;
                }
                meanFreePathSeries.Points.Add(new DataPoint(i, meanFreePath));
                meanPathSeries.Points.Add(new DataPoint(i, meanPath));
            });
            freePathSeries.Points.Add(new DataPoint(i, theoreticalFreePath));
            pathSeries.Points.Add(new DataPoint(i, theoreticalPath));
            var sectorWidth = r / NumberOfSectors;

            if (sectorWidth < double.Epsilon)
            {
                sectorWidth = 0.001;
            }
            var getSectorNumber = new Func <double, double, int>(delegate(double distance, double widthOfSecor)
            {
                var sectorNumber = 0;
                var sectorRadius = widthOfSecor;
                while (distance + double.Epsilon > sectorRadius)
                {
                    sectorRadius += widthOfSecor;
                    ++sectorNumber;
                }
                return(sectorNumber);
            });

            for (var sectorNumber = 0; sectorNumber < NumberOfSectors; ++sectorNumber)
            {
                neutronsDistributionSeries.Items.Add(new BarItem(0, sectorNumber));
            }
            neutronDistanceList.ForEach(distance =>
            {
                var neutronSectorNumber = getSectorNumber(distance, sectorWidth);
                if (neutronSectorNumber < NumberOfSectors)
                {
                    neutronsDistributionSeries.Items[neutronSectorNumber].Value += 1;
                }
            });
            for (var k = 0; k < neutronsDistributionSeries.Items.Count; ++k)
            {
                neutronsDistributionSeries.Items[k].Value /= Math.PI * (Math.Pow(sectorWidth * (k + 1), 2) - Math.Pow((sectorWidth * k), 2));
                double y = sectorWidth * (k + 1);
                double x = Enviroment.NeutronsDistribution(y);
                neutronsDistributionSeriesTheoretical.Points.Add(new DataPoint(x, k));
            }

            SimulateBatchMeanFreePathTextBlock.Text = meanFreePathSeries.Points[i - 1].Y.ToString("E2");
            SimulateBatchMeanPathTextBlock.Text     = meanPathSeries.Points[i - 1].Y.ToString("E2");

            SimulateBatchMeanFreePathPlotModel.Series.Add(meanFreePathSeries);
            SimulateBatchMeanFreePathPlotModel.Series.Add(freePathSeries);

            SimulateBatchMeanPathPlotModel.Series.Add(meanPathSeries);
            SimulateBatchMeanPathPlotModel.Series.Add(pathSeries);

            SimulateBatchDistributionPlotModel.Series.Add(neutronsDistributionSeries);
            SimulateBatchDistributionPlotModel.Series.Add(neutronsDistributionSeriesTheoretical);

            SimulateBatchDistributionPlotModel.Axes[1] =
                new CategoryAxis
            {
                Position       = AxisPosition.Left,
                Title          = "Растояние от точечного источника",
                LabelFormatter = value => ((value + 1) * sectorWidth).ToString("E2")
            };

            SimulateBatchResetScales();
        }