public VectorizedSceneUpdateNodesTests() { Width = 20; Height = 20; Length = 1f; Grid = new PackedHexagonalGrid(Width, Height, Padding, Length); NodesX = Grid.VerticesX.ToArray(); NodesY = Grid.VerticesY.ToArray(); var random = new Random(); Func<float> randomFloat = () => (float)random.NextDouble(); VelocitiesX = Enumerable.Range(0, NodesX.Length).Select(_ => randomFloat()).ToArray(); VelocitiesY = Enumerable.Range(0, NodesY.Length).Select(_ => randomFloat()).ToArray(); const float dt = 0.01f; Dt = new Vector<float>(dt); UpdateNodesReferenceImplementation(dt, NodesX, NodesY, VelocitiesX, VelocitiesY); ReferenceNodesX = NodesX.ToArray(); ReferenceNodesY = NodesY.ToArray(); RestoreNodes(); JitMethods(); }
public static void ClassInitialize(TestContext context) { uint discard = 0x00000000; uint preserve = 0xFFFFFFFF; LeftMask = Vector.AsVectorSingle(new Vector<uint>(new[] { discard, preserve, preserve, preserve })); RightMask = Vector.AsVectorSingle(new Vector<uint>(new[] { preserve, preserve, preserve, discard })); var grid = new PackedHexagonalGrid(Width, Height, Padding, Length); NodesX = grid.VerticesX; NodesY = grid.VerticesY; VelocitiesX = NodesX.ToArray(); VelocitiesY = NodesY.ToArray(); Clear(VelocitiesX, VelocitiesY, Width, Height, Padding, Stride); ReferenceVelocitiesX = VelocitiesX.ToArray(); ReferenceVelocitiesY = VelocitiesY.ToArray(); Clear(ReferenceVelocitiesX, ReferenceVelocitiesY, Width, Height, Padding, Stride); CalculateImpulsesReferenceImplementation(NodesX, NodesY, ReferenceVelocitiesX, ReferenceVelocitiesY, Lambda[0], RestLength[0], Width, Height, Padding, Stride); }
public VectorizedScene(int width, int height, float length, float lambda, float threshold, float timeStep, int stepSize) { Action<string, object> throwNotPositive = (s, x) => { throw new ArgumentOutOfRangeException(s, x, "Positive number required"); }; if (width <= 0) throwNotPositive(nameof(width), width); if (height <= 0) throwNotPositive(nameof(height), height); if (length <= 0) throwNotPositive(nameof(length), length); if (timeStep <= 0) throwNotPositive(nameof(timeStep), timeStep); if (width % VectorSize != 0) throw new ArgumentException($"Parameter {nameof(width)} must be a multiple of" + $"{nameof(VectorSize)} = {VectorSize}."); Lambda = lambda; Threshold = threshold; Length = length; TimeStep = timeStep; Time = 0; StepSize = stepSize; Steps = 0; Stopwatch = new Stopwatch(); Width = width; Height = height; int padding = Padding; var grid = new PackedHexagonalGrid(width, height, padding, length); var center = new Vector2(grid.SpatialWidth, grid.SpatialHeight) / 2; var offset = -center; NodesX = grid.VerticesX; NodesY = grid.VerticesY; // Copy the nodes arrays to preserve the guard NaN's contained within. We'll zero the other elements later. VelocitiesX = NodesX.ToArray(); VelocitiesY = NodesY.ToArray(); // Center the grid around (0, 0). int stride = GetStride(width, padding); for (int row = 0; row < height; row++) { for (int col = 0; col < width; col++) { int index = GetIndex(padding, stride, col, row); NodesX[index] += offset.X; NodesY[index] += offset.Y; } } }