Exemplo n.º 1
0
        public void ModelCalculate()
        {
            if (!HasParaSet())
            {
                throw new Exception("Model Parameters are not set!");
            }
            //获得炉管数
            int nTubeNum = (int)dblInput[5];

            //设置操作条件
            List <string[]> lsExp = CSVOperation.ReadCSV(strCasePath + "\\exp.txt");

            lsExp[1][0] = ((int)dblInput[2]).ToString();                        //打靶目标序号
            lsExp[2][0] = dblInput[0].ToString();                               //打靶目标值
            lsExp[6][0] = dblInput[4].ToString();                               //COP
            lsExp[8][0] = (dblInput[3] * 1000.0 / (double)nTubeNum).ToString(); //进料量
            lsExp[9][0] = dblInput[1].ToString();                               //汽烃比
            CSVOperation.WriteCSV(strCasePath + "\\exp.txt", false, lsExp);

            //设置Simulation文件
            //List<string[]> lsSimulation = CSVOperation.ReadCSV(strExePath + "\\Projects\\Simulation.txt");
            //lsSimulation[2][0] = strCaseName;
            List <string[]> lsSimulation = new List <string[]>();

            lsSimulation.Add(new string[1] {
                "1"
            });
            lsSimulation.Add(new string[1] {
                "0"
            });
            lsSimulation.Add(new string[1] {
                strCaseName
            });
            CSVOperation.WriteCSV(strExePath + "\\Projects\\Simulation.txt", false, lsSimulation);

            //调用coilsim
            Process process = new Process();

            process.StartInfo.FileName         = strExePath + "\\Coilsim.exe";
            process.StartInfo.WindowStyle      = ProcessWindowStyle.Normal;
            process.StartInfo.WorkingDirectory = strExePath;
            process.Start();
            Thread taskKill = new Thread(new ParameterizedThreadStart(KillCoilsim));

            taskKill.Start(process);
            process.WaitForExit();


            //获得产品收率
            if (!File.Exists(strCasePath + "\\yields.csv"))
            {
                nProductID = null;
                dblOutput  = null;
                throw new Exception("Model Failed to Converge!");
            }
            List <string[]> lsYields    = CSVOperation.ReadCSV(strCasePath + "\\yields.csv");
            int             nProductNum = lsYields.Count;

            nProductID = new int[nProductNum];
            dblOutput  = new double[nProductNum];
            for (int i = 0; i < nProductNum; i++)
            {
                nProductID[i] = Convert.ToInt32(lsYields[i][0]);
                dblOutput[i]  = Convert.ToDouble(lsYields[i][2]);
            }
        }
Exemplo n.º 2
0
        public bool SetPara(string strVal)
        {
            aspenc.ActiveDocument("asdsad");
            aspenc.Activate();


            if (!File.Exists(strVal))
            {
                blErr = true;
                throw new Exception("Input Directory is not valid!");
            }
            int             tmpInputNum  = 0;
            int             tmpOutputNum = 0;
            int             inputnum     = 0;
            int             outputnum    = 0;
            List <string[]> Config       = new List <string[]>();

            Config         = CSVOperation.ReadCSV(strVal);
            Path_AspenFile = Config[0][0];
            for (int i = 0; i < Config.Count - 1; i++)
            {
                if (Config[1 + i][0] == "Input")
                {
                    tmpInputNum = tmpInputNum + 1;
                }
                else if (Config[1 + i][0] == "Output")
                {
                    tmpOutputNum = tmpOutputNum + 1;
                }
            }
            InputNum    = tmpInputNum;
            OutputNum   = tmpOutputNum;
            Path_Input  = new string[InputNum];
            Path_Output = new string[OutputNum];
            dblInput    = new double[InputNum];
            dblOutput   = new double[OutputNum];
            for (int i = 0; i < Config.Count - 1; i++)
            {
                if (Config[1 + i][0] == "Input")
                {
                    Path_Input[inputnum] = Config[1 + i][1];
                    inputnum             = inputnum + 1;
                }
                else if (Config[1 + i][0] == "Output")
                {
                    Path_Output[outputnum] = Config[1 + i][1];
                    outputnum = outputnum + 1;
                }
            }
            //scSQL = new ServiceController();
            //scSQL.MachineName = "localhost";
            //scSQL.ServiceName = "MSSQLSERVER";
            //if (scSQL.Status == ServiceControllerStatus.Stopped)
            //{
            //    scSQL.Start();
            //}
            aspen = new Happ.HappLS();
            aspen.InitFromFile2(Path_AspenFile);
            aspen.Visible         = true;
            aspen.SuppressDialogs = 1;
            blErr        = false;
            timer        = null;
            Store_strVal = strVal;
            return(true);
        }
Exemplo n.º 3
0
        public bool SetPara(string strVal)
        {
            if (!File.Exists(strVal))
            {
                blErr = true;
                throw new Exception("Input File Directory is not valid!");
            }
            List <string[]> lsPara = CSVOperation.ReadCSV(strVal);

            if (lsPara.Count <= 0)
            {
                blErr = true;
                throw new Exception("Input File is empty!");
            }
            nInputNum         = Convert.ToInt32(lsPara[1][0]);
            nMediumNum        = Convert.ToInt32(lsPara[1][1]);
            nOutputNum        = Convert.ToInt32(lsPara[1][2]);
            nMidFuncType      = Convert.ToInt32(lsPara[1][3]);
            nOutFuncType      = Convert.ToInt32(lsPara[1][4]);
            nInputNormalType  = Convert.ToInt32(lsPara[1][5]);
            nOutputNormalType = Convert.ToInt32(lsPara[1][6]);

            dblInput   = new double[nInputNum];
            dblOutput  = new double[nOutputNum];
            dblInputW  = new double[nInputNum * nMediumNum];
            dblOutputW = new double[nMediumNum * nOutputNum];
            dblMediumB = new double[nMediumNum];
            dblOutputB = new double[nOutputNum];
            dblInputH  = new double[nInputNum];
            dblInputL  = new double[nInputNum];
            dblOutputH = new double[nOutputNum];
            dblOutputL = new double[nOutputNum];

            for (int i = 0; i < nMediumNum; i++)
            {
                for (int j = 0; j < nInputNum; j++)
                {
                    dblInputW[i * nInputNum + j] = Convert.ToDouble(lsPara[i + 3][j + 1]);
                }
                dblMediumB[i] = Convert.ToDouble(lsPara[i + 3][nInputNum + 1]);
            }
            for (int i = 0; i < nOutputNum; i++)
            {
                for (int j = 0; j < nMediumNum; j++)
                {
                    dblOutputW[i * nMediumNum + j] = Convert.ToDouble(lsPara[j + 3][nInputNum + i + 2]);
                }
                dblOutputB[i] = Convert.ToDouble(lsPara[nMediumNum + 3][nInputNum + i + 2]);

                dblOutputH[i] = Convert.ToDouble(lsPara[nMediumNum + nInputNum + 5 + i][1]);
                dblOutputL[i] = Convert.ToDouble(lsPara[nMediumNum + nInputNum + 5 + i][2]);
            }

            for (int i = 0; i < nInputNum; i++)
            {
                dblInputH[i] = Convert.ToDouble(lsPara[nMediumNum + 5 + i][1]);
                dblInputL[i] = Convert.ToDouble(lsPara[nMediumNum + 5 + i][2]);
            }
            blErr       = false;
            strParaPath = strVal;
            return(true);
        }