Exemple #1
0
        public static void ImportModel(List <int[]> elements, Dictionary <int, double[]> points)

        {
            int ret;

            SAP2000v19.cOAPI   SAPObject = null;
            SAP2000v19.cHelper myHelper  = new SAP2000v19.Helper();

            SAPObject = myHelper.GetObject("CSI.SAP2000.API.SapObject");

            //Get a reference to cSapModel to access all OAPI classes and functions
            SAP2000v19.cSapModel SapModel = SAPObject.SapModel;
            int contadorFrame             = 1;
            int contadorShell             = 1;

            foreach (int[] element in elements)
            {
                double[] firstNode  = points[element[0]];
                double[] secondNode = points[element[1]];

                if (element.Length == 2) // LINE
                {
                    string nameFrame = $"Frame-{contadorFrame++}";
                    ret = SapModel.FrameObj.AddByCoord(firstNode[0], firstNode[1], firstNode[2], secondNode[0], secondNode[1], secondNode[2], ref nameFrame);
                }
                else
                {
                    double[] thirdNode = points[element[2]];
                    double[] xCoords   = new double[element.Length];
                    double[] yCoords   = new double[element.Length];
                    double[] zCoords   = new double[element.Length];

                    for (int i = 0; i < element.Length; i++)
                    {
                        xCoords[i] = points[element[i]][0];
                        yCoords[i] = points[element[i]][1];
                        zCoords[i] = points[element[i]][2];
                    }
                    string nameShell = $"Shell-{contadorShell++}";
                    ret = SapModel.AreaObj.AddByCoord(element.Length, ref xCoords, ref yCoords, ref zCoords, ref nameShell);
                }
            }

            SapModel.View.RefreshView();
        }
Exemple #2
0
        //MAIN METHOD
        static void Main(string[] args)
        {
            //DATA defined by the user
            string loadcase    = "load1"; //the procedure works only for one loadcase.
            double xmin        = 0.0;
            double xmax        = 2.5;
            double ymin        = 0.0;
            double ymax        = 0.3;
            double zmin        = 0.0;
            double zmax        = 1.0;
            int    nlx         = 25;
            int    nly         = 3;
            int    nlz         = 10;
            double rmin        = Math.Sqrt(3); //the filter works for rmin <= Math.Sqrt(3)! For bigger filter check method CreateMapDist and especially the declaration of Map and Dist
            double arx         = 0.4;          //volume %
            int    fixedepanal = 150;          //maximum iterations

            //INITIALIZATION
            cHelper myHelper = new Helper();

            //mySapObject = myHelper.CreateObject(pathToEXE);//get Sap2000 object
            SAP2000v19.cOAPI     Object = null;
            SAP2000v19.cSapModel Model;
            //Object = new SAP2000v19.SapObject();
            Object = myHelper.CreateObject("C:\\Program Files\\Computers and Structures\\SAP2000 19\\SAP2000.exe"); //get Sap2000 object
            Object.ApplicationStart(SAP2000v19.eUnits.kN_m_C, true, "c:\\_SDB\\_TOCPexamples\\testexample1.sdb");   //CHANGE PATH!
            Model = Object.SapModel;
            int  ret;
            int  i;
            bool testbool = true;

            //Create Materials and Solid properties
            Program P = new Program();

            P.CreateMatSolid(ref Model, "Europe", "EN 1992-1-1 per EN 206-1", "C30/37");

            //Read SAP Model
            string[] PointName;
            int      PointNumb;

            string[] SolidName;
            int      SolidNumb;

            string[] FrameName;
            int      FrameNumb;

            string[] AreaName;
            int      AreaNumb;

            string[] LoadName;
            int      LoadNumb;

            P.ReadModel(ref Model, out PointName, out PointNumb, out SolidName, out SolidNumb, out FrameName, out FrameNumb, out AreaName, out AreaNumb, out LoadName, out LoadNumb);

            //DivideSolid
            int    arstoix;
            double diakr;
            string SolidNot;

            P.DivideSolid(ref Model, ref testbool, xmin, xmax, ymin, ymax, zmin, zmax, nlx, nly, nlz, out SolidNot, out arstoix, out diakr);

            //Create Array OptiSolidName
            int OptiSolidNumb;

            string[] OptiSolidName;
            P.CreateOptiSolidName(ref Model, ref testbool, arstoix, xmin, xmax, ymin, ymax, zmin, zmax, diakr, out OptiSolidNumb, out OptiSolidName);

            //Create Arrays Map and Dist
            int[,] Map;
            double[,] Dist;
            P.CreateMapDist(ref Model, OptiSolidNumb, nlx, nly, nlz, diakr, rmin, out Map, out Dist);

            //declaration of x
            double[] xkm2;
            xkm2 = new double[OptiSolidNumb];
            double[] xkm1;
            xkm1 = new double[OptiSolidNumb];
            double[] xk;
            xk = new double[OptiSolidNumb];
            double[] xkfil;
            xkfil = new double[OptiSolidNumb];
            double[] xnew;
            xnew = new double[OptiSolidNumb];
            double[] xnewfil;
            xnewfil = new double[OptiSolidNumb];
            //declaration of der
            double[] der;
            der = new double[OptiSolidNumb];
            double[] derfil;
            derfil = new double[OptiSolidNumb];
            double V = 0.0;

            for (i = 0; i <= OptiSolidNumb - 1; i++)
            {
                xkfil[i] = arx;
                xk[i]    = arx;
                V        = V + xkfil[i];
            }

            //rest of declarations
            double max;
            double comp;
            double comp2;

            //START OF ITERATIVE PROCCESS
            int  epanal  = 0;
            bool testpro = false;

            do
            {
                epanal = epanal + 1;
                Console.WriteLine("\n\n{0} iteration", epanal);

                //update montel based on array xkfil
                P.UpdateModel(ref Model, OptiSolidName, OptiSolidNumb, xkfil);

                //Set Run Case Flag
                ret = Model.Analyze.SetRunCaseFlag(loadcase, true, false);
                for (i = 0; i <= LoadNumb - 1; i++)
                {
                    if (LoadName[i] != loadcase)
                    {
                        ret = Model.Analyze.SetRunCaseFlag(LoadName[i], false, false);
                    }
                }

                //Run Analysis
                ret = Model.Analyze.RunAnalysis();

                //option for results
                ret = Model.Results.Setup.DeselectAllCasesAndCombosForOutput();
                ret = Model.Results.Setup.SetCaseSelectedForOutput(loadcase);

                if ((FrameNumb != 0) || (AreaNumb != 0) || (SolidNumb != OptiSolidNumb))
                {
                    //Calculate Compliance
                    comp = P.CalcCompliance(ref Model, ref testbool, SolidName, SolidNot, SolidNumb, FrameName, FrameNumb, AreaName, AreaNumb);
                }

                //Calculate Derivatives
                P.CalcDerivative(ref Model, ref testbool, OptiSolidName, OptiSolidNumb, xkfil, out der, out comp2);

                //Filter Derivatives
                derfil = P.FilterDer(ref testbool, OptiSolidNumb, Map, Dist, xkfil, der);

                //Optimality Criteria
                P.OptimalityCriteria(OptiSolidNumb, xk, derfil, Map, Dist, V, out xnew, out xnewfil);

                //FindMax and testpro
                P.TestProcedure(ref testpro, OptiSolidNumb, epanal, fixedepanal, xk, xnew, out max);


                Console.WriteLine("the Compliance of all solid elements that are being optimized is: {0}", comp2);
                Console.WriteLine("no error in the procedure: {0}", testbool);
                Console.WriteLine("max is {0}", max);
                Console.WriteLine("end of an iteration");

                for (i = 0; i <= OptiSolidNumb - 1; i++)
                {
                    xk[i]    = xnew[i];
                    xkfil[i] = xnewfil[i];
                }
            } while (testpro == false);//END OF ITERATIVE PROCCESS

            //Delete Solids
            P.DeleteSolid(ref Model, OptiSolidName, OptiSolidNumb, xkfil);

            Console.WriteLine("The procedure is completed");
            Console.ReadKey();
        }