Example #1
0
        public static void TestEndrelease()
        {
            var m1 = new Model();
            var m2 = new Model();

            var l = 4.0;

            var I = (0.1 * 0.1 * 0.1 * 0.1) / 12;
            var A = (0.1 * 0.1 * 0.1);
            var E = 210e9;

            var sec = new Sections.UniformParametric1DSection(A, I, I, I);
            var mat = new Materials.UniformIsotropicMaterial(E, 0.3);
            var p   = 1e3;


            //var p0 = new Point(0, 0, 0);
            //var p1 = new Point(3, 4, 5);


            {//model 1
                var el1 = new BarElement(2);
                var el2 = new BarElement(2);

                el1.Nodes[0] = new Node(0, 0, 0)
                {
                    Constraints = Constraints.Fixed, Label = "n0"
                };;
                el2.Nodes[0] = el1.Nodes[1] = new Node(l / 2, 0, 0)
                {
                    Label = "n1"
                };
                el2.Nodes[1] = new Node(l, 0, 0)
                {
                    Label = "n2"
                };

                el1.Section  = el2.Section = sec;
                el1.Material = el2.Material = mat;

                m1.Nodes.Add(el1.Nodes);
                m1.Nodes.Add(el2.Nodes[1]);

                m1.Elements.Add(el1, el2);

                m1.Nodes["n1"].Loads.Add(new NodalLoad(new Force(0, 0, p, 0, 0, 0)));

                var k = (el1 as BarElement).GetLocalStifnessMatrix();
            }

            {//model 2
                var el2 = new BarElement(3);

                el2.Nodes[0] = new Node(0, 0, 0)
                {
                    Constraints = Constraints.Fixed, Label = "n0"
                };
                el2.Nodes[1] = new Node(l / 2, 0, 0)
                {
                    Label = "n1"
                };
                el2.Nodes[2] = new Node(l, 0, 0)
                {
                    Constraints = Constraints.Fixed, Label = "n2"
                };

                el2.NodalReleaseConditions[2] = Constraints.Released;

                el2.Section  = sec;
                el2.Material = mat;

                m2.Nodes.Add(el2.Nodes);
                m2.Elements.Add(el2);

                m2.Nodes["n1"].Loads.Add(new NodalLoad(new Force(0, 0, p, 0, 0, 0)));

                var k = (el2 as BarElement).GetLocalStifnessMatrix();
            }

            m1.Solve_MPC();
            m2.Solve_MPC();

            var d1 = m1.Nodes["n1"].GetNodalDisplacement();
            var d2 = m2.Nodes["n1"].GetNodalDisplacement();
        }
Example #2
0
        public static void Test3NodeBeam()
        {
            var m1 = new Model();
            var m2 = new Model();

            var l = 2.0;

            var I = 1; //(0.1 * 0.1 * 0.1 * 0.1) / 12;
            var A = 1; //(0.1 * 0.1 * 0.1);
            var E = 1; //210e9;

            var sec = new Sections.UniformParametric1DSection(A, I, I, I);
            var mat = new Materials.UniformIsotropicMaterial(E, 0.3);
            var p   = 1e3;


            //var p0 = new Point(0, 0, 0);
            //var p1 = new Point(3, 4, 5);


            {//model 1
                var el1 = new BarElement(3);

                //el1.Behavior= BarElementBehaviour.BeamZEulerBernoulli;
                el1.Nodes[0] = new Node(0, 0, 0)
                {
                    Constraints = Constraints.Fixed
                };;
                el1.Nodes[1] = new Node(l / 2, 0, 0)
                {
                    Constraints = Constraints.Released
                };
                el1.Nodes[2] = new Node(l, 0, 0)
                {
                    Constraints = Constraints.Released
                };

                el1.Section  = sec;
                el1.Material = mat;

                m1.Nodes.Add(el1.Nodes);
                m1.Elements.Add(el1);
                m1.Nodes.Last().Loads.Add(new NodalLoad(new Force(0, 0, p, 0, 0, 0)));

                var k = (el1 as BarElement).GetLocalStifnessMatrix();
            }


            {//model 2
                var el1 = new BarElement(3);

                //el1.Behavior= BarElementBehaviour.BeamZEulerBernoulli;
                el1.Nodes[0] = new Node(0, 0, 0)
                {
                    Constraints = Constraints.Fixed
                };;
                el1.Nodes[1] = new Node(l / 2, 0, 0)
                {
                    Constraints = Constraints.Released
                };
                el1.Nodes[2] = new Node(l, 0, 0)
                {
                    Constraints = Constraints.Released
                };

                el1.Section  = sec;
                el1.Material = mat;

                m1.Nodes.Add(el1.Nodes);
                m1.Elements.Add(el1);
                m1.Nodes.Last().Loads.Add(new NodalLoad(new Force(0, 0, p, 0, 0, 0)));

                var k = (el1 as BarElement).GetLocalStifnessMatrix();
            }


            m1.Solve_MPC();

            var d1 = m1.Nodes.First().GetSupportReaction();
            //var d2 = m2.Nodes.Last().GetNodalDisplacement();
        }
        public ValidationResult Validate()
        {
            var val = new ValidationResult();

            val.Title = "I Beam torsion with triangle element";

            var span = val.Span = new HtmlTag("span");

            {//report
                span.Add("p").Text("Validate an I Beam nodal displacement and reactions and internal forces");
                span.Add("h3").Text("Validate with");
                span.Add("paragraph").Text("SAP2000");
                span.Add("h3").Text("Validate objective");


                span.Add("paragraph").Text("compare nodal displacement for a model consist of Triangle Elements");

                span.Add("h3").Text("Model Definition");

                span.Add("paragraph")
                .Text("An I shaped beam, totally fixed on one side and under a couple force on other side")
                .AddClosedTag("br");

                span.Add("h3").Text("Validation Result");
            }
            //var magic = 0;

            //example #13 p175


            #region creating model

            var model = new Model();

            var l = UnitConverter.In2M(40);
            var w = UnitConverter.In2M(10);
            var h = UnitConverter.In2M(5);
            var t = UnitConverter.In2M(0.25);

            var e  = UnitConverter.Ksi2Pas(10000); //10'000 ksi
            var no = 0.3;

            var n = 9;

            var xSpan = l / (n - 1);

            var nodes = new Node[n][];

            for (var i = 0; i < n; i++)
            {
                var x = i * xSpan;

                nodes[i] = new Node[7];

                nodes[i][0] = new Node(x, 0, 0);
                nodes[i][1] = new Node(x, w / 2, 0);
                nodes[i][2] = new Node(x, w, 0);

                nodes[i][3] = new Node(x, w / 2, h / 2);

                nodes[i][4] = new Node(x, 0, h);
                nodes[i][5] = new Node(x, w / 2, h);
                nodes[i][6] = new Node(x, w, h);

                model.Nodes.AddRange(nodes[i]);
            }

            var pairs = new int[6][];

            pairs[0] = new int[] { 0, 1 };
            pairs[1] = new int[] { 1, 2 };
            pairs[2] = new int[] { 1, 3 };
            pairs[3] = new int[] { 3, 5 };
            pairs[4] = new int[] { 4, 5 };
            pairs[5] = new int[] { 5, 6 };


            var mat = new Materials.UniformIsotropicMaterial(e, no);
            var sec = new Sections.UniformParametric2DSection(t);


            for (var i = 0; i < n - 1; i++)
            {
                for (int j = 0; j < 6; j++)
                {
                    var n11 = nodes[i][pairs[j][0]];
                    var n12 = nodes[i][pairs[j][1]];

                    var n21 = nodes[i + 1][pairs[j][0]];
                    var n22 = nodes[i + 1][pairs[j][1]];

                    {
                        var elm1 = new TriangleElement()
                        {
                            Material = mat, Section = sec
                        };

                        elm1.Nodes[0] = n11;
                        elm1.Nodes[1] = n12;
                        elm1.Nodes[2] = n21;

                        model.Elements.Add(elm1);

                        var elm2 = new TriangleElement()
                        {
                            Material = mat, Section = sec
                        };

                        elm2.Nodes[0] = n21;
                        elm2.Nodes[1] = n22;
                        elm2.Nodes[2] = n12;

                        model.Elements.Add(elm2);
                    }
                }
            }

            //loading
            nodes.Last()[0].Loads.Add(new NodalLoad(new Force(0, UnitConverter.Kip2N(1.6), 0, 0, 0, 0)));
            nodes.Last()[6].Loads.Add(new NodalLoad(new Force(0, -UnitConverter.Kip2N(1.6), 0, 0, 0, 0)));

            nodes[0].ToList().ForEach(i => i.Constraints = Constraints.Fixed);

            #endregion

            model.Trace.Listeners.Add(new BriefFiniteElementNet.Common.ConsoleTraceListener());
            new ModelWarningChecker().CheckModel(model);

            model.Solve_MPC();

            //show the model
            //ModelVisualizer.TestShowVisualizer(model);

            //generate a list of all results
            List <string> results = new List <string>();
            results.Add("Index ; S11 ; S12 ; S13 ; S21 ; S22 ; S23 ; S31 ; S32 ; S33 ; SVM");
            foreach (var element in model.Elements)
            {
                var el     = (TriangleElement)element;
                var index  = el.GetIndex();
                var cauchy = el.GetInternalStress(new double[] { 0.166666666, 0.1666666, 1.0 }, LoadCombination.DefaultLoadCombination, SectionPoints.Envelope);
                results.Add(index + ";" + cauchy.S11 + ";" + cauchy.S12 + ";" + cauchy.S13 + ";" + cauchy.S21 + ";" + cauchy.S22 + ";" + cauchy.S23
                            + ";" + cauchy.S31 + ";" + cauchy.S32 + ";" + cauchy.S33 + ";" + CauchyStressTensor.GetVonMisesStress(cauchy));

                cauchy = el.GetInternalStress(new double[] { 0.6666666, 0.1666666, 1.0 }, LoadCombination.DefaultLoadCombination, SectionPoints.Envelope);
                results.Add(index + ";" + cauchy.S11 + ";" + cauchy.S12 + ";" + cauchy.S13 + ";" + cauchy.S21 + ";" + cauchy.S22 + ";" + cauchy.S23
                            + ";" + cauchy.S31 + ";" + cauchy.S32 + ";" + cauchy.S33 + ";" + CauchyStressTensor.GetVonMisesStress(cauchy));

                cauchy = el.GetInternalStress(new double[] { 0.166666666, 0.6666666, 1.0 }, LoadCombination.DefaultLoadCombination, SectionPoints.Envelope);
                results.Add(index + ";" + cauchy.S11 + ";" + cauchy.S12 + ";" + cauchy.S13 + ";" + cauchy.S21 + ";" + cauchy.S22 + ";" + cauchy.S23
                            + ";" + cauchy.S31 + ";" + cauchy.S32 + ";" + cauchy.S33 + ";" + CauchyStressTensor.GetVonMisesStress(cauchy));
            }
            //Write data if needed
            //File.WriteAllLines("Insert path here!!", results.ToArray());


            var A = nodes.Last()[2];
            var B = nodes.Last()[4];
            var C = nodes.First()[1];
            var D = nodes.First()[0];
            var E = nodes.Last()[6];

            /*
             * for (int i = 0; i < nodes.Last().Length; i++)
             * {
             *  nodes.Last()[i].Label = i.ToString();
             * }
             */

            /**/
            A.Label = "A";
            B.Label = "B";
            C.Label = "C";
            D.Label = "D";
            E.Label = "E";
            /**/


            var n50 = model.Nodes[50];
            var n56 = model.Nodes[56];
            var n57 = model.Nodes[57];


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

                var da = 1 / 0.0254 * A.GetNodalDisplacement().Displacements;        // [inch]
                var db = 1 / 0.0254 * B.GetNodalDisplacement().Displacements;        // [inch]

                var d50 = 1 / 0.0254 * n50.GetNodalDisplacement().Displacements;     // [inch]
                var d56 = 1 / 0.0254 * n56.GetNodalDisplacement().Displacements;     // [inch]
                var d57 = 1 / 0.0254 * n57.GetNodalDisplacement().Displacements;     // [inch]

                var sap2000Da = new Vector(-0.014921, 0.085471, 0.146070);           //tbl 7.14
                var sap2000Db = new Vector(-0.014834, -0.085475, -0.144533);         //tbl 7.14

                var abaqusDa = new Vector(-15.4207E-03, 88.2587E-03, 150.910E-03);   //node 9
                var abaqusDb = new Vector(-15.3246E-03, -88.2629E-03, -148.940E-03); //node 5

                var abaqus8  = new Vector(-120.875E-06, 88.3894E-03, -1.01662E-03);  //node 8
                var abaqus12 = new Vector(15.3931E-03, 89.1206E-03, -149.515E-03);   //node 12
                var abaqus41 = new Vector(-189.084E-06, 72.3778E-03, -734.918E-06);  //node 41


                span.Add("paragraph").Text(string.Format("Validation output for nodal displacements:"));

                span.Add("paragraph").Text(string.Format("Err at node A (displacement): {0:0.00}%", Util.GetErrorPercent(da, abaqusDa))).AddClosedTag("br");;
                span.Add("paragraph").Text(string.Format("Err at node B (displacement): {0:0.00}%", Util.GetErrorPercent(db, abaqusDb))).AddClosedTag("br");;

                span.Add("paragraph").Text(string.Format("Err at node 41 (57) (displacement): {0:0.00}%", Util.GetErrorPercent(d50, abaqus41))).AddClosedTag("br");;
                span.Add("paragraph").Text(string.Format("Err at node 12 (56) (displacement): {0:0.00}%", Util.GetErrorPercent(d56, abaqus12))).AddClosedTag("br");;
                span.Add("paragraph").Text(string.Format("Err at node 08 (50) (displacement): {0:0.00}%", Util.GetErrorPercent(d57, abaqus8))).AddClosedTag("br");;
            }

            {//element stress
                {
                    var e81 = model.Elements[85] as TriangleElement;

                    var tr = e81.GetTransformationManager();

                    //t = 1/t;

                    var am = tr.TransformLocalToGlobal(e81.GetLocalInternalStress(LoadCase.DefaultLoadCase, 1 / 6.0, 1 / 6.0, 0) * (1 / t));
                    var at = tr.TransformLocalToGlobal(e81.GetLocalInternalStress(LoadCase.DefaultLoadCase, 1 / 6.0, 1 / 6.0, +1) * (1 / t));
                    var ab = tr.TransformLocalToGlobal(e81.GetLocalInternalStress(LoadCase.DefaultLoadCase, 1 / 6.0, 1 / 6.0, -1) * (1 / t));

                    var bm = tr.TransformLocalToGlobal(e81.GetLocalInternalStress(LoadCase.DefaultLoadCase, 4 / 6.0, 1 / 6.0, 0) * (1 / t));
                    var bt = tr.TransformGlobalToLocal(e81.GetLocalInternalStress(LoadCase.DefaultLoadCase, 4 / 6.0, 1 / 6.0, +1) * (1 / t));
                    var bb = tr.TransformLocalToGlobal(e81.GetLocalInternalStress(LoadCase.DefaultLoadCase, 4 / 6.0, 1 / 6.0, -1) * (1 / t));

                    var cm = tr.TransformLocalToGlobal(e81.GetLocalInternalStress(LoadCase.DefaultLoadCase, 1 / 6.0, 4 / 6.0, 0) * (1 / t));
                    var ct = tr.TransformLocalToGlobal(e81.GetLocalInternalStress(LoadCase.DefaultLoadCase, 1 / 6.0, 4 / 6.0, +1) * (1 / t));
                    var cb = tr.TransformLocalToGlobal(e81.GetLocalInternalStress(LoadCase.DefaultLoadCase, 1 / 6.0, 4 / 6.0, -1) * (1 / t));

                    var abacus_at = new CauchyStressTensor()
                    {
                        S11 = 103.814E-03, S22 = 249.185E-03, S12 = 1.03438, S21 = 1.03438
                    } *-1e9;
                    var abacus_bt = new CauchyStressTensor()
                    {
                        S11 = -34.7168E-03, S22 = -538.942E-03, S12 = 1.03438, S21 = 1.08243
                    } *-1e9;
                    var abacus_ct = new CauchyStressTensor()
                    {
                        S11 = -201.062E-03, S22 = -1.18348, S12 = 747.243E-03, S21 = 747.243E-03
                    } *-1e9;

                    var e1 = Util.GetErrorPercent(at, abacus_ct);
                    var e2 = Util.GetErrorPercent(bt, abacus_at);
                    var e3 = Util.GetErrorPercent(ct, abacus_bt);

                    span.Add("paragraph").Text(string.Format("Validation output for element stress:"));

                    span.Add("paragraph").Text(string.Format("Err at p1 element 81 (stress): {0:0.00}%", e1)).AddClosedTag("br");
                    span.Add("paragraph").Text(string.Format("Err at p2 element 81 (stress): {0:0.00}%", e2)).AddClosedTag("br");
                    span.Add("paragraph").Text(string.Format("Err at p3 element 81 (stress): {0:0.00}%", e3)).AddClosedTag("br");

                    //in abaqus e81 connected to 8-12-41
                    //in bfe e85 connected to 57-56-50
                }
            }

            return(val);
        }
        public ValidationResult Validate()
        {
            var val = new ValidationResult();

            val.Title = "I Beam torsion with triangle element";

            var span = val.Span = new HtmlTag("span");

            {//report
                span.Add("p").Text("Validate an I Beam nodal displacement and reactions and internal forces");
                span.Add("h3").Text("Validate with");
                span.Add("paragraph").Text("Abaqus");
                span.Add("h3").Text("Validate objective");


                span.Add("paragraph").Text("compare nodal displacement for a model consist of Triangle Elements");

                span.Add("h3").Text("Model Definition");

                span.Add("paragraph")
                .Text("An I shaped beam, totally fixed on one side and under a couple force on other side")
                .AddClosedTag("br");

                span.Add("h3").Text("Validation Result");
            }
            //var magic = 0;

            //example #13 p175


            #region creating model

            //var l = UnitConverter.In2M(40);
            //var w = UnitConverter.In2M(10);
            //var h = UnitConverter.In2M(5);
            var t = 0.25;     // UnitConverter.In2M(0.25);

            var e  = 10000.0; // UnitConverter.Ksi2Pas(10000); //10'000 ksi
            var no = 0.3;

            var mat = new Materials.UniformIsotropicMaterial(e, no);
            var sec = new Sections.UniformParametric2DSection(t);

            var model = AbaqusInputFileReader.AbaqusInputToBFE("Case_01V2\\data1\\job-1.inp");

            {                                    //inp file is imerial unit, bfe is metric
                foreach (var nde in model.Nodes) //location
                {
                    var lc = nde.Location;

                    lc.X = UnitConverter.In2M(lc.X);
                    lc.Y = UnitConverter.In2M(lc.Y);
                    lc.Z = UnitConverter.In2M(lc.Z);

                    //nde.Location = lc;


                    if (nde.Constraints == Constraints.RotationFixed)
                    {
                        nde.Constraints = Constraints.Released;
                    }
                }

                foreach (var nde in model.Nodes)//loads
                {
                    foreach (var ld in nde.Loads)
                    {
                        var f = ld.Force;

                        f.Fx = UnitConverter.Kip2N(f.Fx);
                        f.Fy = UnitConverter.Kip2N(f.Fy);
                        f.Fz = UnitConverter.Kip2N(f.Fz);

                        //ld.Force = f;
                    }
                }
            }


            foreach (var elm in model.Elements)
            {
                if (elm is TriangleElement tri)
                {
                    tri.Material = mat;
                    tri.Section  = sec;

                    tri.MembraneFormulation = MembraneFormulation.PlaneStress;
                    tri.Behavior            = PlaneElementBehaviours.FullThinShell;
                }
            }

            #endregion

            model.Trace.Listeners.Add(new Common.ConsoleTraceListener());
            new ModelWarningChecker().CheckModel(model);

            model.Solve_MPC();

            var bfeNodalDisp = model.Nodes.ToDictionary(i => i.Index, i => i.GetNodalDisplacement());

            //Dictionary<int, Displacement> abqNodalDisp;

            List <object[]> disp;
            List <object[]> stresses;

            using (var str = System.IO.File.OpenRead("Case_01V2\\data1\\node-disp.rpt"))
                disp =
                    AbaqusOutputFileReader.ReadTable(str,
                                                     AbaqusOutputFileReader.ColType.String,
                                                     AbaqusOutputFileReader.ColType.Real,
                                                     AbaqusOutputFileReader.ColType.Real,
                                                     AbaqusOutputFileReader.ColType.Real,
                                                     AbaqusOutputFileReader.ColType.Real,
                                                     AbaqusOutputFileReader.ColType.Real,
                                                     AbaqusOutputFileReader.ColType.Real);

            using (var str = System.IO.File.OpenRead("Case_01V2\\data1\\element-stress.rpt"))
                stresses =
                    AbaqusOutputFileReader.ReadTable(str,
                                                     AbaqusOutputFileReader.ColType.String,
                                                     AbaqusOutputFileReader.ColType.Int,
                                                     AbaqusOutputFileReader.ColType.Real,
                                                     AbaqusOutputFileReader.ColType.Real,
                                                     AbaqusOutputFileReader.ColType.Real,
                                                     AbaqusOutputFileReader.ColType.Real,
                                                     AbaqusOutputFileReader.ColType.Real,
                                                     AbaqusOutputFileReader.ColType.Real,
                                                     AbaqusOutputFileReader.ColType.Real,
                                                     AbaqusOutputFileReader.ColType.Real);

            var strs = stresses.Select(i => new
            {
                Label   = (string)i[0],
                IntPt   = (int)i[1],
                S11Loc1 = (double)i[2],
                S11Loc2 = (double)i[3],
                S22Loc1 = (double)i[4],
                S22Loc2 = (double)i[5],
                S33Loc1 = (double)i[6],
                S33Loc2 = (double)i[7],
                S12Loc1 = (double)i[8],
                S12Loc2 = (double)i[9],
            }).ToArray();

            var disps = disp.Select(i => new
            {
                Label        = (string)i[0],
                Displacement = new Displacement((double)i[1], (double)i[2], (double)i[3], (double)i[4], (double)i[5], (double)i[6])
            }).ToArray();

            var strss = strs.Select(i => new
            {
                Label = i.Label,
                ptr   = i.IntPt,
                st    = new CauchyStressTensor(i.S11Loc1, i.S22Loc1, i.S33Loc1)
                {
                    S12 = -i.S12Loc1, S21 = -i.S12Loc1
                },                                                                                                  //top stress
                sb = new CauchyStressTensor(i.S11Loc2, i.S22Loc2, i.S33Loc2)
                {
                    S12 = -i.S12Loc2, S21 = -i.S12Loc2
                },                                                                                                  //bot stress
                sm = new CauchyStressTensor(0.5 * i.S11Loc2 + 0.5 * i.S11Loc1, 0.5 * i.S22Loc2 + 0.5 * i.S22Loc1, 0.5 * i.S33Loc2 + 0.5 * i.S33Loc1)
                {
                    S12 = -0.5 * i.S12Loc2 + -0.5 * i.S12Loc1, S21 = -0.5 * i.S12Loc2 + -0.5 * i.S12Loc1
                },                                                                                                                                                                                                                            //mid stress
            }).ToArray();


            var maxAbsErr = Vector.Zero;

            var nodalErrs = new List <double>();
            var elmErrs   = new List <double>();

            var mids = new int[] { 42, 57, 58, 59, 60, 61, 62, 63, 34 };
            var sup  = new int[] { 6, 11, 3, 34, 7, 2, 10 };
            var rest = Enumerable.Range(1, 63).Where(i => !mids.Contains(i) && !sup.Contains(i)).ToArray();

            var abqNodalDisp = disps.ToDictionary(i => i.Label, i => i.Displacement);


            foreach (var key in bfeNodalDisp.Keys)
            {
                var test_bfe = bfeNodalDisp[key];
                var ref_abq  = abqNodalDisp[(key + 1).ToString()];

                if (mids.Contains(key + 1) && !sup.Contains(key + 1))
                {
                    test_bfe.DY = ref_abq.DY;
                    Guid.NewGuid();
                }


                if (key == 60)
                {
                    Guid.NewGuid();
                }

                var d = ref_abq - test_bfe;

                var du = d.Displacements;
                var dr = d.Rotations;

                var ru = du.Length / ref_abq.Displacements.Length;
                var rr = dr.Length / ref_abq.Rotations.Length;

                if (d.Displacements.Length > maxAbsErr.Length)
                {
                    maxAbsErr = d.Displacements;
                }

                nodalErrs.Add(ru);

                var r1 = test_bfe.DX / ref_abq.DX;
                var r2 = test_bfe.DY / ref_abq.DY;
                var r3 = test_bfe.DZ / ref_abq.DZ;
            }


            foreach (var key in bfeNodalDisp.Keys)
            {
                var test_bfe = bfeNodalDisp[key];
                var ref_abq  = abqNodalDisp[(key + 1).ToString()];

                var nde = model.Nodes[key];

                //nde.SetNodalDisplacement(LoadCase.DefaultLoadCase, ref_abq);
            }

            //errs.Sort();


            var midErrs = mids.Select(i => nodalErrs[i - 1]).ToArray();
            var supErrs = sup.Select(i => nodalErrs[i - 1]).ToArray();
            var restErr = rest.Select(i => nodalErrs[i - 1]).ToArray();

            var restMax = restErr.Max();



            //var elm2 = model.Elements[64];


            var p1t = new double[] { 1 / 6.0, 1 / 6.0, 1 };
            var p1m = new double[] { 1 / 6.0, 1 / 6.0, 0 };
            var p1b = new double[] { 1 / 6.0, 1 / 6.0, -1 };

            var p2t = new double[] { 4 / 6.0, 1 / 6.0, 1 };
            var p2m = new double[] { 4 / 6.0, 1 / 6.0, 0 };
            var p2b = new double[] { 4 / 6.0, 1 / 6.0, -1 };

            var p3t = new double[] { 1 / 6.0, 4 / 6.0, 1 };
            var p3m = new double[] { 1 / 6.0, 4 / 6.0, 0 };
            var p3b = new double[] { 1 / 6.0, 4 / 6.0, -1 };


            var problems = new int[] { 82, 84, 86, 88, 90, 92, 94, 96 };
            var trs      = new Matrix(3, 3);

            trs[0, 1] = 1;
            trs[1, 0] = -1;
            trs[2, 2] = 1;



            foreach (var elm in model.Elements)
            {
                if (elm is TriangleElement tri)
                {
                    var trns = tri.GetTransformationManager();


                    var s1t = tri.GetLocalInternalStress(p1t);
                    var s1m = tri.GetLocalInternalStress(p1m);
                    var s1b = tri.GetLocalInternalStress(p1b);

                    var s2t = tri.GetLocalInternalStress(p2t);
                    var s2m = tri.GetLocalInternalStress(p2m);
                    var s2b = tri.GetLocalInternalStress(p2b);

                    var s3t = tri.GetLocalInternalStress(p3t);
                    var s3m = tri.GetLocalInternalStress(p3m);
                    var s3b = tri.GetLocalInternalStress(p3b);

                    if (tri.Label == "94")
                    {
                        Guid.NewGuid();
                    }

                    if (problems.Contains(tri.label.ToInt()))
                    {
                        s1m = CauchyStressTensor.Transform(s1m, trs);
                        s2m = CauchyStressTensor.Transform(s2m, trs);
                        s3m = CauchyStressTensor.Transform(s3m, trs);

                        s1t = CauchyStressTensor.Transform(s1t, trs);
                        s2t = CauchyStressTensor.Transform(s2t, trs);
                        s3t = CauchyStressTensor.Transform(s3t, trs);

                        s1b = CauchyStressTensor.Transform(s1b, trs);
                        s2b = CauchyStressTensor.Transform(s2b, trs);
                        s3b = CauchyStressTensor.Transform(s3b, trs);
                    }

                    var tag = tri.label;

                    var as1 = strss.FirstOrDefault(i => i.ptr == 1 && i.Label == tag);
                    var as2 = strss.FirstOrDefault(i => i.ptr == 2 && i.Label == tag);
                    var as3 = strss.FirstOrDefault(i => i.ptr == 3 && i.Label == tag);

                    var fnc = new Func <CauchyStressTensor, double[]>(i => new double[] { i.S11, i.S22, i.S33, i.S12 });

                    var e1t = ErrorUtil.GetRelativeError(as1.sb, -s1t, fnc);
                    var e1m = ErrorUtil.GetRelativeError(as1.sm, -s1m, fnc);
                    var e1b = ErrorUtil.GetRelativeError(as1.st, -s1b, fnc);

                    var e2t = ErrorUtil.GetRelativeError(as2.sb, -s2t, fnc);
                    var e2m = ErrorUtil.GetRelativeError(as2.sm, -s2m, fnc);
                    var e2b = ErrorUtil.GetRelativeError(as2.st, -s2b, fnc);

                    var e3t = ErrorUtil.GetRelativeError(as3.sb, -s3t, fnc);
                    var e3m = ErrorUtil.GetRelativeError(as3.sm, -s3m, fnc);
                    var e3b = ErrorUtil.GetRelativeError(as3.st, -s3b, fnc);

                    var eMax =
                        CalcUtil.NormInf(e1t, e1b, e2t, e2b, e3t, e3b);
                    //CalcUtil.NormInf(e1m, e2m, e3m);//max abs value

                    if (tri.Label == "51")
                    {
                        Guid.NewGuid();
                    }

                    elmErrs.Add(eMax);
                }
            }



            var maxStress = elmErrs.Max();
            var avg       = elmErrs.Average();

            var tmp = Enumerable.Range(0, elmErrs.Count).Select(i => Tuple.Create(i + 1, elmErrs[i])).OrderBy(i => - i.Item2).ToList();

            elmErrs.Sort();

            Guid.NewGuid();

            /*
             * {//nodal displacements
             *
             *  span.Add("h4").Text("Nodal Displacements");
             *  span.Add("paragraph").Text(string.Format("Validation output for nodal displacements:"));
             *
             *  var da = 1 / 0.0254 * A.GetNodalDisplacement().Displacements; // [inch]
             *  var db = 1 / 0.0254 * B.GetNodalDisplacement().Displacements; // [inch]
             *
             *  var d50 = 1 / 0.0254 * n50.GetNodalDisplacement().Displacements; // [inch]
             *  var d56 = 1 / 0.0254 * n56.GetNodalDisplacement().Displacements; // [inch]
             *  var d57 = 1 / 0.0254 * n57.GetNodalDisplacement().Displacements; // [inch]
             *
             *  var sap2000Da = new Vector(-0.014921, 0.085471, 0.146070); //tbl 7.14
             *  var sap2000Db = new Vector(-0.014834, -0.085475, -0.144533); //tbl 7.14
             *
             *  var abaqusDa = new Vector(-15.4207E-03, 88.2587E-03, 150.910E-03); //node 9
             *  var abaqusDb = new Vector(-15.3246E-03, -88.2629E-03, -148.940E-03); //node 5
             *
             *  var abaqus8 = new Vector(-120.875E-06, 88.3894E-03, -1.01662E-03); //node 8
             *  var abaqus12 = new Vector(15.3931E-03, 89.1206E-03, -149.515E-03); //node 12
             *  var abaqus41 = new Vector(-189.084E-06, 72.3778E-03, -734.918E-06); //node 41
             *
             *
             *  span.Add("paragraph").Text(string.Format("Validation output for nodal displacements:"));
             *
             *  span.Add("paragraph").Text(string.Format("Err at node A (displacement): {0:0.00}%", Util.GetErrorPercent(da, abaqusDa))).AddClosedTag("br"); ;
             *  span.Add("paragraph").Text(string.Format("Err at node B (displacement): {0:0.00}%", Util.GetErrorPercent(db, abaqusDb))).AddClosedTag("br"); ;
             *
             *  span.Add("paragraph").Text(string.Format("Err at node 41 (57) (displacement): {0:0.00}%", Util.GetErrorPercent(d50, abaqus41))).AddClosedTag("br"); ;
             *  span.Add("paragraph").Text(string.Format("Err at node 12 (56) (displacement): {0:0.00}%", Util.GetErrorPercent(d56, abaqus12))).AddClosedTag("br"); ;
             *  span.Add("paragraph").Text(string.Format("Err at node 08 (50) (displacement): {0:0.00}%", Util.GetErrorPercent(d57, abaqus8))).AddClosedTag("br"); ;
             * }
             *
             * {//element stress
             *  {
             *      var e81 = model.Elements[85] as TriangleElement;
             *
             *      var tr = e81.GetTransformationManager();
             *
             *      //t = 1/t;
             *
             *      var am = tr.TransformLocalToGlobal(e81.GetLocalInternalStress(LoadCase.DefaultLoadCase, 1 / 6.0, 1 / 6.0, 0) * (1 / t));
             *      var at = tr.TransformLocalToGlobal(e81.GetLocalInternalStress(LoadCase.DefaultLoadCase, 1 / 6.0, 1 / 6.0, +1) * (1 / t));
             *      var ab = tr.TransformLocalToGlobal(e81.GetLocalInternalStress(LoadCase.DefaultLoadCase, 1 / 6.0, 1 / 6.0, -1) * (1 / t));
             *
             *      var bm = tr.TransformLocalToGlobal(e81.GetLocalInternalStress(LoadCase.DefaultLoadCase, 4 / 6.0, 1 / 6.0, 0) * (1 / t));
             *      var bt = tr.TransformGlobalToLocal(e81.GetLocalInternalStress(LoadCase.DefaultLoadCase, 4 / 6.0, 1 / 6.0, +1) * (1 / t));
             *      var bb = tr.TransformLocalToGlobal(e81.GetLocalInternalStress(LoadCase.DefaultLoadCase, 4 / 6.0, 1 / 6.0, -1) * (1 / t));
             *
             *      var cm = tr.TransformLocalToGlobal(e81.GetLocalInternalStress(LoadCase.DefaultLoadCase, 1 / 6.0, 4 / 6.0, 0) * (1 / t));
             *      var ct = tr.TransformLocalToGlobal(e81.GetLocalInternalStress(LoadCase.DefaultLoadCase, 1 / 6.0, 4 / 6.0, +1) * (1 / t));
             *      var cb = tr.TransformLocalToGlobal(e81.GetLocalInternalStress(LoadCase.DefaultLoadCase, 1 / 6.0, 4 / 6.0, -1) * (1 / t));
             *
             *      var abacus_at = new CauchyStressTensor() { S11 = 103.814E-03, S22 = 249.185E-03, S12 = 1.03438, S21 = 1.03438 } * -1e9;
             *      var abacus_bt = new CauchyStressTensor() { S11 = -34.7168E-03, S22 = -538.942E-03, S12 = 1.03438, S21 = 1.08243 } * -1e9;
             *      var abacus_ct = new CauchyStressTensor() { S11 = -201.062E-03, S22 = -1.18348, S12 = 747.243E-03, S21 = 747.243E-03 } * -1e9;
             *
             *      var e1 = Util.GetErrorPercent(at, abacus_ct);
             *      var e2 = Util.GetErrorPercent(bt, abacus_at);
             *      var e3 = Util.GetErrorPercent(ct, abacus_bt);
             *
             *      span.Add("paragraph").Text(string.Format("Validation output for element stress:"));
             *
             *      span.Add("paragraph").Text(string.Format("Err at p1 element 81 (stress): {0:0.00}%", e1)).AddClosedTag("br");
             *      span.Add("paragraph").Text(string.Format("Err at p2 element 81 (stress): {0:0.00}%", e2)).AddClosedTag("br");
             *      span.Add("paragraph").Text(string.Format("Err at p3 element 81 (stress): {0:0.00}%", e3)).AddClosedTag("br");
             *
             *      //in abaqus e81 connected to 8-12-41
             *      //in bfe e85 connected to 57-56-50
             *  }
             *
             * }
             */
            return(val);
        }
        public ValidationResult Validate()
        {
            var val = new ValidationResult();

            //var magic = 0;

            //example #13 p175

            #region creating model

            var model = new Model();

            var l = UnitConverter.In2M(40);
            var w = UnitConverter.In2M(10);
            var h = UnitConverter.In2M(5);
            var t = UnitConverter.In2M(0.25);

            var e  = UnitConverter.Ksi2Pas(10000); //10'000 ksi
            var no = 0.3;

            var n = 9;

            var xSpan = l / (n - 1);

            var nodes = new Node[n][];

            for (var i = 0; i < n; i++)
            {
                var x = i * xSpan;

                nodes[i] = new Node[7];

                nodes[i][0] = new Node(x, 0, 0);
                nodes[i][1] = new Node(x, w / 2, 0);
                nodes[i][2] = new Node(x, w, 0);

                nodes[i][3] = new Node(x, w / 2, h / 2);

                nodes[i][4] = new Node(x, 0, h);
                nodes[i][5] = new Node(x, w / 2, h);
                nodes[i][6] = new Node(x, w, h);

                model.Nodes.AddRange(nodes[i]);
            }

            var pairs = new int[6][];

            pairs[0] = new int[] { 0, 1 };
            pairs[1] = new int[] { 1, 2 };
            pairs[2] = new int[] { 1, 3 };
            pairs[3] = new int[] { 3, 5 };
            pairs[4] = new int[] { 4, 5 };
            pairs[5] = new int[] { 5, 6 };


            var mat = new Materials.UniformIsotropicMaterial(e, no);
            var sec = new Sections.UniformParametric2DSection(t);


            for (var i = 0; i < n - 1; i++)
            {
                for (int j = 0; j < 6; j++)
                {
                    var n11 = nodes[i][pairs[j][0]];
                    var n12 = nodes[i][pairs[j][1]];

                    var n21 = nodes[i + 1][pairs[j][0]];
                    var n22 = nodes[i + 1][pairs[j][1]];

                    {
                        var elm1 = new TriangleElement()
                        {
                            Material = mat, Section = sec
                        };

                        elm1.Nodes[0] = n11;
                        elm1.Nodes[1] = n12;
                        elm1.Nodes[2] = n21;

                        model.Elements.Add(elm1);

                        var elm2 = new TriangleElement()
                        {
                            Material = mat, Section = sec
                        };

                        elm2.Nodes[0] = n21;
                        elm2.Nodes[1] = n22;
                        elm2.Nodes[2] = n12;

                        model.Elements.Add(elm2);
                    }
                }
            }

            //loading
            nodes.Last()[0].Loads.Add(new NodalLoad(new Force(0, UnitConverter.Kip2N(1.6), 0, 0, 0, 0)));
            nodes.Last()[6].Loads.Add(new NodalLoad(new Force(0, -UnitConverter.Kip2N(1.6), 0, 0, 0, 0)));

            nodes[0].ToList().ForEach(i => i.Constraints = Constraints.Fixed);

            #endregion

            model.Trace.Listeners.Add(new BriefFiniteElementNet.Common.ConsoleTraceListener());
            new ModelWarningChecker().CheckModel(model);



            model.Solve();

            var A = nodes.Last()[2];
            var B = nodes.Last()[4];
            var C = nodes.First()[1];
            var D = nodes.First()[0];
            var E = nodes.Last()[6];

            /*
             * for (int i = 0; i < nodes.Last().Length; i++)
             * {
             *  nodes.Last()[i].Label = i.ToString();
             * }
             */

            /**/
            A.Label = "A";
            B.Label = "B";
            C.Label = "C";
            D.Label = "D";
            E.Label = "E";
            /**/


            var n50 = model.Nodes[50];
            var n56 = model.Nodes[56];
            var n57 = model.Nodes[57];



            val.Title = "I Beam torsion with triangle element";

            var da = 1 / 0.0254 * A.GetNodalDisplacement().Displacements;        // [inch]
            var db = 1 / 0.0254 * B.GetNodalDisplacement().Displacements;        // [inch]

            var d50 = 1 / 0.0254 * n50.GetNodalDisplacement().Displacements;     // [inch]
            var d56 = 1 / 0.0254 * n56.GetNodalDisplacement().Displacements;     // [inch]
            var d57 = 1 / 0.0254 * n57.GetNodalDisplacement().Displacements;     // [inch]

            var sap2000Da = new Vector(-0.014921, 0.085471, 0.146070);           //tbl 7.14
            var sap2000Db = new Vector(-0.014834, -0.085475, -0.144533);         //tbl 7.14

            var abaqusDa = new Vector(-15.4207E-03, 88.2587E-03, 150.910E-03);   //node 9
            var abaqusDb = new Vector(-15.3246E-03, -88.2629E-03, -148.940E-03); //node 5

            var abaqus8  = new Vector(-120.875E-06, 88.3894E-03, -1.01662E-03);  //node 8
            var abaqus12 = new Vector(15.3931E-03, 89.1206E-03, -149.515E-03);   //node 12
            var abaqus41 = new Vector(-189.084E-06, 72.3778E-03, -734.918E-06);  //node 41

            Console.WriteLine("Err at A against abaqus (displacement): {0:0.00}%", GetError(da, abaqusDa));
            Console.WriteLine("Err at B against abaqus (displacement): {0:0.00}%", GetError(db, abaqusDb));

            Console.WriteLine("Err at 41 (57) against abaqus (displacement): {0:0.00}%", GetError(d50, abaqus41));
            Console.WriteLine("Err at 12 (56) against abaqus (displacement): {0:0.00}%", GetError(d56, abaqus12));
            Console.WriteLine("Err at 08 (50) against abaqus (displacement): {0:0.00}%", GetError(d57, abaqus8));


            model.ReIndexElements();
            model.ReIndexNodes();

            //ModelVisualizerControl.VisualizeInNewWindow(model);

            {
                var e81 = model.Elements[85] as TriangleElement;


                var tr = e81.GetTransformationManager();

                //t = 1/t;

                var am = tr.TransformLocalToGlobal(e81.GetLocalInternalStress(LoadCase.DefaultLoadCase, 1 / 6.0, 1 / 6.0, 0) * (1 / t));
                var at = tr.TransformLocalToGlobal(e81.GetLocalInternalStress(LoadCase.DefaultLoadCase, 1 / 6.0, 1 / 6.0, +1) * (1 / t));
                var ab = tr.TransformLocalToGlobal(e81.GetLocalInternalStress(LoadCase.DefaultLoadCase, 1 / 6.0, 1 / 6.0, -1) * (1 / t));

                var bm = tr.TransformLocalToGlobal(e81.GetLocalInternalStress(LoadCase.DefaultLoadCase, 4 / 6.0, 1 / 6.0, 0) * (1 / t));
                var bt = tr.TransformLocalToGlobal(e81.GetLocalInternalStress(LoadCase.DefaultLoadCase, 4 / 6.0, 1 / 6.0, +1) * (1 / t));
                var bb = tr.TransformLocalToGlobal(e81.GetLocalInternalStress(LoadCase.DefaultLoadCase, 4 / 6.0, 1 / 6.0, -1) * (1 / t));

                var cm = tr.TransformLocalToGlobal(e81.GetLocalInternalStress(LoadCase.DefaultLoadCase, 1 / 6.0, 4 / 6.0, 0) * (1 / t));
                var ct = tr.TransformLocalToGlobal(e81.GetLocalInternalStress(LoadCase.DefaultLoadCase, 1 / 6.0, 4 / 6.0, +1) * (1 / t));
                var cb = tr.TransformLocalToGlobal(e81.GetLocalInternalStress(LoadCase.DefaultLoadCase, 1 / 6.0, 4 / 6.0, -1) * (1 / t));

                var abacus_at = new CauchyStressTensor()
                {
                    S11 = 103.814E-03, S22 = 249.185E-03, S12 = 1.03438, S21 = 1.03438
                } *-1e9;
                var abacus_bt = new CauchyStressTensor()
                {
                    S11 = -34.7168E-03, S22 = -538.942E-03, S12 = 1.03438, S21 = 1.08243
                } *-1e9;
                var abacus_ct = new CauchyStressTensor()
                {
                    S11 = -201.062E-03, S22 = -1.18348, S12 = 747.243E-03, S21 = 747.243E-03
                } *-1e9;

                var e1 = GetError(at, abacus_ct);
                var e2 = GetError(bt, abacus_at);
                var e3 = GetError(ct, abacus_bt);

                Console.WriteLine("Err at p1 element 81 (stress): {0:0.00}%", e1);
                Console.WriteLine("Err at p2 element 81 (stress): {0:0.00}%", e2);
                Console.WriteLine("Err at p3 element 81 (stress): {0:0.00}%", e3);

                //in abaqus e81 connected to 8-12-41
                //in bfe e85 connected to 57-56-50
            }

            for (int i = 0; i < model.Elements.Count; i++)
            {
                model.Elements[i].Label = i.ToString();
            }

            throw new NotImplementedException();
        }
        public ValidationResult Validate()
        {
            var val = new ValidationResult();

            //var magic = 0;

            //example #13 p175

            #region creating model

            var model = new Model();

            var l = UnitConverter.In2M(40);
            var w = UnitConverter.In2M(10);
            var h = UnitConverter.In2M(5);
            var t = UnitConverter.In2M(0.25);

            var e  = UnitConverter.Ksi2Pas(10000); //10'000 ksi
            var no = 0.3;

            var n = 9;

            var xSpan = l / (n - 1);

            var nodes = new Node[n][];

            for (var i = 0; i < n; i++)
            {
                var x = i * xSpan;

                nodes[i] = new Node[7];

                nodes[i][0] = new Node(x, 0, 0);
                nodes[i][1] = new Node(x, w / 2, 0);
                nodes[i][2] = new Node(x, w, 0);

                nodes[i][3] = new Node(x, w / 2, h / 2);

                nodes[i][4] = new Node(x, 0, h);
                nodes[i][5] = new Node(x, w / 2, h);
                nodes[i][6] = new Node(x, w, h);

                model.Nodes.AddRange(nodes[i]);
            }

            var pairs = new int[6][];

            pairs[0] = new int[] { 0, 1 };
            pairs[1] = new int[] { 1, 2 };
            pairs[2] = new int[] { 1, 3 };
            pairs[3] = new int[] { 3, 5 };
            pairs[4] = new int[] { 4, 5 };
            pairs[5] = new int[] { 5, 6 };


            var mat = new Materials.UniformIsotropicMaterial(e, no);
            var sec = new Sections.UniformParametric2DSection(t);


            for (var i = 0; i < n - 1; i++)
            {
                for (int j = 0; j < 6; j++)
                {
                    var n11 = nodes[i][pairs[j][0]];
                    var n12 = nodes[i][pairs[j][1]];

                    var n21 = nodes[i + 1][pairs[j][0]];
                    var n22 = nodes[i + 1][pairs[j][1]];

                    {
                        var elm1 = new TriangleElement()
                        {
                            Material = mat, Section = sec
                        };

                        elm1.Nodes[0] = n11;
                        elm1.Nodes[1] = n12;
                        elm1.Nodes[2] = n21;

                        model.Elements.Add(elm1);

                        var elm2 = new TriangleElement()
                        {
                            Material = mat, Section = sec
                        };

                        elm2.Nodes[0] = n21;
                        elm2.Nodes[1] = n22;
                        elm2.Nodes[2] = n12;

                        model.Elements.Add(elm2);
                    }
                }
            }

            //loading
            nodes.Last()[0].Loads.Add(new NodalLoad(new Force(0, UnitConverter.Kip2N(1.6), 0, 0, 0, 0)));
            nodes.Last()[6].Loads.Add(new NodalLoad(new Force(0, -UnitConverter.Kip2N(1.6), 0, 0, 0, 0)));

            nodes[0].ToList().ForEach(i => i.Constraints = Constraints.Fixed);

            #endregion

            model.Trace.Listeners.Add(new BriefFiniteElementNet.Common.ConsoleTraceListener());
            new ModelWarningChecker().CheckModel(model);


            //ModelVisualizerControl.VisualizeInNewWindow(model);

            model.Solve();

            var A = nodes.Last()[2];
            var B = nodes.Last()[4];
            var C = nodes.First()[1];
            var D = nodes.First()[0];
            var E = nodes.Last()[6];

            /*
             * for (int i = 0; i < nodes.Last().Length; i++)
             * {
             *  nodes.Last()[i].Label = i.ToString();
             * }
             */

            /**/
            A.Label = "A";
            B.Label = "B";
            C.Label = "C";
            D.Label = "D";
            E.Label = "E";
            /**/


            val.Title = "I Beam torsion with triangle element";

            var da = 1 / 0.0254 * A.GetNodalDisplacement().Displacements;        // [inch]
            var db = 1 / 0.0254 * B.GetNodalDisplacement().Displacements;        // [inch]

            var sap2000Da = new Vector(-0.014921, 0.085471, 0.146070);           //tbl 7.14
            var sap2000Db = new Vector(-0.014834, -0.085475, -0.144533);         //tbl 7.14

            var abaqusDa = new Vector(-15.4207E-03, 88.2587E-03, 150.910E-03);   //node 9
            var abaqusDb = new Vector(-15.3246E-03, -88.2629E-03, -148.940E-03); //node 5

            Console.WriteLine("Err at A against abaqus (displacement): {0:0.00}%", GetError(da, abaqusDa));
            Console.WriteLine("Err at B against abaqus (displacement): {0:0.00}%", GetError(db, abaqusDb));


            {
                var e81 = model.Elements[85] as TriangleElement;

                var stress = e81.GetLocalInternalStress(LoadCase.DefaultLoadCase, 1 / 6.0, 1 / 6.0, 0);
            }

            for (int i = 0; i < model.Elements.Count; i++)
            {
                model.Elements[i].Label = i.ToString();
            }

            throw new NotImplementedException();
        }