static void TestTet()
        {
            //new Validation.Case_03.Validator().Validate();

            var tet =
                new TetrahedronElement();

            //new Tetrahedral();

            tet.Nodes[0] = new Node(-1, -1, 0);
            tet.Nodes[1] = new Node(1, -1, 0);
            tet.Nodes[2] = new Node(1, 1, 0);
            tet.Nodes[3] = new Node(0, 0, 5);

            tet.Material = UniformIsotropicMaterial.CreateFromYoungPoisson(210e9, 0.3);
            //tet.E = 1000;tet.Nu = 0.3;

            var stf = tet.GetGlobalStifnessMatrix();

            var ctrl = new MatrixVisualizerControl();

            ctrl.VisualizeMatrix(stf);

            new Window()
            {
                Content = ctrl, Title = "epsi1on Matrix Visualizer!", Width = 24 * 50, Height = 24 * 50
            }
            .ShowDialog();
        }
Exemple #2
0
        public static void ValidateSingleInclinedFrame()
        {
            var model = new Model();
            var ndes  = new Node[] { new Node(0, 0, 0), new Node(2, 3, 5) };

            var h = 0.1;
            var w = 0.05;

            var a  = h * w;
            var iy = h * h * h * w / 12;
            var iz = w * w * w * h / 12;
            var j  = iy + iz;

            var sec = new Sections.UniformParametric1DSection(a, iy, iz, j);
            var mat = UniformIsotropicMaterial.CreateFromYoungPoisson(1, 0.25);

            var elm = new BarElement(ndes[0], ndes[1])
            {
                Material = mat, Section = sec, Behavior = BarElementBehaviours.FullFrame
            };

            //var elm2 = new BarElement(ndes[1], ndes[2]) { Material = mat, Section = sec, Behavior = BarElementBehaviours.FullFrame };

            model.Elements.Add(elm);
            model.Nodes.Add(ndes);

            ndes[0].Constraints = Constraints.Fixed;

            ndes[1].Loads.Add(new NodalLoad(new Force(0, 1, 0, 0, 0, 0)));

            model.Solve_MPC();

            var res = OpenseesValidator.OpenseesValidate(model, LoadCase.DefaultLoadCase, false);
        }
        public static void Run()
        {
            var model = new Model();
            var n1    = new Node(0, 0, 0)
            {
                Label = "n1", Constraints = Constraints.Fixed
            };
            var n2 = new Node(10, 0, 0)
            {
                Label = "n2", Constraints = Constraints.RotationFixed & Constraints.FixedDX & Constraints.FixedDY
            };

            var beam = new BarElement(n1, n2)
            {
                Label = "Beam", Behavior = BarElementBehaviour.BeamYEulerBernoulli
            };

            //beam.Section = new UniformGeometric1DSection(SectionGenerator.GetISetion(0.24, 0.67, 0.01, 0.006));
            beam.Section = new UniformParametric1DSection()
            {
                A = 1e-4, Iy = 1e-6, Iz = 1e-6, J = 1e-6
            };
            beam.Material = UniformIsotropicMaterial.CreateFromYoungPoisson(1e10, 0.2);

            model.Nodes.Add(n1, n2);
            model.Elements.Add(beam);

            var force = new Force(0, 0, -1000, 0, 0, 0);

            n2.Loads.Add(new NodalLoad(force));

            model.Solve_MPC();
        }
Exemple #4
0
        public static void ValidateOneSpanUniformLoad()
        {
            var model = new Model();

            var ndes = new Node[] {
                new Node(0, 0, 0),
                new Node(1, 0, 0),
                //new Node(2, 0, 0)
            };

            var h = 0.1;
            var w = 0.05;

            var a  = h * w;
            var iy = h * h * h * w / 12;
            var iz = w * w * w * h / 12;
            var j  = iy + iz;
            var e  = 210e9;

            var sec = new Sections.UniformParametric1DSection(a, iy, iz, j);
            var mat = UniformIsotropicMaterial.CreateFromYoungPoisson(e, 0.25);

            BarElement e1;

            model.Elements.Add(e1 = new BarElement(ndes[0], ndes[1])
            {
                Material = mat, Section = sec, Behavior = BarElementBehaviours.FullFrame
            });
            //model.Elements.Add(new BarElement(ndes[1], ndes[2]) { Material = mat, Section = sec, Behavior = BarElementBehaviours.FullFrame });

            e1.StartReleaseCondition =
                //e1.EndReleaseCondition =
                Constraints.MovementFixed;

            var ld = new Loads.UniformLoad(LoadCase.DefaultLoadCase, Vector.K, 1000, CoordinationSystem.Global);

            var eqload = e1.GetGlobalEquivalentNodalLoads(ld);


            model.Nodes.Add(ndes);

            ndes[0].Constraints = ndes[2].Constraints = Constraints.Fixed;
            //ndes[1].Constraints = ndes[2].Constraints = Constraints.Fixed;

            //for (var i = 0; i < model.Elements.Count; i++)
            //    (model.Elements[i] as BarElement).Loads.Add();

            //ndes[1].Loads.Add(new NodalLoad(new Force(0, 1, 0, 0, 0, 0)));



            model.Solve_MPC();

            var res  = OpenseesValidator.OpenseesValidate(model, LoadCase.DefaultLoadCase, false);
            var disp = res[0];

            var idx = disp.Columns["Absolute Error"].Ordinal;

            var max = disp.Rows.Cast <DataRow>().Select(i => (double)i[idx]).Max();
        }
        public static void Run1()
        {
            double h = 5;

            Node n1 = new Node(0, 0, 0);
            Node n2 = new Node(h, 0, 0);

            n1.Constraints = Constraints.Fixed;

            var section  = new UniformGeometric1DSection(SectionGenerator.GetRectangularSection(1, 0.5));
            var material = UniformIsotropicMaterial.CreateFromYoungShear(205e9, 81e9);

            BarElement e = new BarElement(n1, n2)
            {
                Section  = section,
                Material = material
            };

            e.Behavior = BarElementBehaviours.FullFrame;

            var lc1 = new LoadCase("C1", LoadType.Dead);
            var lc2 = new LoadCase("C2", LoadType.Live);
            var lc3 = new LoadCase("C3", LoadType.Live);

            var load = new UniformLoad()
            {
                Direction          = Vector.FromXYZ(0, 0, -1),
                CoordinationSystem = CoordinationSystem.Global,
                Magnitude          = 1,
                Case = lc1
            };
            var load2 = new UniformLoad()
            {
                Direction          = Vector.FromXYZ(1, 0, 0),
                CoordinationSystem = CoordinationSystem.Global,
                Magnitude          = 10,
                Case = lc2
            };

            var load3 = new ConcentratedLoad(new Force(0, 0, 0, 00, 10, 00), new IsoPoint(0.50), CoordinationSystem.Local);

            load3.Case = lc3;

            e.Loads.Add(load);
            e.Loads.Add(load2);
            e.Loads.Add(load3);

            Model model = new Model();

            model.Nodes.Add(n1);
            model.Nodes.Add(n2);
            model.Elements.Add(e);
            model.Solve_MPC();

            BarInternalForceVisualizer.VisualizeInNewWindow(e);
        }
        public static void SimplySupportedBeamUDL()
        {
            var model = new BriefFiniteElementNet.Model();

            var pin = new Constraint(
                dx: DofConstraint.Fixed, dy: DofConstraint.Fixed, dz: DofConstraint.Fixed,
                rx: DofConstraint.Fixed, ry: DofConstraint.Released, rz: DofConstraint.Released);

            Node n1, n2;

            model.Nodes.Add(n1 = new Node(x: 0.0, y: 0.0, z: 0.0)
            {
                Constraints = pin
            });
            model.Nodes.Add(n2 = new Node(x: 10.0, y: 0.0, z: 0.0)
            {
                Constraints = pin
            });

            var elm1 = new BarElement(n1, n2);

            model.Elements.Add(elm1);

            double       height   = 0.200;
            double       width    = 0.050;
            double       E        = 7900;
            var          section  = new UniformGeometric1DSection(SectionGenerator.GetRectangularSection(height, width));
            BaseMaterial material = UniformIsotropicMaterial.CreateFromYoungPoisson(E, 1);

            elm1.Section  = section;
            elm1.Material = material;

            var u1 = new Loads.UniformLoad(LoadCase.DefaultLoadCase, new Vector(0, 1, 1), -1, CoordinationSystem.Global);

            elm1.Loads.Add(u1);

            model.Solve_MPC();

            double x;
            Force  reaction1 = n1.GetSupportReaction();

            x = reaction1.Fz;                                             //15000 = 3*10000/2 -> correct
            x = reaction1.My;                                             // 0 -> correct

            Force f1_internal = elm1.GetExactInternalForceAt(-1 + 1e-10); //-1 is start

            x = f1_internal.Fz;
            x = f1_internal.My;

            var delta = elm1.GetInternalDisplacementAt(0);
        }
        public static void Run1()
        {
            var l     = 10;
            var model = new Model();

            model.Nodes.Add(new Node(0, 0, 0)
            {
                Label = "n0"
            });
            model.Nodes.Add(new Node(l, 0, 0)
            {
                Label = "n1"
            });
            //Fixed nodes
            model.Nodes["n0"].Constraints = Constraints.Fixed;
            model.Nodes["n1"].Constraints = Constraints.Fixed;

            var bar = new BarElement(model.Nodes["n0"], model.Nodes["n1"])
            {
                Label = "e0"
            };

            //Pinned bar releases

            bar.StartReleaseCondition = Constraints.MovementFixed;

            bar.EndReleaseCondition = Constraints.MovementFixed & Constraints.FixedRX;

            model.Elements.Add(bar);

            var sec = new UniformGeometric1DSection(SectionGenerator.GetISetion(0.24, 0.67, 0.01, 0.006));
            var mat = UniformIsotropicMaterial.CreateFromYoungPoisson(210e9, 0.3);

            (model.Elements["e0"] as BarElement).Material = mat;
            (model.Elements["e0"] as BarElement).Section  = sec;

            var u1 = new UniformLoad(LoadCase.DefaultLoadCase, -Vector.K, 1, CoordinationSystem.Global);

            model.Elements["e0"].Loads.Add(u1);

            model.Solve_MPC();

            var n0Force = model.Nodes["n0"].GetSupportReaction();
            var n1Force = model.Nodes["n1"].GetSupportReaction();

            Console.WriteLine("support reaction of n0: {0}, n1: {1}", n0Force, n1Force);

            var elm = model.Elements[0] as BarElement;

            BarInternalForceVisualizer.VisualizeInNewWindow(elm);
        }
        public static void TestBarStiffness()
        {
            var iy = 0.02;
            var iz = 0.02;
            var a  = 0.01;

            var j = iy + iz;

            var e = 210e9;
            var g = 70e9;
            //var rho = 13;

            var model = new Model();

            model.Nodes.Add(new Node(0, 0, 0));
            model.Nodes.Add(new Node(3, 5, 7));

            var barElement = new BarElement(model.Nodes[0], model.Nodes[1]);

            barElement.Behavior = BarElementBehaviours.FullFrame;
            barElement.Material = UniformIsotropicMaterial.CreateFromYoungShear(e, g);

            var frameElement = new FrameElement2Node(model.Nodes[0], model.Nodes[1])
            {
                Iy = iy,
                Iz = iz,
                A  = a,
                J  = j,
                E  = e,
                G  = g,
                //MassDensity = rho
            };

            frameElement.ConsiderShearDeformation = false;

            //barElement.Material = new UniformBarMaterial(e, g, rho);
            barElement.Section = new UniformParametric1DSection()
            {
                Iy = iy, Iz = iz, A = a
            };

            var frK  = frameElement.GetGlobalStifnessMatrix();
            var barK = barElement.GetGlobalStifnessMatrix();

            var d = (frK - barK).Max(i => Math.Abs(i));
        }
Exemple #9
0
        public static void testInternalForce_Console()
        {
            var model = new Model();
            var ndes  = new Node[] { new Node(0, 0, 0), new Node(3, 0, 0) };

            var h = UnitConverter.In2M(4);
            var w = UnitConverter.In2M(4);

            var e = UnitConverter.Psi2Pas(20e4);

            var a  = h * w;
            var iy = h * h * h * w / 12;
            var iz = w * w * w * h / 12;
            var j  = iy + iz;

            var sec = new Sections.UniformParametric1DSection(a = 1, iy = 1, iz = 1, j = 1);
            var mat = UniformIsotropicMaterial.CreateFromYoungPoisson(e = 1, 0.25);

            var elm = new BarElement(ndes[0], ndes[1])
            {
                Material = mat, Section = sec, Behavior = BarElementBehaviours.FullFrame
            };

            //var elm2 = new BarElement(ndes[1], ndes[2]) { Material = mat, Section = sec, Behavior = BarElementBehaviours.FullFrame };

            model.Elements.Add(elm);
            model.Nodes.Add(ndes);

            ndes[0].Constraints = Constraints.Fixed;

            ndes[1].Loads.Add(new NodalLoad(new Force(1, 0, 1, 0, 0, 0)));

            model.Solve_MPC();

            var tr = elm.GetTransformationManager();

            var d1 = tr.TransformLocalToGlobal(elm.GetInternalDisplacementAt(1 - 1e-10, LoadCase.DefaultLoadCase));
            var d2 = ndes[1].GetNodalDisplacement(LoadCase.DefaultLoadCase);


            var frc = elm.GetInternalForceAt(-1, LoadCase.DefaultLoadCase);

            var gfrc = elm.GetTransformationManager().TransformLocalToGlobal(frc);

            var f0 = ndes[0].GetSupportReaction();
        }
        private static void TestTrussShapeFunction()
        {
            var bar = new BarElement(3);

            bar.Nodes[0] = new Node(0, 0, 0);
            bar.Nodes[1] = new Node(1, 0, 0);
            bar.Nodes[2] = new Node(2, 0, 0);

            bar.Material = UniformIsotropicMaterial.CreateFromYoungPoisson(3, 0.3);
            bar.Section  = new Sections.UniformParametric1DSection(4);

            var hlp = new TrussHelper(bar);

            var pl = hlp.GetN_i(bar, 0);

            hlp.GetJMatrixAt(bar, 0);
            var stf = hlp.CalcLocalStiffnessMatrix(bar);
        }
Exemple #11
0
        public void Run3()
        {
            var m1 = new Model();

            var el1 = new BarElement();

            el1.Nodes[0] = new Node(0, 0, 0)
            {
                Constraints = Constraints.MovementFixed & Constraints.FixedRX, Label = "n0"
            };
            el1.Nodes[1] = new Node(4, 0, 3)
            {
                Constraints = Constraints.MovementFixed, Label = "n1"
            };

            el1.Section  = new Sections.UniformGeometric1DSection(SectionGenerator.GetISetion(0.24, 0.67, 0.01, 0.006));
            el1.Material = UniformIsotropicMaterial.CreateFromYoungPoisson(210e9, 0.3);


            var loadMagnitude = -1e3;
            var loadDirection = Vector.K;

            var l1 = new Loads.UniformLoad();

            var elementDir = el1.Nodes[1].Location - el1.Nodes[0].Location;//or n0 - n1, does not matter

            var absCosTeta = Vector.Cross(elementDir.GetUnit(), loadDirection.GetUnit()).Length;


            l1.Direction          = loadDirection;
            l1.CoordinationSystem = CoordinationSystem.Global;
            l1.Magnitude          = loadMagnitude * absCosTeta; //magnitude should multiple by reduction coefficient absCosTeta


            el1.Loads.Add(l1);

            m1.Elements.Add(el1);
            m1.Nodes.Add(el1.Nodes);

            m1.Solve_MPC();

            Console.WriteLine("n0 reaction: {0}", m1.Nodes[0].GetSupportReaction());
            Console.WriteLine("n1 reaction: {0}", m1.Nodes[0].GetSupportReaction());
        }
Exemple #12
0
        public static void ValidateConsoleUniformLoad()
        {
            var model = new Model();

            var ndes = new Node[] {
                new Node(0, 0, 0),
                new Node(5, 2, 3)
            };

            var h = 0.1;
            var w = 0.05;

            var a  = h * w;
            var iy = h * h * h * w / 12;
            var iz = w * w * w * h / 12;
            var j  = iy + iz;
            var e  = 210e9;

            var sec = new Sections.UniformParametric1DSection(a, iy, iz, j);
            var mat = UniformIsotropicMaterial.CreateFromYoungPoisson(e, 0.25);

            model.Elements.Add(new BarElement(ndes[0], ndes[1])
            {
                Material = mat, Section = sec, Behavior = BarElementBehaviours.FullFrame
            });

            model.Nodes.Add(ndes);

            ndes[0].Constraints = Constraints.Fixed;

            (model.Elements[0] as BarElement).Loads.Add(new Loads.UniformLoad(LoadCase.DefaultLoadCase, Vector.K, 1000, CoordinationSystem.Local));

            model.Solve_MPC();

            var res = OpenseesValidator.OpenseesValidate(model, LoadCase.DefaultLoadCase, false);

            var disp = res[0];

            var idx = disp.Columns["Absolute Error"].Ordinal;

            var max = disp.Rows.Cast <DataRow>().Select(i => (double)i[idx]).Max();
        }
        static public void test0()
        {
            var model = new Model();

            var n1 = new Node()
            {
                Constraints = Constraints.Fixed
            };
            var n2 = new Node(5, 0, 0)
            {
                Constraints = Constraints.Fixed
            };

            var old = n1.Constraints;

            old.DY         = DofConstraint.Released;
            n1.Constraints = old;

            var elm = new BarElement(n1, n2);

            var sec = SectionGenerator.GetRectangularSection(0.1, 0.1);

            elm.Section  = new UniformGeometric1DSection(sec);
            elm.Material = UniformIsotropicMaterial.CreateFromYoungPoisson(210e9, 0.3);

            n1.Settlements.Add(new Settlement(new Displacement(0, 0, 0.01)));

            model.Nodes.Add(n1);

            model.Nodes.Add(n2);
            model.Elements.Add(elm);

            model.Solve_MPC();

            var d = n1.GetNodalDisplacement();
        }
Exemple #14
0
        public void Run2()
        {
            var m1 = new Model();

            var el1 = new BarElement();

            el1.Nodes[0] = new Node(0, 0, 0)
            {
                Constraints = Constraints.MovementFixed & Constraints.FixedRX, Label = "n0"
            };
            el1.Nodes[1] = new Node(3, 0, 4)
            {
                Constraints = Constraints.MovementFixed, Label = "n1"
            };

            el1.Section  = new Sections.UniformGeometric1DSection(SectionGenerator.GetISetion(0.24, 0.67, 0.01, 0.006));
            el1.Material = UniformIsotropicMaterial.CreateFromYoungPoisson(210e9, 0.3);


            var l1 = new Loads.UniformLoad();

            l1.Direction          = Vector.K;
            l1.CoordinationSystem = CoordinationSystem.Local;
            l1.Magnitude          = 1e3;


            el1.Loads.Add(l1);

            m1.Elements.Add(el1);
            m1.Nodes.Add(el1.Nodes);

            m1.Solve_MPC();

            Console.WriteLine("n0 reaction: {0}", m1.Nodes[0].GetSupportReaction());
            Console.WriteLine("n1 reaction: {0}", m1.Nodes[0].GetSupportReaction());
        }
        public static void Run()
        {
            var model = new Model();

            var l = 5;

            var n1 = new Node(0, 0, 0);
            var n2 = new Node(0, 0, l);


            var axialLoad      = 1000;
            var horizontalLoad = 1000;

            var f = new Force(horizontalLoad, 0, axialLoad, 0, 0, 0);

            /**/
            var h = 0.1;
            var w = 0.05;

            var a  = h * w;
            var iy = h * h * h * w / 12;
            var iz = w * w * w * h / 12;
            var j  = iy + iz;
            var e  = 210e9;
            var nu = 0.3;

            var g = e / (2 * 1 + nu);
            /**/

            var sec = new Sections.UniformParametric1DSection(a, iy, iz, j);
            var mat = UniformIsotropicMaterial.CreateFromYoungShear(e, g);

            var belm = new BarElement(n1, n2)
            {
                Material = mat, Section = sec, Behavior = BarElementBehaviours.FullFrame
            };

            model.Elements.Add(belm);
            model.Nodes.Add(n1, n2);

            n1.Constraints = Constraints.Fixed;

            n2.Loads.Add(new NodalLoad(f));


            model.Solve_MPC();

            var d = model.Nodes[1].GetNodalDisplacement();

            var expectedDx = (horizontalLoad * l * l * l) / (3 * e * iy);
            var expectedRy = (horizontalLoad * l * l) / (2 * e * iy);
            var expectedDz = axialLoad * l / (e * a);

            var epsilon = 0.0;

            if (Math.Abs(d.DX - expectedDx) > epsilon)
            {
                throw new NotImplementedException();
            }
            if (Math.Abs(d.RY - expectedRy) > epsilon)
            {
                throw new NotImplementedException();
            }
            if (Math.Abs(d.DZ - expectedDz) > epsilon)
            {
                throw new NotImplementedException();
            }
        }
Exemple #16
0
        public static void ValidateEndRelease()
        {
            var model = new Model();

            var ndes = new Node[] {
                new Node(0, 0, 0),
                new Node(3, 0, 0),
                new Node(6, 0, 0),
            };

            /**/
            var h = 0.1;
            var w = 0.05;

            var a  = h * w;
            var iy = h * h * h * w / 12;
            var iz = w * w * w * h / 12;
            var j  = iy + iz;
            var e  = 210e9;
            var nu = 0.3;

            var g = e / (2 * 1 + nu);
            /**/

            var sec = new Sections.UniformParametric1DSection(a, iy, iz, j);
            var mat = UniformIsotropicMaterial.CreateFromYoungShear(e, g);

            {
                var belm = new BarElement(ndes[0], ndes[1])
                {
                    Material = mat, Section = sec, Behavior = BarElementBehaviours.FullFrame
                };

                belm.StartReleaseCondition =
                    Constraints.FixedDX & Constraints.FixedDY & Constraints.FixedDZ &
                    Constraints.FixedRX;

                model.Elements.Add(belm);
            }
            {
                var belm = new BarElement(ndes[1], ndes[2])
                {
                    Material = mat, Section = sec, Behavior = BarElementBehaviours.FullFrame
                };

                belm.EndReleaseCondition =
                    Constraints.FixedDX & Constraints.FixedDY & Constraints.FixedDZ &
                    Constraints.FixedRX;

                model.Elements.Add(belm);
            }


            model.Nodes.Add(ndes);

            ndes[0].Constraints = ndes[2].Constraints = Constraints.Fixed;

            //ndes[1].Constraints =
            //    Constraints.FixedDX & Constraints.FixedRX
            //& Constraints.FixedDY & Constraints.FixedRZ//find beam.z dofs

            ;
            //(model.Elements[0] as BarElement).Loads.Add(new Loads.UniformLoad(LoadCase.DefaultLoadCase, Vector.K, 1000, CoordinationSystem.Local));

            ndes[1].Loads.Add(new NodalLoad(new Force(Vector.K, Vector.Zero)));
            //ndes[1].Loads.Add(new NodalLoad(new Force(Vector.J * 2, Vector.Zero)));

            model.Solve_MPC();


            var d = model.Nodes[1].GetNodalDisplacement();


            var t = (model.Elements[0] as BarElement).GetInternalForceAt(1);


            var res = OpenseesValidator.OpenseesValidate(model, LoadCase.DefaultLoadCase, false);

            var disp = res[0];

            var idx = disp.Columns["Absolute Error"].Ordinal;

            var max = disp.Rows.Cast <DataRow>().Select(i => (double)i[idx]).Max();
        }
Exemple #17
0
        public static Model Generate3DTetrahedralElementGrid(int m, int n, int l)
        {
            var buf = new Model();

            var dx = 1.0;
            var dy = 1.0;
            var dz = 1.0;

            var nodes = new Node[m, n, l];

            for (int k = 0; k < l; k++)
            {
                for (int i = 0; i < n; i++)
                {
                    for (int j = 0; j < m; j++)
                    {
                        var pos = new Point(i * dx, j * dy, k * dz);
                        var nde = new Node()
                        {
                            Location = pos
                        };
                        buf.Nodes.Add(nde);

                        nde.Constraints = Constraints.RotationFixed;

                        nodes[j, i, k] = nde;
                    }
                }
            }


            var elm = new Func <Node, Node, Node, Node, TetrahedronElement>((n1, n2, n3, n4) =>
            {
                var buff = new TetrahedronElement();

                buff.Nodes[0] = n1;
                buff.Nodes[1] = n2;
                buff.Nodes[2] = n3;
                buff.Nodes[3] = n4;

                buff.Material = UniformIsotropicMaterial.CreateFromYoungPoisson(210e9, 0.3);

                buff.FixNodeOrder();
                return(buff);
            });

            var elms = new List <Element>();

            for (int i = 0; i < m - 1; i++)
            {
                for (int j = 0; j < n - 1; j++)
                {
                    for (int k = 0; k < l - 1; k++)
                    {
                        var ns = new Node[] {
                            nodes[i, j, k],
                            nodes[i + 1, j, k],
                            nodes[i + 1, j + 1, k],
                            nodes[i, j + 1, k],

                            nodes[i, j, k + 1],
                            nodes[i + 1, j, k + 1],
                            nodes[i + 1, j + 1, k + 1],
                            nodes[i, j + 1, k + 1],
                        };


                        elms.Add(elm(ns[0], ns[1], ns[3], ns[4]));
                        elms.Add(elm(ns[2], ns[1], ns[3], ns[6]));

                        elms.Add(elm(ns[1], ns[3], ns[4], ns[6]));

                        elms.Add(elm(ns[4], ns[5], ns[6], ns[1]));
                        elms.Add(elm(ns[4], ns[6], ns[7], ns[3]));
                    }
                }
            }

            buf.Elements.Add(elms.ToArray());

            for (int i = 0; i < n * m; i++)
            {
                buf.Nodes[i].Constraints = Constraints.Fixed;
            }


            return(buf);
        }
        /// <summary>
        /// Method that reads an Abaqus input file and returns a BFE model with the same nodes and elements
        /// </summary>
        /// <param name="path">Path to an input file</param>
        /// <returns>A BFE model</returns>
        public static Model AbaqusInputToBFE(string pathToInputFile)
        {
            var buf = new Model();

            //splitting char
            char delimiter = ',';
            Node node;
            TetrahedronElement element;

            //list for the node- and elementsets
            List <NodeSet>    nodeSets    = new List <NodeSet>();
            List <ElementSet> elementSets = new List <ElementSet>();

            using (StreamReader sr = File.OpenText(pathToInputFile))
            {
                string[] split;
                selectedInputVariable selectedVar = selectedInputVariable.Nodes;
                string input = sr.ReadLine();
                while (input != null)
                {
                    split = input.Split(delimiter);
                    if (split[0].Contains('*'))
                    {
                        switch (split[0])
                        {
                        case "*Node":
                            selectedVar = selectedInputVariable.Nodes;
                            break;

                        case "*Element":
                            selectedVar = selectedInputVariable.Elements;
                            break;

                        case "*Nset":
                            selectedVar = selectedInputVariable.NodeSet;
                            nodeSets.Add(new NodeSet()
                            {
                                Name = split[1].Replace("nset=", "")
                            });
                            break;

                        case "*Elset":
                            selectedVar = selectedInputVariable.ElementSet;
                            elementSets.Add(new ElementSet()
                            {
                                Name = split[1].Replace("elset=", "")
                            });
                            break;

                        case "*Cload":
                            selectedVar = selectedInputVariable.CLoad;
                            break;

                        case "*Boundary":
                            selectedVar = selectedInputVariable.BC;
                            break;

                        default:
                            selectedVar = selectedInputVariable.Other;
                            break;
                        }
                    }
                    else
                    {
                        switch (selectedVar)
                        {
                        case selectedInputVariable.Nodes:
                        {
                            node = ReadNode(input, delimiter);
                            if (node != null)
                            {
                                //tetrahedron element - > fix rotation
                                node.Constraints = Constraints.RotationFixed;
                                buf.Nodes.Add(node);
                            }
                            break;
                        }

                        case selectedInputVariable.Elements:
                        {
                            element = ReadTetraElement(input, delimiter, buf.Nodes);
                            if (element != null)
                            {
                                element.Material = UniformIsotropicMaterial.CreateFromYoungPoisson(210e9, 0.25);
                                element.FixNodeOrder();
                                buf.Elements.Add(element);
                            }
                            break;
                        }

                        case selectedInputVariable.NodeSet:
                        {
                            for (int i = 0; i < split.Count(); i++)
                            {
                                nodeSets[nodeSets.Count - 1].Nodes.Add(Convert.ToInt32(split[i]));
                            }
                            break;
                        }

                        case selectedInputVariable.ElementSet:
                        {
                            for (int i = 0; i < split.Count(); i++)
                            {
                                elementSets[elementSets.Count - 1].Elements.Add(Convert.ToInt32(split[i]));
                            }
                            break;
                        }

                        case selectedInputVariable.CLoad:
                        {
                            NodeSet set = nodeSets.Where(x => x.Name.Replace(" ", "") == split[0].Replace(" ", "")).FirstOrDefault();
                            if (set != null)
                            {
                                //determine the magnitude of the load
                                var load = new BriefFiniteElementNet.NodalLoad();
                                var frc  = new Force();
                                if (Convert.ToInt32(split[1]) == 1)
                                {
                                    frc.Fx     = Convert.ToDouble(split[2]);
                                    load.Force = frc;
                                }
                                else if (Convert.ToInt32(split[1]) == 2)
                                {
                                    frc.Fy     = Convert.ToDouble(split[2]);
                                    load.Force = frc;
                                }
                                else if (Convert.ToInt32(split[1]) == 3)
                                {
                                    frc.Fz     = Convert.ToDouble(split[2]);
                                    load.Force = frc;
                                }
                                //add the load to the nodes
                                foreach (var nodeLabel in set.Nodes)
                                {
                                    buf.Nodes[nodeLabel - 1].Loads.Add(load);
                                }
                            }
                            break;
                        }

                        case selectedInputVariable.BC:
                        {
                            NodeSet set = nodeSets.Where(x => x.Name.Replace(" ", "") == split[0].Replace(" ", "")).FirstOrDefault();
                            if (set != null)
                            {
                                //add the load to the nodes
                                foreach (var nodeLabel in set.Nodes)
                                {
                                    buf.Nodes[nodeLabel - 1].Constraints = Constraints.Fixed;
                                }
                            }
                            break;
                        }

                        default:
                            break;
                        }
                    }
                    input = sr.ReadLine();
                }
            }
            return(buf);
        }
        public static void ValidateConsoleUniformLoad()
        {
            var model = new Model();

            var ndes = new Node[] {
                new Node(0, 0, 0),
                new Node(3, 0, 0)
            };

            /**/
            var h = 0.1;
            var w = 0.05;

            var a  = h * w;
            var iy = h * h * h * w / 12;
            var iz = w * w * w * h / 12;
            var j  = iy + iz;
            var e  = 210e9;
            var nu = 0.3;

            var g = e / (2 * 1 + nu);
            /**/

            var sec = new Sections.UniformParametric1DSection(a, iy, iz, j);
            var mat = UniformIsotropicMaterial.CreateFromYoungShear(e, g);

            BarElement        belm;
            FrameElement2Node frmelm;

            belm = new BarElement(ndes[0], ndes[1])
            {
                Material = mat, Section = sec, Behavior = BarElementBehaviours.FullFrame
            };
            frmelm = new FrameElement2Node(ndes[0], ndes[1])
            {
                Iz = sec.Iz, Iy = sec.Iy, A = sec.A, J = sec.J, E = e, G = g
            };

            var bk   = belm.GetGlobalStifnessMatrix();
            var fk   = frmelm.GetGlobalStifnessMatrix();
            var diff = bk - fk;

            model.Elements.Add(belm);

            model.Nodes.Add(ndes);

            ndes[0].Constraints = Constraints.Fixed;

            //ndes[1].Constraints =
            //    Constraints.FixedDX & Constraints.FixedRX
            //& Constraints.FixedDY & Constraints.FixedRZ//find beam.z dofs

            ;
            var ul = new Loads.UniformLoad(LoadCase.DefaultLoadCase, Vector.K, 1000, CoordinationSystem.Global);

            (model.Elements[0] as BarElement).Loads.Add(ul);


            var eqv = (model.Elements[0] as BarElement).GetGlobalEquivalentNodalLoads(ul);

            //ndes[1].Loads.Add(new NodalLoad(new Force(Vector.K, Vector.Zero)));
            //ndes[1].Loads.Add(new NodalLoad(new Force(Vector.J*2, Vector.Zero)));

            model.Solve_MPC();


            var d = model.Nodes[1].GetNodalDisplacement();

            var t = (model.Elements[0] as BarElement).GetInternalForceAt(-1);


            var res = OpenseesValidator.OpenseesValidate(model, LoadCase.DefaultLoadCase, false);

            var disp = res[0];

            var idx = disp.Columns["Absolute Error"].Ordinal;

            var max = disp.Rows.Cast <DataRow>().Select(i => (double)i[idx]).Max();
        }
        public ValidationResult Validate()
        {
            var model = new Model();

            var ndes = new Node[] {
                new Node(0, 0, 0),
                new Node(1, 0, 0),
                new Node(2, 0, 0),
                new Node(3, 0, 0),
            };

            /**/
            var h = 0.1;
            var w = 0.05;

            var a  = h * w;
            var iy = h * h * h * w / 12;
            var iz = w * w * w * h / 12;
            var j  = iy + iz;
            var e  = 210e9;
            var nu = 0.3;

            var g = e / (2 * 1 + nu);
            /**/

            var sec = new Sections.UniformParametric1DSection(a, iy, iz, j);
            var mat = UniformIsotropicMaterial.CreateFromYoungShear(e, g);

            //bar-element -> rigid linkg -> bar element
            {
                var barElm = new BarElement(ndes[0], ndes[1])
                {
                    Material = mat, Section = sec, Behavior = BarElementBehaviours.FullFrame
                };
                model.Elements.Add(barElm);
            }
            {
                var rigidElm = new RigidElement_MPC();
                rigidElm.Nodes = new NodeList()
                {
                    ndes[1], ndes[2]
                };
                rigidElm.UseForAllLoads = true;
                model.MpcElements.Add(rigidElm);
            }
            {
                var barElm = new BarElement(ndes[2], ndes[3])
                {
                    Material = mat, Section = sec, Behavior = BarElementBehaviours.FullFrame
                };
                model.Elements.Add(barElm);
            }
            model.Nodes.Add(ndes);

            ndes[0].Constraints = Constraints.Fixed;

            ndes[3].Loads.Add(new NodalLoad(new Force(1000, 2000, 5000, 1000, 2000, 2000)));
            //ndes[1].Loads.Add(new NodalLoad(new Force(Vector.J * 2, Vector.Zero)));

            model.Solve_MPC();

            var span = new HtmlTag("span");

            span.Add("p").Text("Validation of rigid element");
            span.Add("paragraph").Text("The rigid element connects different nodes through non-deformable elements. ");
            span.Add("h3").Text("Model Definition");

            span.Add("paragraph").Text(string.Format(CultureInfo.CurrentCulture, "A linear beam of 3 meters long, with 4 nodes, 2 bar elements and 1 rigid element in-between.")).AddClosedTag("br");

            span.Add("paragraph").Text("The first node is fixed in the 3D space.").AddClosedTag("br");
            span.Add("paragraph").Text("The last node is loaded with a random load; both forces and moments.").AddClosedTag("br");
            span.Add("paragraph").Text("The rigid element should transfer all rotational DOF from the second node to the thrid. The displacements  along the beam will be trasnfered ass well, although the the displacements in the perpendicular direct will scale.").AddClosedTag("br");

            span.Add("h3").Text("Validation Result");
            span.Add("h4").Text("Nodal Displacements");
            span.Add("paragraph").Text(string.Format("Validation output for nodal displacements:"));


            var n1   = model.Nodes[1].GetNodalDisplacement();
            var n2   = model.Nodes[2].GetNodalDisplacement();
            var diff = n1 - n2;

            //linear beam with loads -> rigid elements introduces rigid body -> Y and Z (translations perpendicular to the beam) are non zero and scaled. Set to zero to avoid confusion with result.
            diff.DY = diff.DZ = 0.0;

            //span.Add("p").AddClass("bg-info").Text(string.Format("-Max ABSOLUTE Error: {0:e3}", diff));//htmltags cannot encode the delta and teta chars so will use vector length
            span.Add("p").AddClass("bg-info")
            .Text(string.Format("-Max ABSOLUTE Error: Displacement:{0:e3} , Rotation:{1:e3}",
                                diff.Displacements.Length, diff.Rotations.Length));

            var buf = new ValidationResult();

            buf.Span  = span;
            buf.Title = "Rigid element Validation";

            return(buf);
        }