Beispiel #1
0
 public Node WithBoundaryCondition(BoundaryCondition bc)
 {
     this.BoundaryCondition = bc;
     return(this);
 }
Beispiel #2
0
        public void ValidateFile()
        {
            this.IsValid = false;
            StreamReader file = new StreamReader(File.OpenRead(this.Path));

            file.ReadLine();
            this.NodesCount = Convert.ToInt32(file.ReadLine());
            if (!(this.NodesCount > 0))
            {
                throw new Exception("Nodes count has to be bigger than 0");
            }

            file.ReadLine();
            this.Nodes = new List <Node>();
            for (var i = 0; i < NodesCount; i++)
            {
                double[] pos = Utils.LineToDoubles(file.ReadLine());
                if (pos.Length != 2)
                {
                    throw new Exception("Wrong number of coordinates");
                }
                this.Nodes.Add(new Node().WithId(i).WithPosX(pos[0]).WithPosY(pos[1]));
            }

            file.ReadLine();
            this.ElementsCount = Convert.ToInt32(file.ReadLine());
            if (!(this.ElementsCount > 0))
            {
                throw new Exception("Elements count has to be bigger than 0");
            }

            file.ReadLine();
            this.Elements = new List <Element>();
            for (var i = 0; i < this.ElementsCount; i++)
            {
                int[] nodesIndexes = Utils.LineToInts(file.ReadLine());
                if (nodesIndexes.Length != 2)
                {
                    throw new Exception("Wrong number of elements connexions");
                }
                this.Elements.Add(new Element()
                                  .WithFirstNode(this.Nodes[nodesIndexes[0] - 1])
                                  .WithSecondNode(this.Nodes[nodesIndexes[1] - 1])
                                  .WithType(Element.ELASTIC_BEAM)
                                  .WithYoungModulus(ElementAttributes.YoungModulus)
                                  .WithSection(ElementAttributes.Section)
                                  );
            }

            file.ReadLine();

            for (var i = 0; i < this.NodesCount; i++)
            {
                double[] forces = Utils.LineToDoubles(file.ReadLine());
                if (forces.Length != 2)
                {
                    throw new Exception("Wrong number of force components");
                }
                this.Nodes[i].WithForce(new Vector().WithPolarValues(forces[0], forces[1]));
            }

            file.ReadLine();

            for (var i = 0; i < this.NodesCount; i++)
            {
                int[] bcs = Utils.LineToInts(file.ReadLine());
                if (bcs.Length != 4)
                {
                    throw new Exception("Wrong number of BC components");
                }
                BoundaryCondition boundaryCondition = new BoundaryCondition();
                if (bcs[0] == 1)
                {
                    boundaryCondition.WithX(bcs[1]);
                }

                if (bcs[2] == 1)
                {
                    boundaryCondition.WithY(bcs[3]);
                }
                this.Nodes[i].WithBoundaryCondition(boundaryCondition);
            }

            this.IsValid = true;
        }
Beispiel #3
0
 public Node()
 {
     this.BoundaryCondition = new BoundaryCondition();
     this.Force             = new Vector().WithZeroes(2);
 }