protected override async Task <NewtonResult[][]> GenerateNewtonArrayAsync()
        {
            var chunkSize  = Options.PixelSize.Width / _chunks;
            var collection = new List <ChunkOptions>();
            var width      = 0;

            for (var i = 0; i < _chunks; ++i)
            {
                var nextWidth = i == _chunks - 1 ? Options.PixelSize.Width : width + chunkSize;
                collection.Add(new ChunkOptions
                {
                    FractalOptions = Options,
                    MinWidth       = width,
                    MaxWidth       = nextWidth,
                });
                width = nextWidth;
            }

            var tasks     = collection.Select(x => _context.CallActivityAsync <NewtonResult[][]>(nameof(EntryPoint.ExecuteChunk), x));
            var rawResult = await Task.WhenAll(tasks);

            var result = new NewtonResult[Options.PixelSize.Width][];

            foreach (var(item, options) in rawResult.Zip(collection, (x, y) => (x, y)))
            {
                for (var px = options.MinWidth; px < options.MaxWidth; ++px)
                {
                    result[px] = item[px - options.MinWidth];
                }
            }

            return(result);
        }
Esempio n. 2
0
        public static NewtonResult[][] ExecuteChunk([ActivityTrigger] ChunkOptions options, ILogger log)
        {
            var fractalOptions = options.FractalOptions;
            var element        = MathElement.Parse(fractalOptions.Expression, fractalOptions.VariableName);
            var func           = element.ToNewtonFunction(fractalOptions.Multiplicity).ToFunc();

            var result = new NewtonResult[options.MaxWidth - options.MinWidth][];

            for (var px = options.MinWidth; px < options.MaxWidth; ++px)
            {
                var x = fractalOptions.DomainSize.MinX + (fractalOptions.DomainSize.MaxX - fractalOptions.DomainSize.MinX) * px / (fractalOptions.PixelSize.Width - 1);
                result[px - options.MinWidth] = new NewtonResult[fractalOptions.PixelSize.Height];
                for (var py = 0; py < fractalOptions.PixelSize.Height; ++py)
                {
                    var y             = fractalOptions.DomainSize.MaxY - (fractalOptions.DomainSize.MaxY - fractalOptions.DomainSize.MinY) * py / (fractalOptions.PixelSize.Height - 1);
                    var newtonOptions = new NewtonOptions
                    {
                        Precision     = fractalOptions.Precision,
                        StartingPoint = new Complex(x, y),
                        MaxIterations = fractalOptions.MaxIterations,
                    };
                    result[px - options.MinWidth][py] = MathUtils.NewtonMethod(func, newtonOptions);
                }
            }

            return(result);
        }
        private NewtonResult[] NewtonBandInternal(int px)
        {
            var x      = Options.DomainSize.MinX + (Options.DomainSize.MaxX - Options.DomainSize.MinX) * px / (Options.PixelSize.Width - 1);
            var result = new NewtonResult[Options.PixelSize.Height];

            for (var py = 0; py < Options.PixelSize.Height; ++py)
            {
                var y             = Options.DomainSize.MaxY - (Options.DomainSize.MaxY - Options.DomainSize.MinY) * py / (Options.PixelSize.Height - 1);
                var newtonOptions = new NewtonOptions
                {
                    Precision     = Options.Precision,
                    StartingPoint = new Complex(x, y),
                    MaxIterations = Options.MaxIterations,
                };
                result[py] = MathUtils.NewtonMethod(Function, newtonOptions);
            }

            return(result);
        }
        protected virtual Task <NewtonResult[][]> GenerateNewtonArrayAsync()
        {
            var result = new NewtonResult[Options.PixelSize.Width][];

            for (var px = 0; px < Options.PixelSize.Width; ++px)
            {
                var x = Options.DomainSize.MinX + (Options.DomainSize.MaxX - Options.DomainSize.MinX) * px / (Options.PixelSize.Width - 1);
                result[px] = new NewtonResult[Options.PixelSize.Height];
                for (var py = 0; py < Options.PixelSize.Height; ++py)
                {
                    var y             = Options.DomainSize.MaxY - (Options.DomainSize.MaxY - Options.DomainSize.MinY) * py / (Options.PixelSize.Height - 1);
                    var newtonOptions = new NewtonOptions
                    {
                        Precision     = Options.Precision,
                        StartingPoint = new Complex(x, y),
                        MaxIterations = Options.MaxIterations,
                    };
                    result[px][py] = MathUtils.NewtonMethod(Function, newtonOptions);
                }
            }

            return(Task.FromResult(result));
        }