Example #1
0
        draw drawtest = new draw();//创建类 draw 的实例


        private void 打开OToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog d = new OpenFileDialog();

            d.Filter = "(*.mat)|*.mat|所有文件(*.*)|*.*"; if (d.ShowDialog() == DialogResult.OK)
            {
                FileStream fs = File.OpenRead(d.FileName); StreamReader sr = new StreamReader(fs); string s;
                string     filename = d.FileName;
                d1 = pcl.loaddata(filename);
                // MessageBox.Show(filename);
                MWArray[] agrsIn = new MWArray[] { d1 };  
                pcl.pces(4, ref agrsOut, agrsIn);

                MWNumericArray x1 = agrsOut[0] as MWNumericArray;
                MWNumericArray x2 = agrsOut[1] as MWNumericArray;
                MWNumericArray x3 = agrsOut[2] as MWNumericArray;
                MWNumericArray x4 = agrsOut[3] as MWNumericArray;
                rbegin        = (double[, ])x1.ToArray();
                pend          = (double[, ])x2.ToArray();
                rpk           = (double[, ])x3.ToArray();
                f1            = (double[, ])d1.ToArray();
                qt_mean       = x4.ToScalarDouble();
                textBox4.Text = qt_mean.ToString();
                for (int i = 0; i < 12000; i++)
                {
                    data[i].X = (int)i;//强制类型转换,将double转为int,可能会丢失数据
                    data[i].Y = (int)((1000 - f1[0, i *5]) * 250 / 4500 + 100);
                }
                this.timer1.Enabled  = true; //可以使用
                this.timer1.Interval = 100;  //定时时间为100毫秒
                this.timer1.Tick    += new System.EventHandler(this.timer1_Tick);

                this.timer1.Start();//启动定时器
            }
        }
        public double simulate(double length, double crossSection, Material material, Cooler cooler, double powerFactor)
        {
            double[,] data = cooler.getDataNative("CPM");
            for (int i = 0; i < data.GetLength(0); i++)
            {
                data[i, 0]  = 300.0 - (300.0 - data[i, 0]) * powerFactor;
                data[i, 1] *= powerFactor;
            }
            MWNumericArray coolerData   = (MWNumericArray)data;
            MWNumericArray materialData = material.getData("PM");

            // We assume that if the MATLAB code generates an exception or returns NaN, it's becuase the parameters
            // imply a system which is infeasible.  That might mean that the steady state temperature would be below
            // the lowest conductivity data point for the material.
            try {
                MWNumericArray ssTemp = (MWNumericArray)matlabSim.steadystatetemperature(length, crossSection, materialData, coolerData);
                double         answer = ssTemp.ToScalarDouble();
                if (Double.IsNaN(answer))
                {
                    throw new ArgumentException("Bad arguments to simulate method");
                }
                else
                {
                    return(answer);
                }
            } catch (Exception ex) {
                throw new ArgumentException("Bad arguments to simulate method", ex);
            }
        }
        public double strutLength(double targetTemp, double crossSection, Material material, Cooler cooler)
        {
            MWNumericArray targetTempData   = new MWNumericArray(targetTemp);
            MWNumericArray crossSectionData = new MWNumericArray(crossSection);
            MWNumericArray materialData     = material.getData("PM");
            MWNumericArray coolerData       = cooler.getData("CPM");
            MWNumericArray strutLength      = (MWNumericArray)matlabSim.strutlength(
                targetTempData, crossSectionData, materialData, coolerData);

            return(strutLength.ToScalarDouble());
        }
Example #4
0
        public static double DTC_SRC_Mgain2(double Td, double fs, double Q)
        {
            double         value  = -1;
            MWArray        output = solve.solve_DTCSRC_Mgain2(Td, fs, Q);
            MWNumericArray result = (MWNumericArray)output;

            value = result.ToScalarDouble();
            if (value < 0)
            {
                Console.WriteLine("Wrong DTC_SRC_Mgain1!");
                System.Environment.Exit(-1);
            }
            return(value);
        }
 public double simulate(double length, double crossSection, Material material, Cooler cooler)
 {
     try {
         MWNumericArray lengthData       = new MWNumericArray(length);
         MWNumericArray crossSectionData = new MWNumericArray(crossSection);
         MWNumericArray materialData     = material.getData("PM");
         MWNumericArray coolerData       = cooler.getData("CPM");
         MWNumericArray ssTemp           = (MWNumericArray)matlabSim.steadystatetemperature(
             lengthData, crossSectionData, materialData, coolerData);
         return(ssTemp.ToScalarDouble());
     } catch (Exception ex) {
         throw new ArgumentException("Bad arguments to simulate method", ex);
     }
 }
Example #6
0
        public void getGasCalculate(string database, string tableName, double l, double r, double t, out double dist, out double tick)
        {
            MWCharArray    dataPath  = new MWCharArray(database);
            MWCharArray    table     = new MWCharArray(tableName);
            MWNumericArray length    = new MWNumericArray(l);
            MWNumericArray radius    = new MWNumericArray(r);
            MWNumericArray thickness = new MWNumericArray(t);

            MWArray[] argsOut = new MWArray[2];
            MWArray[] argsIn  = new MWArray[] { dataPath, table, length, radius, thickness };
            m2CClass.GasLeak(2, ref argsOut, argsIn);
            MWNumericArray distance = argsOut[0] as MWNumericArray;
            MWNumericArray timeTick = argsOut[1] as MWNumericArray;

            dist = (double)distance.ToScalarDouble();
            tick = (double)timeTick.ToScalarDouble();
        }
        public double strutLength(double targetTemp, double crossSection, Material material, Cooler cooler, double powerFactor)
        {
            double[,] data = cooler.getDataNative("CPM");
            for (int i = 0; i < data.GetLength(0); i++)
            {
                data[i, 0]  = 300.0 - (300.0 - data[i, 0]) * powerFactor;
                data[i, 1] *= powerFactor;
            }
            MWNumericArray targetTempData   = new MWNumericArray(targetTemp);
            MWNumericArray crossSectionData = new MWNumericArray(crossSection);
            MWNumericArray materialData     = material.getData("PM");
            MWNumericArray coolerData       = (MWNumericArray)data;
            MWNumericArray strutLength      = (MWNumericArray)matlabSim.strutlength(
                targetTempData, crossSectionData, materialData, coolerData);
            double answer = strutLength.ToScalarDouble();

            return(answer);
        }
Example #8
0
        private void button7_Click(object sender, EventArgs e)
        {
            PSNR.Class1 psnr   = new PSNR.Class1();
            MWCharArray marked = fMarked;
            MWCharArray src    = fCarrier;
            double      result = 0;

            try
            {
                MWArray[] argsOut = new MWArray[1];//表示两个输出参数
                MWArray[] argsIn  = new MWArray[] { marked, src };

                psnr.PSNR(1, ref argsOut, argsIn);
                MWNumericArray x = argsOut[0] as MWNumericArray;
                result = x.ToScalarDouble();
                MessageBox.Show("PSNR值为:" + result, "计算结果");
            }
            catch
            {
                MessageBox.Show("计算失败!请检查图片大小是否相等", "警告!");
                return;
            }
        }
Example #9
0
        /// <summary>
        /// 计算电路参数,并模拟电压、电流波形
        /// </summary>
        private void Simulate()
        {
            double P   = math_P;
            double Vin = math_Vin;
            double Vo  = math_Vo;
            double fr  = math_fr;
            double n   = math_n;
            double Lr  = math_Lr;
            double Cr  = math_Cr;

            double M  = n * Vo / Vin;
            double Zr = Math.Sqrt(Lr / Cr);
            double RL = Math.Pow(Vo, 2) / P;
            double Q  = Zr / (Math.Pow(n, 2) * RL); //品质因数(仅用于计算,并非基波等效的品质因数)

            //标幺化
            double Vbase = Vo;
            double Ibase = Vbase / Zr;
            double fbase = fr;

            //求解Td和fs
            MWArray        output  = Formula.solve.solve_DTCSRC(Q, M, math_Tdead * fbase);
            MWNumericArray result  = (MWNumericArray)output;
            double         Td_base = result[1].ToScalarDouble();
            double         fs_base = result[2].ToScalarDouble();

            if (Td_base < 0 || Td_base > 0.5)
            {
                Console.WriteLine("Wrong Td!");
                System.Environment.Exit(-1);
            }
            if (fs_base < 0.75 || fs_base >= 100)
            {
                Console.WriteLine("Wrong fs!");
                System.Environment.Exit(-1);
            }

            if (fs_base > 1.5)
            {//定频控制,求解对应Td
                fs_base = 1.5;
                output  = Formula.solve.solve_DTCSRC_Td(Q, M, fs_base);
                result  = (MWNumericArray)output;
                Td_base = result.ToScalarDouble();
                if (Td_base < 0 || Td_base > 0.5)
                {
                    Console.WriteLine("Wrong Td!");
                    System.Environment.Exit(-1);
                }
            }
            double Ts    = 1 / (fs_base * fbase);
            double Tbase = Ts;

            int mode = Formula.DTC_SRC_CCMflag(Td_base, fs_base, Q, M); //电流导通模式 0->DCM 1->CCM

            math_qZVS = 0;
            double Td   = Tbase * Td_base;
            double Te2  = Tbase * Formula.DTC_SRC_Te2(Td_base, fs_base, Q, M, mode);
            double ILp  = 0;
            double VCrp = 0;

            curve_iL  = new Curve();
            curve_vCr = new Curve();
            double startTime = 0;
            double endTime   = 1;
            double dt        = (endTime - startTime) / Configuration.DEGREE;

            for (int i = 0; i <= Configuration.DEGREE; i++)
            {
                double t   = startTime + dt * i;
                double iLr = Formula.DTC_SRC_ilr(t, Td_base, fs_base, Q, M, mode);
                double vCr = Formula.DTC_SRC_vcr(t, Td_base, fs_base, Q, M, mode);
                curve_iL.Add(Tbase * t, Ibase * iLr);
                curve_vCr.Add(Tbase * t, Vbase * vCr);
                if (Function.LE(Te2 / Tbase, t) && Function.LE(t, 0.5))
                {
                    math_qZVS += iLr * dt * Tbase;
                }
                //记录峰值
                ILp  = Math.Max(ILp, Math.Abs(Ibase * iLr));
                VCrp = Math.Max(VCrp, Math.Abs(Vbase * vCr));
            }
            //补充特殊点(保证现有的开关器件损耗计算中,判断开通/关断/导通状态的部分正确) FIXME 更好的方法?
            curve_iL.Order(0, 0);
            curve_iL.Order(Ts / 2, 0);
            //生成主电路元件波形
            curve_iSp = curve_iL.Cut(Te2, Te2 + Ts / 2, -1);
            curve_iSs = curve_iL.Cut(0, Td + Ts / 2, -n);
            curve_iDs = curve_iL.Cut(Td, Ts / 2, n);
            math_vSp  = Vin;
            math_vSs  = Vo;
            math_vDs  = Vo;
            double Io = Vo / RL;

            curve_iCf = curve_iDs.Copy(1, 0, -Io);
            curve_iCf.Order(0, -Io);
            curve_iCf.Order(Td_base, -Io);
            //计算有效值
            math_ILrms  = curve_iL.CalcRMS();
            math_ICfrms = curve_iCf.CalcRMS();

            math_fs   = fs_base * fbase; //还原实际值;
            math_ψ    = Formula.DTC_SRC_Ψm(Vin, Vo * n, Vbase, Ts, Td_base, fs_base, Q, M, mode);
            math_ILp  = ILp;
            math_VCrp = VCrp;
        }