Example #1
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);
        }
Example #2
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);
        }
Example #3
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);
        }
Example #4
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";
        }
Example #5
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";
        }
Example #6
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";
        }