Ejemplo n.º 1
0
        public void ModelMassSIUnits()
        {
            var k3d           = new Toolkit();
            var gamma         = 1.0; // (kN/m3)
            var unit_material = new FemMaterial_Isotrop("unit", "unit", 1, 0.5, 0.5, gamma, 1.0, -1.0, FemMaterial.FlowHypothesis.mises, 1.0, null);
            var b             = 100; // (cm)
            var t             = 50;  // (cm)
            var unit_crosec   = k3d.CroSec.Box(b, b, b, t, t, t, 0, 0, unit_material);

            var elems = new List <BuilderBeam>()
            {
                k3d.Part.IndexToBeam(0, 1, "A", unit_crosec),
            };

            var L      = 1.0; // in m
            var points = new List <Point3> {
                new Point3(), new Point3(L, 0, 0)
            };

            var model = k3d.Model.AssembleModel(elems, null, null, out var info, out var mass, out var cog, out var msg,
                                                out var runtimeWarning, new List <Joint>(), points);

            var ucf = UnitsConversionFactory.Conv();

            mass = ucf.kg().toUnit(mass);

            Assert.AreEqual(mass, 100, 1e-10);
        }
Ejemplo n.º 2
0
        /// <summary>
        ///
        /// The main program executes the tests. Output may be routed to
        /// various locations, depending on the arguments passed.
        /// </summary>
        /// <remarks>Run with --help for a full list of arguments supported</remarks>
        /// <param name="args"></param>
        public static int Main(string[] args)
        {
            // set the system of physical units to SI
            INIReader.ClearSingleton();
            UnitsConversionFactory.ClearSingleton();

            var ini = INIReader.Instance();

            ini.Values["UnitsSystem"] = "SI";
            ini.Values["gravity"]     = "10.0";

            // run the tests
            var res = new AutoRun().Execute(args);

            Console.WriteLine("Press any key to close");
            Console.ReadKey();
            return(res);
        }
Ejemplo n.º 3
0
        public void ModelMassImperialUnits()
        {
            // make temporary changes to the the ini-file and units-conversion
            INIReader.ClearSingleton();
            UnitsConversionFactory.ClearSingleton();

            var ini = INIReader.Instance();

            ini.Values["UnitsSystem"] = "imperial";
            ini.Values["gravity"]     = "9.80665";

            var k3d   = new Toolkit();
            var gamma = 1.0; // (kip/ft3)

            var unit_material = new FemMaterial_Isotrop("unit", "unit", 1, 0.5, 0.5, gamma, 1.0, -1.0, FemMaterial.FlowHypothesis.mises, 1.0, null);
            var b             = 12; // (inch)
            var t             = 6;  // (inch)
            var unit_crosec   = k3d.CroSec.Box(b, b, b, t, t, t, 0, 0, unit_material);

            var elems = new List <BuilderBeam>()
            {
                k3d.Part.IndexToBeam(0, 1, "A", unit_crosec),
            };

            var L      = 1.0; // in feet
            var points = new List <Point3> {
                new Point3(), new Point3(L, 0, 0)
            };

            var model = k3d.Model.AssembleModel(elems, null, null, out var info, out var mass, out var cog, out var msg,
                                                out var runtimeWarning, new List <Joint>(), points);

            // clear temporary changes to the the ini-file and units-conversion
            INIReader.ClearSingleton();
            UnitsConversionFactory.ClearSingleton();
            ini = INIReader.Instance();
            // switch back to SI units
            ini.Values["UnitsSystem"] = "SI";

            Assert.AreEqual(mass, 1000, 1e-10);
        }
Ejemplo n.º 4
0
        public void ImperialUnits()
        {
            var k3d    = new Toolkit();
            var logger = new MessageLogger();

            // make temporary changes to the the ini-file and units-conversion
            INIReader.ClearSingleton();
            UnitsConversionFactory.ClearSingleton();

            var ini = INIReader.Instance();

            ini.Values["UnitsSystem"] = "imperial";

            var resourcePath = @"";

            // get a cross section from the cross section table in the folder 'Resources'
            var         crosecPath     = Path.Combine(resourcePath, "CrossSections/CrossSectionValues.bin");
            CroSecTable inCroSecs      = k3d.CroSec.ReadCrossSectionTable(crosecPath, out var info);
            var         crosec_family  = inCroSecs.crosecs.FindAll(x => x.family == "W");
            var         crosec_initial = crosec_family.Find(x => x.name == "W12X26");

            // clear temporary changes to the the ini-file and units-conversion
            INIReader.ClearSingleton();
            UnitsConversionFactory.ClearSingleton();

            var cs = crosec_initial as CroSec_I;

            var m2feet      = 3.28084;
            var height_feet = 0.31 * m2feet;
            var width_feet  = 0.165 * m2feet;

            Assert.AreEqual(cs._height, height_feet, 1e-5);
            Assert.AreEqual(cs.lf_width, width_feet, 1e-5);

            var feet42inch4 = Math.Pow(12.0, 4);
            var cm42inch4   = Math.Pow(1.0 / 2.54, 4);
            var Iyy_inch1   = 8491.12 * cm42inch4;
            var Iyy_inch2   = cs.Iyy * feet42inch4;

            Assert.AreEqual(Iyy_inch1, Iyy_inch2, 1e-1);
        }
Ejemplo n.º 5
0
        public void MeshLoadProfiling()
        {
            var k3d = new Toolkit();

            int    nBeams      = 20;
            int    nFaces      = 1500;
            double lengthBeams = 10.0;
            double xIncBeam    = lengthBeams / nBeams;
            double xIncMesh    = lengthBeams / nFaces;
            double limit_dist  = xIncBeam / 100.0;

            // create beams
            var lines = new List <Line3>();
            var nodeI = new Point3(0, 0, 0);

            for (int beamInd = 0; beamInd < nBeams; ++beamInd)
            {
                var nodeK = new Point3(nodeI.X + xIncBeam, 0, 0);
                lines.Add(new Line3(nodeI, nodeK));
                nodeI = nodeK;
            }
            LineToBeam.solve(new List <Point3>(), lines, true, true, limit_dist, new List <Vector3>(), new List <string>(),
                             new List <Color>(), new List <CroSec>(), true,
                             out List <Point3> outPoints, out List <BuilderBeam> builderElements, out string info);

            // create a MeshLoad
            var meshUnitLoadsBuffer = new Dictionary <MeshUnitLoad, MeshUnitLoad>();
            var mesh = new Mesh();

            mesh.Vertices.Add(new Point3d(0, -0.5, 0));
            mesh.Vertices.Add(new Point3d(0, 0.5, 0));
            for (var faceInd = 0; faceInd < nFaces; ++faceInd)
            {
                mesh.Vertices.Add(new Point3d((faceInd + 1) * xIncMesh, -0.5, 0));
                mesh.Vertices.Add(new Point3d((faceInd + 1) * xIncMesh, 0.5, 0));
                var nV = mesh.Vertices.Count;
                mesh.Faces.AddFace(new MeshFace(nV - 4, nV - 3, nV - 1, nV - 2));
            }
            UnitsConversionFactory ucf = UnitsConversionFactories.Conv();
            UnitConversion         m   = ucf.m();
            var baseMesh = m.toBaseMesh(new RhinoMesh(mesh));

            var load = new MeshLoad(new List <Vector3>()
            {
                new Vector3(0, 0, -1)
            });

            load.InitUnitLoads(meshUnitLoadsBuffer, baseMesh, LoadOrientation.global, new List <bool>()
            {
                true, true
            },
                               new List <Point3>(), new List <string>());

            // create a Support
            var support = k3d.Support.Support(new Point3(0, 0, 0), k3d.Support.SupportFixedConditions);

            // assemble the model
            var model = k3d.Model.AssembleModel(builderElements, new List <Support>()
            {
                support
            }, new List <Load>()
            {
                load
            },
                                                out info, out var mass, out var cog, out var msg, out var runtimeWarning);

            ThIAnalyze.solve(model, out var outMaxDisp, out var outG, out var outComp, out var warning, out model);

            Assert.AreEqual(outMaxDisp[0], 2.8232103119331837, 1E-5);
            // Assert.AreEqual(1, 1, 1E-8);
        }
Ejemplo n.º 6
0
        public void CantileverEigenfrequency()
        {
            // make temporary changes to the the ini-file and units-conversion
            INIReader.ClearSingleton();
            UnitsConversionFactory.ClearSingleton();

            var ini = INIReader.Instance();

            ini.Values["UnitsSystem"] = "imperial";
            ini.Values["gravity"]     = "9.80665";

            var k3d           = new Toolkit();
            var E             = 70000; // (kip/ft2) == 486111.1 (psi)
            var gamma         = 1.0;   // (kip/ft3)
            var unit_material = new FemMaterial_Isotrop("unit", "unit", E, 0.5 * E, 0.5 * E, gamma, 1.0, -1.0, FemMaterial.FlowHypothesis.mises, 1.0, null);
            var b             = 6;     // (inch)
            var t             = 3;     // (inch)
                                       // Iy = 108 inch^4
                                       // g = 20.833 lb/inch
            var unit_crosec = k3d.CroSec.Box(b, b, b, t, t, t, 0, 0, unit_material);

            var elems = new List <BuilderBeam>()
            {
                k3d.Part.IndexToBeam(0, 1, "A", unit_crosec),
            };

            var L      = 10.0; // in feet
            var points = new List <Point3> {
                new Point3(), new Point3(L, 0, 0)
            };

            var supports = new List <Support> {
                k3d.Support.Support(0, k3d.Support.SupportFixedConditions)
            };

            var model = k3d.Model.AssembleModel(elems, supports, null, out var info, out var mass, out var cog, out var msg,
                                                out var runtimeWarning, new List <Joint>(), points);

            // calculate the natural vibrations
            int    from_shape_ind = 1;
            int    shapes_num     = 1;
            int    max_iter       = 100;
            double eps            = 1e-8;
            var    disp_dummy     = new List <double>();
            var    scaling        = EigenShapesScalingType.matrix;

            model = k3d.Algorithms.NaturalVibes(model, from_shape_ind, shapes_num, max_iter, eps, disp_dummy, scaling,
                                                out var nat_frequencies, out var modal_masses, out var participation_facs,
                                                out var participation_facs_disp, out model);

            // calculate the expected value of the first eigen-frequency
            // see Young, W. C., Budynas, R. G.(2002). Roark's Formulas for Stress and Strain .
            // 7nd Edition, McGraw-Hill, Chapter 16 , pp 767 - 768
            var E_          = E * 1000.0 * Math.Pow(UnitConversionCollection.inch_to_ft, 2);
            var I_          = unit_crosec.Iyy / Math.Pow(UnitConversionCollection.inch_to_ft, 4);
            var w_          = unit_crosec.A * gamma * 1000.0 * UnitConversionCollection.inch_to_ft;
            var g_          = UnitConversionCollection.g_IU / UnitConversionCollection.inch_to_ft;
            var L_          = L / UnitConversionCollection.inch_to_ft;
            var Kn          = 3.52;
            var f1_expected = Kn / 2.0 / Math.PI * Math.Sqrt(E_ * I_ * g_ / w_ / Math.Pow(L_, 4));

            Assert.AreEqual(nat_frequencies[0], f1_expected, 1e-2);

            // clear temporary changes to the the ini-file and units-conversion
            INIReader.ClearSingleton();
            UnitsConversionFactory.ClearSingleton();
            ini = INIReader.Instance();
            // switch back to SI units
            ini.Values["UnitsSystem"] = "SI";
        }
Ejemplo n.º 7
0
        public void MeshLoadProfiling()
        {
            var k3d    = new Toolkit();
            var logger = new MessageLogger();

            int    nBeams      = 20;
            int    nFaces      = 1500;
            double lengthBeams = 10.0;
            double xIncBeam    = lengthBeams / nBeams;
            double xIncMesh    = lengthBeams / nFaces;
            double limit_dist  = xIncBeam / 100.0;

            // create beams
            var lines = new List <Line3>();
            var nodeI = new Point3(0, 0, 0);

            for (int beamInd = 0; beamInd < nBeams; ++beamInd)
            {
                var nodeK = new Point3(nodeI.X + xIncBeam, 0, 0);
                lines.Add(new Line3(nodeI, nodeK));
                nodeI = nodeK;
            }

            var builderElements = k3d.Part.LineToBeam(lines, new List <string>(), new List <CroSec>(), logger, out List <Point3> outPoints);

            // create a MeshLoad
            var mesh = new Mesh3((nFaces + 1) * 2, nFaces);

            mesh.AddVertex(new Point3(0, -0.5, 0));
            mesh.AddVertex(new Point3(0, 0.5, 0));
            for (var faceInd = 0; faceInd < nFaces; ++faceInd)
            {
                mesh.AddVertex(new Point3((faceInd + 1) * xIncMesh, -0.5, 0));
                mesh.AddVertex(new Point3((faceInd + 1) * xIncMesh, 0.5, 0));
                var nV = mesh.Vertices.Count;
                mesh.AddFace(nV - 4, nV - 3, nV - 1, nV - 2);
            }
            UnitsConversionFactory ucf = UnitsConversionFactory.Conv();
            UnitConversion         m   = ucf.m();
            var baseMesh = m.toBaseMesh(mesh);

            // create a mesh load
            var load = k3d.Load.MeshLoad(new List <Vector3>()
            {
                new Vector3(0, 0, -1)
            }, baseMesh);

            // create a support
            var support = k3d.Support.Support(new Point3(0, 0, 0), k3d.Support.SupportFixedConditions);

            // assemble the model
            var model = k3d.Model.AssembleModel(builderElements, new List <Support>()
            {
                support
            }, new List <Load>()
            {
                load
            },
                                                out var info, out var mass, out var cog, out var message, out var runtimeWarning);

            // calculate the model
            model = k3d.Algorithms.AnalyzeThI(model, out var outMaxDisp, out var outG, out var outComp, out var warning);
            Assert.AreEqual(outMaxDisp[0], 2.8232103119228276, 1E-5);
        }
Ejemplo n.º 8
0
        public void SinglemassEigenfrequency_SI()
        {
            // make temporary changes to the the ini-file and units-conversion
            INIReader.ClearSingleton();
            UnitsConversionFactory.ClearSingleton();

            var ini = INIReader.Instance();

            ini.Values["UnitsSystem"] = "SI";
            ini.Values["UnitsSystem"] = "SI";

            var gravity = 9.81; // m/s2

            ini.Values["gravity"]    = gravity.ToString(CultureInfo.InvariantCulture);
            ini.Values["UnitLength"] = "ft";
            ini.Values["UnitForce"]  = "MN";
            ini.Values["UnitMass"]   = "t";

            var uc = UnitsConversionFactory.Conv();

            gravity = uc.gravity().toBase(); // cm/s2

            var k3d   = new Toolkit();
            var E     = uc["N/cm2"].toBase(70);
            var gamma = uc["N/cm3"].toBase(1.0);
            // input is not scaled to base units
            var unit_material = new FemMaterial_Isotrop("unit", "unit", E, 0.5 * E, 0.5 * E, gamma, 1.0, -1.0, FemMaterial.FlowHypothesis.mises, 1.0, null);

            var b = 6; // (cm)
            var t = 3; // (cm)
            // input is scaled to base units
            var unit_crosec = k3d.CroSec.Box(b, b, b, t, t, t, 0, 0, unit_material);

            var elems = new List <BuilderBeam>()
            {
                k3d.Part.IndexToBeam(0, 1, "A", unit_crosec),
            };

            elems[0].bending_stiff = false;

            var L      = uc["cm"].toBase(10.0);
            var points = new List <Point3> {
                new Point3(), new Point3(L, 0, 0)
            };

            var supports = new List <Support>
            {
                k3d.Support.Support(0, k3d.Support.SupportFixedConditions),
                k3d.Support.Support(1, new List <bool>()
                {
                    false, true, true, true, true, true
                })
            };

            var model = k3d.Model.AssembleModel(elems, supports, null, out var info, out var mass, out var cog, out var msg,
                                                out var runtimeWarning, new List <Joint>(), points);

            // calculate the natural vibrations
            int    from_shape_ind = 1;
            int    shapes_num     = 1;
            int    max_iter       = 100;
            double eps            = 1e-8;
            var    disp_dummy     = new List <double>();
            var    scaling        = EigenShapesScalingType.matrix;

            model = k3d.Algorithms.NaturalVibes(model, from_shape_ind, shapes_num, max_iter, eps, disp_dummy, scaling,
                                                out var nat_frequencies, out var modal_masses, out var participation_facs,
                                                out var participation_facs_disp, out model);

            var E_     = E;                                // N/cm2
            var A_     = unit_crosec.A;                    // cm2
            var L_     = L;                                // cm;
            var gamma_ = unit_material.gamma();            // N/cm3
            var c      = E_ * A_ / L;                      // N / m
            var m      = A_ * L_ * gamma_ / gravity * 0.5; // kg
            var omega0 = Math.Sqrt(c / m);                 // rad / sec
            var f0     = omega0 / 2.0 / Math.PI;           // 1 / sec = Hz

            Assert.AreEqual(nat_frequencies[0], f0, 1e-2);

            // clear temporary changes to the the ini-file and units-conversion
            INIReader.ClearSingleton();
            UnitsConversionFactory.ClearSingleton();
            ini = INIReader.Instance();
            // switch back to SI units
            ini.Values["UnitsSystem"] = "SI";
        }
Ejemplo n.º 9
0
        public void PointMassOnSpring_SI()
        {
            // make temporary changes to the the ini-file and units-conversion
            INIReader.ClearSingleton();
            UnitsConversionFactory.ClearSingleton();

            var ini = INIReader.Instance();

            ini.Values["UnitsSystem"] = "SI";
            ini.Values["UnitsSystem"] = "SI";

            var gravity = 9.81; // m/s2

            ini.Values["gravity"] = gravity.ToString(CultureInfo.InvariantCulture);

            ini.Values["UnitLength"] = "cm";
            ini.Values["UnitForce"]  = "N";
            ini.Values["UnitMass"]   = "t";

            var k3d = new Toolkit();

            var uc         = UnitsConversionFactory.Conv();
            var c_trans    = uc["N/cm"].toBase(50);
            var c_rot      = uc["Ncm/rad"].toBase(50);
            var unitCrosec = k3d.CroSec.Spring(new double[] { c_trans, c_trans, c_trans, c_rot, c_rot, c_rot });
            var elems      = new List <BuilderBeam>()
            {
                k3d.Part.IndexToBeam(0, 1, "A", unitCrosec),
            };

            elems[0].bending_stiff = false;

            var L      = uc["cm"].toBase(10.0);
            var points = new List <Point3> {
                new Point3(), new Point3(L, 0, 0)
            };

            var supports = new List <Support>
            {
                k3d.Support.Support(0, k3d.Support.SupportFixedConditions),
                k3d.Support.Support(1, new List <bool>()
                {
                    false, true, true, true, true, true
                })
            };

            var m          = uc["kg"].toBase(50); // kg
            var point_mass = new PointMass(1, m, 1);

            var model = k3d.Model.AssembleModel(elems, supports, new List <Load>()
            {
                point_mass
            }, out var info, out var mass, out var cog, out var msg,
                                                out var runtimeWarning, new List <Joint>(), points);

            // calculate the natural vibrations
            int    from_shape_ind = 1;
            int    shapes_num     = 1;
            int    max_iter       = 100;
            double eps            = 1e-8;
            var    disp_dummy     = new List <double>();
            var    scaling        = EigenShapesScalingType.matrix;

            model = k3d.Algorithms.NaturalVibes(model, from_shape_ind, shapes_num, max_iter, eps, disp_dummy, scaling,
                                                out var nat_frequencies, out var modal_masses, out var participation_facs,
                                                out var participation_facs_disp, out model);

            var omega0 = Math.Sqrt(c_trans / m); // rad / sec
            var f0     = omega0 / 2.0 / Math.PI; // 1 / sec = Hz

            Assert.AreEqual(nat_frequencies[0], f0, 1e-2);

            // clear temporary changes to the the ini-file and units-conversion
            INIReader.ClearSingleton();
            UnitsConversionFactory.ClearSingleton();
            ini = INIReader.Instance();
            // switch back to SI units
            ini.Values["UnitsSystem"] = "SI";
        }