예제 #1
0
    public static Scenario FloodWithCubes(float smoothingLength)
    {
        List <float3> initialPositions = new List <float3>();
        float         step             = smoothingLength;
        int           xSteps           = (int)(2.9f / step);
        int           ySteps           = (int)(2.0f / step);
        int           zSteps           = (int)(0.3f / step);

        for (int z = 0; z < zSteps; ++z)
        {
            for (int y = 0; y < ySteps; ++y)
            {
                for (int x = 0; x < xSteps; ++x)
                {
                    initialPositions.Add((new float3(x, y, z) + new float3(1.5f)) * step);
                }
            }
        }
        int remainingParticles = (32 - (initialPositions.Count % 32)) % 32;

        for (int i = 0; i < remainingParticles; ++i)
        {
            initialPositions.Add(
                rnd.NextFloat3(new float3(smoothingLength * 1.5f), new float3(2.9f, 2.0f, 0.3f) - new float3(smoothingLength * 1.5f))
                );
        }

        List <float3> boundaryPositions = new List <float3>();

        Obstacles.AddCubeToBoundaries(new float3(1.0f, 0.0f, 1.0f), new float3(0.2f, 1.2f, 0.2f), boundaryPositions, smoothingLength);
        Obstacles.AddCubeToBoundaries(new float3(2.0f, 0.0f, 2.0f), new float3(0.3f, 0.7f, 0.4f), boundaryPositions, smoothingLength);
        Obstacles.AddCubeToBoundaries(new float3(2.0f, 0.0f, 0.5f), new float3(0.15f, 0.2f, 0.4f), boundaryPositions, smoothingLength);
        Obstacles.AddCubeToBoundaries(new float3(2.5f, 0.0f, 1.3f), new float3(0.1f, 2.2f, 0.1f), boundaryPositions, smoothingLength);
        Obstacles.AddCubeToBoundaries(new float3(1.2f, 0.0f, 1.4f), new float3(0.15f, 0.4f, 0.1f), boundaryPositions, smoothingLength);
        Obstacles.AddCubeToBoundaries(new float3(0.1f, 0.0f, 2.3f), new float3(1.0f, 0.2f, 0.2f), boundaryPositions, smoothingLength);

        return(new Scenario {
            particlePositions = initialPositions,
            boundaryPositions = boundaryPositions
        });
    }
    void InitializeBoundaries(List <float3> initBoundaryPositions)
    {
        Obstacles.AddCubeToBoundaries(new float3(0.0f, 0.0f, 0.0f), bounds, initBoundaryPositions, smoothingLength);
        ComputeBuffer initialBoundaryParticles = new ComputeBuffer(initBoundaryPositions.Count, sizeof(int) * 2);
        ComputeBuffer initialBoundaryPositions = new ComputeBuffer(initBoundaryPositions.Count, sizeof(float) * 3);

        initialBoundaryPositions.SetData(initBoundaryPositions);
        boundaryParticles = new ComputeBuffer(initBoundaryPositions.Count, sizeof(int) * 2);    boundaryParticles.name = "Boundary Particles";
        boundaryPositions = new ComputeBuffer(initBoundaryPositions.Count, sizeof(float) * 3);  boundaryPositions.name = "Boundary Positions";
        boundaryVolume    = new ComputeBuffer(initBoundaryPositions.Count, sizeof(float));         boundaryVolume.name = "Boundary Volume";
        SortBoundaryParticles(initialBoundaryParticles, initialBoundaryPositions);
        initialBoundaryParticles.Dispose();
        initialBoundaryPositions.Dispose();

        int kernel = simulateParticles.FindKernel("ComputeBoundaryVolume");

        simulateParticles.SetBuffer(kernel, "sorted_boundary_positions", boundaryPositions);
        simulateParticles.SetBuffer(kernel, "boundary_bins", boundaryBins);
        simulateParticles.SetBuffer(kernel, "boundary_prefix_sums", boundaryPrefixSums);
        simulateParticles.SetBuffer(kernel, "boundary_volume", boundaryVolume);
        simulateParticles.Dispatch(kernel, (int)math.ceil(initBoundaryPositions.Count / 32.0f), 1, 1);
    }