예제 #1
0
    public void Analysis()
    {
        // analysis model
        var model = new Model();

        var corners = _grid.GetCorners()
                      .Where(c => c.GetConnectedVoxels().Any(v => v.Type == VoxelType.Block))
                      .Select(c => new FeaCorner(c))
                      .ToList();

        var nodes = corners.Select(c => c.Node).ToArray();

        var elements = _grid.GetVoxels()
                       .Where(v => v.Type == VoxelType.Block)
                       .SelectMany(v => MakeTetrahedra(v))
                       .ToArray();

        model.Nodes.Add(nodes);
        model.Elements.Add(elements);

        model.Solve();

        // analysis results
        foreach (var corner in corners)
        {
            var d = corner.Node
                    .GetNodalDisplacement(LoadCase.DefaultLoadCase)
                    .Displacements;

            corner.Displacement = new Vector3((float)d.X, (float)d.Z, (float)d.Y);
            var length = corner.Displacement.magnitude;

            foreach (var voxel in corner.GetConnectedVoxels())
            {
                voxel.Value += length;
            }
        }

        var activeVoxels = _grid.GetVoxels().Where(v => v.Type == VoxelType.Block);

        foreach (var voxel in activeVoxels)
        {
            voxel.Value /= voxel.GetCorners().Count();
        }

        var min = activeVoxels.Min(v => v.Value);
        var max = activeVoxels.Max(v => v.Value);

        foreach (var voxel in activeVoxels)
        {
            voxel.Value = Mathf.InverseLerp(min, max, voxel.Value);
        }
    }