コード例 #1
0
ファイル: Mass_tests.cs プロジェクト: karamba3d/K3D_tests
        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);
        }
コード例 #2
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";
        }
コード例 #3
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);
        }
コード例 #4
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";
        }