Ejemplo n.º 1
0
        public Mesh(int horizontalPointCount, int verticalPointCount, Rectangle rectangle)
        {
            int n = horizontalPointCount,
                m = verticalPointCount;
            double a = rectangle.Left,
                    b = rectangle.Right,
                    c = rectangle.Bottom,
                    d = rectangle.Top,
                    h = (b - a) / (n + 1),
                    k = (d - c) / (m + 1);

            var nodes = new Node[(n + 2) * (m + 2)];
            var interiorNodes = new Node[n * m];
            var boundaryNodes = new Node[(n + 2) * (m + 2) - n * m];

            int interiorNodesCount = 0,
                boundaryNodesCount = 0;
            for (int j = 0; j < m + 2; j++)
                for (int i = 0; i < n + 2; i++)
                {
                    Node node;
                    Vector2 nodePosition = new Vector2(a + i * h, c + j * k);
                    bool nodeIsInside = j != 0 && j != m + 1 && i != 0 && i != n + 1;
                    if (nodeIsInside)
                    {
                        node = new Node(nodePosition, interiorNodesCount, true);
                        interiorNodes[interiorNodesCount] = node;
                        interiorNodesCount++;
                    }
                    else
                    {
                        node = new Node(nodePosition, boundaryNodesCount, false);
                        boundaryNodes[boundaryNodesCount] = node;
                        boundaryNodesCount++;
                    }
                    int index = j * (n + 2) + i;
                    nodes[index] = node;
                }

            Nodes = new ReadOnlyCollection<Node>(nodes);
            InteriorNodes = new ReadOnlyCollection<Node>(interiorNodes);
            BoundaryNodes = new ReadOnlyCollection<Node>(boundaryNodes);


            var finiteElements = new FiniteElement[(n + 1) * (m + 1) * 2];

            for (int j = 0; j < m + 1; j++)
                for (int i = 0; i < n + 1; i++)
                {
                    int leftLower = j * (n + 2) + i,
                        leftUpper = (j + 1) * (n + 2) + i,
                        rightLower = j * (n + 2) + i + 1,
                        rightUpper = (j + 1) * (n + 2) + i + 1,
                        index = (j * (n + 1) + i) * 2;
                    finiteElements[index] = new FiniteElement(nodes[leftLower], nodes[rightUpper], nodes[leftUpper]);
                    finiteElements[index + 1] = new FiniteElement(nodes[rightLower], nodes[leftLower], nodes[rightUpper]);
                }

            FiniteElements = new ReadOnlyCollection<FiniteElement>(finiteElements);
        }
Ejemplo n.º 2
0
 public FiniteElement(FEM2D.Node node0, FEM2D.Node node1, FEM2D.Node node2)
 {
     var feNode0 = new Node(node0.Position, node1.Position, node2.Position, node0.Index, node0.IsInside);
     var feNode1 = new Node(node1.Position, node2.Position, node0.Position, node1.Index, node1.IsInside);
     var feNode2 = new Node(node2.Position, node0.Position, node1.Position, node2.Index, node2.IsInside);
     Nodes = new ReadOnlyCollection<Node>(new[] { feNode0, feNode1, feNode2 });
 }
Ejemplo n.º 3
0
 public Triangle(Node node1, Node node2, Node node3)
 {
     this.nodes = new Node[] { node1, node2, node3 };
 }