示例#1
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            List <GH_Element> elements = new List <GH_Element>();
            List <GH_Support> supports = new List <GH_Support>();

            List <GH_Load> loads = new List <GH_Load>();

            int modelType = 1;

            if (!DA.GetDataList <GH_Element>(0, elements))
            {
                return;
            }

            if (!DA.GetDataList <GH_Support>(1, supports))
            {
                return;
            }

            if (!DA.GetDataList <GH_Load>(2, loads))
            {
                return;
            }

            if (!DA.GetData(3, ref modelType))
            {
                return;
            }


            //Clear current structure... Perhaps change this for a more parametric approach, or opening existing files
            GH_Model model = null;

            switch (modelType)
            {
            case 0:
                model = new GH_Model(ModelType.Truss2D, elements, loads, supports);
                break;

            case 1:
                model = new GH_Model(ModelType.Full3D, elements, loads, supports);
                break;

            case 2:
                model = new GH_Model(ModelType.Membrane3D, elements, loads, supports);
                break;

            default:
                throw new Exception("Model type does not exist or not yet implemented");
            }

            model.AssembleSharpModel();

            DA.SetData(0, model);
        }
        public void Truss()
        {
            model = new GH_Model(ModelType.Full3D);

            GH_CrossSection crossSection = new GH_RectangularCrossSection(100, 100);
            GH_Material     material     = new GH_ElasticMaterial(100, 100, 100, 100);


            Point3d p1 = new Point3d(-10, 0, 0);
            Point3d p2 = new Point3d(0, 0, 0);
            Point3d p3 = new Point3d(10, 0, 0);
            Point3d p4 = new Point3d(-10, 0, 10);
            Point3d p5 = new Point3d(0, 0, 10);
            Point3d p6 = new Point3d(10, 0, 10);



            model.Elements.Add(new GH_Beam(p1, p2, crossSection, material));
            model.Elements.Add(new GH_Beam(p2, p3, crossSection, material));
            model.Elements.Add(new GH_Beam(p4, p5, crossSection, material));
            model.Elements.Add(new GH_Beam(p5, p6, crossSection, material));
            model.Elements.Add(new GH_Beam(p1, p4, crossSection, material));
            model.Elements.Add(new GH_Beam(p2, p5, crossSection, material));
            model.Elements.Add(new GH_Beam(p3, p6, crossSection, material));
            model.Elements.Add(new GH_Beam(p4, p2, crossSection, material));
            model.Elements.Add(new GH_Beam(p2, p6, crossSection, material));
            model.Supports.Add(new GH_NodeSupport(p1, true, true, true, true, true, true));
            model.Supports.Add(new GH_NodeSupport(p3, true, true, true, true, true, true));
            model.Loads.Add(new GH_NodalLoad(p5, new Vector3d(0, 0, -1000), new Vector3d(0, 0, 0)));

            model.AssembleSharpModel();


            Assert.AreEqual(9, model.Model.ElementCount);

            model.Solve();


            Assert.NotNull(model.Results);



            Vector3d displacement = model.GetNodeDisplacement(1);                             //Displacement at point2 (index 1)

            Assert.NotNull(displacement);
            Assert.AreEqual(0.0, displacement.X, 0.001);
            Assert.AreEqual(0.0, displacement.Y, 0.001);
            Assert.AreNotEqual(0.0, displacement.Z);             //TODO Calculate real value
        }