示例#1
0
        public void SAPCalculation(string inputPath, string loadingName, string outputPath, List <string> frameName, out bool getResult, string condition, int realTimes)
        {
            //loadingName = "DL+SOIL(NL)";
            loadingUID.Clear();
            loadingValue.Clear();
            loadingProp.Clear();
            jointProp.Clear();
            jtDisplacement.Clear();


            bool temp_bool = true;

            mySapObject = new SAP2000v15.SapObject();
            mySapModel  = mySapObject.SapModel;
            mySapObject.ApplicationStart(SAP2000v15.eUnits.kip_ft_F, temp_bool, "");

            ret = mySapModel.File.OpenFile(inputPath);
            ret = mySapModel.Analyze.RunAnalysis();

            ret = mySapModel.Results.Setup.DeselectAllCasesAndCombosForOutput();
            ret = mySapModel.Results.Setup.SetCaseSelectedForOutput(loadingName, true);

            wb = new XSSFWorkbook();

            for (int i = 0; i < frameName.Count; i++)
            {
                ret = mySapModel.Results.FrameForce(frameName[i], SAP2000v15.eItemTypeElm.ObjectElm, ref num, ref obj, ref ObjSta, ref elm, ref ElmSta, ref LoadCase, ref StepType_test, ref StepNum_test, ref P, ref V2, ref V3, ref T, ref M2, ref M3);

                var forceProp = Tuple.Create(frameName[i], loadingName, frameName[i]);
                loadingProp.Add(forceProp);

                try
                {
                    forceProp = Tuple.Create(frameName[i], loadingName, frameName[i + 1]);
                    loadingProp.Add(forceProp);
                }
                catch
                {
                    forceProp = Tuple.Create(frameName[i], loadingName, frameName[0]);
                    loadingProp.Add(forceProp);
                }

                for (int j = 0; j < 2; j++)
                {
                    var forceValue = Tuple.Create(P[j], V2[j], V3[j], T[j], M2[j], M3[j]);
                    loadingValue.Add(forceValue);
                    loadingUID.Add(Guid.NewGuid().ToString("D"));
                }
                ret = mySapModel.Results.JointDispl(frameName[i], SAP2000v15.eItemTypeElm.ObjectElm, ref num, ref obj, ref elm, ref LoadCase, ref StepType_test, ref StepNum_test, ref U1, ref U2, ref U3, ref R1, ref R2, ref R3);
                var dispProp = Tuple.Create(frameName[i], loadingName);
                jointProp.Add(dispProp);
                var dispValue = Tuple.Create(U1[0], U2[0], U3[0], R1[0], R2[0], R3[0]);
                jtDisplacement.Add(dispValue);
            }

            input.CreateResultFile(wb, loadingProp, loadingValue, loadingName);
            input.CreateDisplacementFile(wb, jointProp, jtDisplacement, "JointDisplacement");
            input.FileSaving(wb, outputPath);

            getResult = true;//0.33直徑與地震載重使用,只有當直徑變化過目標值後再擷取分析結果,

            if (getResult)
            {
                try
                {
                    oExcuteSQL.DeleteDataBySectionUIDAndTimes($"STN_{condition}Data", sectionUID, realTimes);
                }
                catch
                {
                }
                oExcuteSQL.InsertSAPData($"STN_{condition}Data", loadingUID, sectionUID, loadingProp, realTimes, loadingValue);
            }

            mySapObject.ApplicationExit(true);
        }
        public void SAPCalculation(string inputPath, string loadingName, string outputPath, List <string> frameName)
        {
            loadingUID.Clear();
            loadingValue.Clear();
            loadingProp.Clear();
            jointProp.Clear();
            jtDisplacement.Clear();

            bool temp_bool = true;

            mySapObject = new SapObject();
            mySapModel  = mySapObject.SapModel;
            mySapObject.ApplicationStart(eUnits.kip_ft_F, temp_bool, "");

            ret = mySapModel.File.OpenFile(inputPath);
            ret = mySapModel.Analyze.RunAnalysis();

            ret = mySapModel.Results.Setup.DeselectAllCasesAndCombosForOutput();
            ret = mySapModel.Results.Setup.SetCaseSelectedForOutput(loadingName, true);

            wb = new XSSFWorkbook();

            for (int i = 0; i < frameName.Count; i++)
            {
                ret = mySapModel.Results.FrameForce(frameName[i], eItemTypeElm.ObjectElm, ref num, ref obj, ref ObjSta,
                                                    ref elm, ref ElmSta, ref LoadCase, ref StepType_test, ref StepNum_test, ref P, ref V2, ref V3, ref T,
                                                    ref M2, ref M3);
                // I-End of frame
                var forceProp = Tuple.Create(frameName[i], loadingName, frameName[i]);
                loadingProp.Add(forceProp);
                // J-End of frame
                try
                {
                    forceProp = Tuple.Create(frameName[i], loadingName, frameName[i + 1]);
                    loadingProp.Add(forceProp);
                }
                catch // last frame
                {
                    forceProp = Tuple.Create(frameName[i], loadingName, frameName[0]);
                    loadingProp.Add(forceProp);
                }
                for (int j = 0; j < 2; j++)
                {
                    string tempUID    = Guid.NewGuid().ToString("D");
                    var    forceValue = Tuple.Create(P[j], V2[j], V3[j], T[j], M2[j], M3[j]);
                    loadingValue.Add(forceValue);
                    loadingUID.Add(tempUID);
                    // find maximum value
                    if (Math.Abs(V2[j]) > MaxV)
                    {
                        MaxV          = Math.Abs(V2[j]);
                        indexV        = (i + 1).ToString();
                        parameterV[0] = P[j];
                        parameterV[1] = V2[j];
                        parameterV[2] = M3[j];
                        stirrupUID    = tempUID;
                    }
                    if (Math.Abs(M3[j]) > MaxM)
                    {
                        MaxM          = Math.Abs(M3[j]);
                        indexM        = (i + 1).ToString();
                        parameterM[0] = P[j];
                        parameterM[1] = V2[j];
                        parameterM[2] = M3[j];
                        RCUID         = tempUID;
                    }
                }
                ret = mySapModel.Results.JointDispl(frameName[i], eItemTypeElm.ObjectElm, ref num, ref obj, ref elm,
                                                    ref LoadCase, ref StepType_test, ref StepNum_test, ref U1, ref U2, ref U3, ref R1, ref R2, ref R3);
                var dispProp = Tuple.Create(frameName[i], loadingName);
                jointProp.Add(dispProp);
                var dispValue = Tuple.Create(U1[0], U2[0], U3[0], R1[0], R2[0], R3[0]);
                jtDisplacement.Add(dispValue);
            }
            List <Tuple <string, double, double, double> > outData = new List <Tuple <string, double, double, double> >();

            outData.Add(Tuple.Create(indexV, parameterV[0], parameterV[1], parameterV[2]));
            outData.Add(Tuple.Create(indexM, parameterM[0], parameterM[1], parameterM[2]));
            input.CreateResultFile(wb, loadingProp, loadingValue, loadingName);
            input.CreateDisplacementFile(wb, jointProp, jtDisplacement, "JointDisplacement");
            input.FileSaving(wb, outputPath);

            try
            {
                oExcuteSQL.DeleteDataBySectionUIDAndTimes($"STN_SiteData", sectionUID, 1);
            }
            catch
            {
            }
            oExcuteSQL.InsertSAPData($"STN_SiteData", loadingUID, sectionUID, loadingProp, 1, loadingValue);

            // close Sap2000
            mySapObject.ApplicationExit(false);
            mySapModel  = null;
            mySapObject = null;

            // validation
            foreach (var list in outData)
            {
                Console.WriteLine("frame {0}:\tP={1}\tV={2}\tM={3}", list.Item1, list.Item2, list.Item3, list.Item4);
            }
        }