private void UpdateField() { var dataSource = DataSource; var bounds = dataSource.GetGridBounds(); Viewport2D.SetContentBounds(this, bounds); ViewportPanel.SetViewportBounds(this, bounds); int length = (n + 2) * (n + 2); uOld = new double[length]; vOld = new double[length]; densityOld = new double[length]; for (int i = 0; i < length; i++) { int ix = i % n; int iy = i / n; Vector vector = wrapper.GetVector(ix / (double)n, iy / (double)n); if (vector.X.IsNaN() || vector.Y.IsNaN()) { vector = new Vector(); } vOld[i] = 50000 * vector.X; uOld[i] = 50000 * vector.Y; } }
protected override void GetFluidData(double[,] dens_prev, double[,] u_prev, double[,] v_prev) { if (wrapper == null) { return; } base.GetFluidData(dens_prev, u_prev, v_prev); int nanCount = 0; for (int i = 1; i <= N; i++) { for (int j = 1; j <= N; j++) { var vector = wrapper.GetVector(i / (double)N, j / (double)N); if (!vector.X.IsNaN() && !vector.Y.IsNaN()) { u_prev[i, j] = vector.X * N; v_prev[i, j] = vector.Y * N; } else { nanCount++; } } } Debug.WriteLine("Nan count " + nanCount.ToString()); }
protected void UpdateParticles(int width, int height) { if (fieldWrapper == null) { return; } TimeSpan updateTime = stopwatch.Elapsed; var dt = updateTime.TotalMilliseconds - prevUpdateTime.TotalMilliseconds; prevUpdateTime = updateTime; var particlesArray = particles.ToArray(); foreach (var particle in particlesArray) { Point position = new Point(ViewportPanel.GetX(particle), ViewportPanel.GetY(particle)); position = PointFromViewport(position); var vector = fieldWrapper.GetVector(position.X, position.Y).ChangeLength(1.0 / width, 1.0 / height); var shift = particleVelocity * vector * dt; position += shift; var viewportPosition = PointToViewport(position); if (viewportPosition.X < bounds.XMin || viewportPosition.X > bounds.XMax || viewportPosition.Y < bounds.YMin || viewportPosition.Y > bounds.YMax) { particles.Remove(particle); panel.Children.Remove(particle); continue; } ViewportPanel.SetX(particle, viewportPosition.X); ViewportPanel.SetY(particle, viewportPosition.Y); } }
protected override void RebuildUI() { if (DataSource == null) return; if (Plotter == null) return; if (Palette == null) return; int width = DataSource.Width; int height = DataSource.Height; fieldWrapper = new UniformField2DWrapper(DataSource.Data); var coordinate = SectionCoordinate; var minMaxLength = DataSource.GetMinMaxLength(); PointCollection points = new PointCollection(width + 2); var palette = Palette; int[] pixels = new int[width]; for (int ix = 0; ix < width; ix++) { double x = ix; var value = fieldWrapper.GetVector(x / (double)width, coordinate / (double)width); double length = value.Length; if (length.IsNaN()) length = minMaxLength.Min; double ratio = (length - minMaxLength.Min) / minMaxLength.GetLength(); if (ratio < 0) ratio = 0; if (ratio > 1) ratio = 1; points.Add(new Point(x, 1 - ratio)); var color = palette.GetColor(ratio); pixels[ix] = color.ToArgb(); } points.Add(new Point(width, 1)); points.Add(new Point(0, 1)); polygon.Points = points; var paletteBmp = BitmapFrame.Create(width, 1, 96, 96, PixelFormats.Bgra32, null, pixels, (width * PixelFormats.Bgra32.BitsPerPixel + 7) / 8); var brush = new ImageBrush(paletteBmp); polygon.Fill = brush; }
protected override void RebuildUI() { if (DataSource == null) return; if (Plotter == null) return; if (Palette == null) return; int width = DataSource.Width; int height = DataSource.Height; fieldWrapper = new UniformField2DWrapper(DataSource.Data); var coordinate = SectionCoordinate; var minMaxLength = DataSource.GetMinMaxLength(); PointCollection points = new PointCollection(height + 2); var palette = Palette; int[] pixels = new int[height]; for (int iy = 0; iy < height; iy++) { double y = iy; var value = fieldWrapper.GetVector(coordinate / (double)height, y / (double)height); double length = value.Length; if (length.IsNaN()) length = minMaxLength.Min; double ratio = (length - minMaxLength.Min) / minMaxLength.GetLength(); if (ratio < 0) ratio = 0; if (ratio > 1) ratio = 1; points.Add(new Point(ratio, height - y)); var color = palette.GetColor(ratio); pixels[iy] = color.ToArgb(); } points.Add(new Point(0, 0)); points.Add(new Point(0, height)); polygon.Points = points; var paletteBmp = BitmapFrame.Create(1, height, 96, 96, PixelFormats.Pbgra32, null, pixels, (1 * PixelFormats.Pbgra32.BitsPerPixel + 7) / 8); var brush = new ImageBrush(paletteBmp); polygon.Fill = brush; }
protected override void RebuildUI() { if (DataSource == null) { return; } if (Plotter == null) { return; } if (Palette == null) { return; } int width = DataSource.Width; int height = DataSource.Height; fieldWrapper = new UniformField2DWrapper(DataSource.Data); var coordinate = SectionCoordinate; var minMaxLength = DataSource.GetMinMaxLength(); PointCollection points = new PointCollection(width + 2); var palette = Palette; int[] pixels = new int[width]; for (int ix = 0; ix < width; ix++) { double x = ix; var value = fieldWrapper.GetVector(x / width, coordinate / width); double length = value.Length; if (length.IsNaN()) { length = minMaxLength.Min; } double ratio = (length - minMaxLength.Min) / minMaxLength.GetLength(); if (ratio < 0) { ratio = 0; } if (ratio > 1) { ratio = 1; } points.Add(new Point(x, 1 - ratio)); var color = palette.GetColor(ratio); pixels[ix] = color.ToArgb(); } points.Add(new Point(width, 1)); points.Add(new Point(0, 1)); polygon.Points = points; var paletteBmp = BitmapFrame.Create(width, 1, 96, 96, PixelFormats.Bgra32, null, pixels, (width * PixelFormats.Bgra32.BitsPerPixel + 7) / 8); var brush = new ImageBrush(paletteBmp); polygon.Fill = brush; }
protected override void RebuildUI() { if (DataSource == null) { return; } if (Plotter == null) { return; } if (Palette == null) { return; } int width = DataSource.Width; int height = DataSource.Height; fieldWrapper = new UniformField2DWrapper(DataSource.Data); var coordinate = SectionCoordinate; var minMaxLength = DataSource.GetMinMaxLength(); PointCollection points = new PointCollection(height + 2); var palette = Palette; int[] pixels = new int[height]; for (int iy = 0; iy < height; iy++) { double y = iy; var value = fieldWrapper.GetVector(coordinate / (double)height, y / (double)height); double length = value.Length; if (length.IsNaN()) { length = minMaxLength.Min; } double ratio = (length - minMaxLength.Min) / minMaxLength.GetLength(); if (ratio < 0) { ratio = 0; } if (ratio > 1) { ratio = 1; } points.Add(new Point(ratio, height - y)); var color = palette.GetColor(ratio); pixels[iy] = color.ToArgb(); } points.Add(new Point(0, 0)); points.Add(new Point(0, height)); polygon.Points = points; var paletteBmp = BitmapFrame.Create(1, height, 96, 96, PixelFormats.Pbgra32, null, pixels, (1 * PixelFormats.Pbgra32.BitsPerPixel + 7) / 8); var brush = new ImageBrush(paletteBmp); polygon.Fill = brush; }