Ejemplo n.º 1
0
        private void RemoveButton_Click(object sender, RoutedEventArgs e)
        {
            int n = CWDataGrid.SelectedItems.Count;

            if (n > 0)
            {
                for (int i = 0; i < n; i++)
                {
                    CW  scw = CWDataGrid.SelectedItems[i] as CW;
                    int k   = scw.No;
                    int ii  = 0;
                    foreach (CW cw in _cw_list)
                    {
                        if (cw.No == k)
                        {
                            _cw_list.RemoveAt(ii);
                            break;
                        }
                        ii++;
                    }
                }
            }

            _cw_no = 1;
            for (int i = 0; i < _cw_list.Count; i++)
            {
                _cw_list[i].No = _cw_no;
                _cw_no++;
            }
            CWDataGrid.Items.Refresh();
        }
Ejemplo n.º 2
0
        private void WriteInputFile(string inpfile)
        {
            System.IO.StreamWriter writer;
            writer = System.IO.File.CreateText(_inpfile);

            // Domain
            string dom = "";

            dom += "DOMAIN\t1\t1\r\n";
            writer.Write(dom);
            dom = "";
            int    cyl_num     = int.Parse(NumCyl_Val.Text);
            int    n           = 0;
            string stroke_type = "";

            if (Stroke_Type_Val.Text == "2" || Stroke_Type_Val.Text == "2-stroke")
            {
                n           = cyl_num;
                stroke_type = "2";
            }
            else if (Stroke_Type_Val.Text == "4" || Stroke_Type_Val.Text == "4-stroke")
            {
                n           = cyl_num / 2;
                stroke_type = "4";
            }

            bool flag = false;

            for (int i = 0; i < n; i++)
            {
                if (i % 8 == 7)
                {
                    dom += "\t" + (i + 1).ToString() + "\r\n";
                    flag = false;
                }
                else
                {
                    dom += "\t" + (i + 1).ToString();
                    flag = true;
                }
            }
            writer.Write(dom);
            if (flag)
            {
                writer.Write("\r\n");
            }

            // Parameter
            string param = "";

            param += "PARAMETERS\t";
            param += "1\t";
            double rpm = double.Parse(RPM_Val.Text);

            if (CrankRot_Val.Text == "CCW")
            {
                rpm = -rpm;
            }
            param += rpm.ToString() + "\t";
            param += "1\t";
            param += Stroke_Type_Val.Text + "\r\n";
            writer.Write(param);

            // Pressure
            string press = "";

            press += "PRESSURE\t";
            press += "1\t";
            press += Press_Val.Text + "\r\n";

            // ##############################################################################

            // MB
            string        mb           = "";
            List <double> total_mb_pos = new List <double>();

            for (int i = 0; i < n + 1; i++)
            {
                mb += "MB\t";
                mb += (i + 1).ToString() + "\t";
                mb += (double.Parse(MB_Val.Text) * i).ToString() + "\r\n";
                total_mb_pos.Add(double.Parse(MB_Val.Text) * i);
            }
            double del_mb = total_mb_pos[1];

            // Web
            string        web           = "";
            double        fweb_pos      = double.Parse(fWebPos_Val.Text);
            double        web_dis       = double.Parse(WebDis_Val.Text);
            List <double> total_web_pos = new List <double>();
            int           m             = n * 2;

            for (int i = 0; i < m; i++)
            {
                total_web_pos.Add(del_mb * System.Math.Truncate(i * 0.5) + fweb_pos + web_dis * (i % 2));
            }
            for (int i = 0; i < m; i++)
            {
                web += "WEB\t";
                web += (i + 1).ToString() + "\t";
                web += total_web_pos[i].ToString() + "\t";
                web += WebMass_Val.Text + "\t";
                web += Stroke_Val.Text + "\t";
                web += WebCOG_Val.Text + "\r\n";
            }

            // CW
            string cw = "";

            for (int i = 0; i < _cw_list.Count; i++)
            {
                CW cw_obj = _cw_list[i] as CW;
                cw += "CW\t";
                cw += (i + 1).ToString() + "\t";
                cw += cw_obj.Position.ToString() + "\t";
                cw += cw_obj.Mass.ToString() + "\t";
                cw += cw_obj.COG.ToString() + "\t";
                cw += cw_obj.COG.ToString() + "\r\n";
            }

            // Piston
            string piston = "";
            double pmss   = 0;
            double pbore  = 0;

            if (Pmass_Val.Text != "")
            {
                pmss = double.Parse(Pmass_Val.Text);
            }
            if (Pbore_Val.Text != "")
            {
                pbore = double.Parse(Pbore_Val.Text);
            }
            for (int i = 0; i < cyl_num; i++)
            {
                piston += "PISTON\t";
                piston += (i + 1).ToString() + "\t";
                piston += pmss.ToString() + "\t";
                piston += pbore.ToString() + "\r\n";
            }

            // Conrod
            string conrod  = "";
            double conmass = 0;
            double coniner = 0;
            double conlen  = 0;
            double concog  = 0;

            if (ConMass_Val.Text != "")
            {
                conmass = double.Parse(ConMass_Val.Text);
            }
            if (ConIner_Val.Text != "")
            {
                coniner = double.Parse(ConIner_Val.Text);
            }
            if (ConLen_Val.Text != "")
            {
                conlen = double.Parse(ConLen_Val.Text);
            }
            if (ConCOG_Val.Text != "")
            {
                concog = double.Parse(ConCOG_Val.Text);
            }
            for (int i = 0; i < cyl_num; i++)
            {
                conrod += "CONROD\t";
                conrod += (i + 1).ToString() + "\t";
                conrod += conmass.ToString() + "\t";
                conrod += coniner.ToString() + "\t";
                conrod += conlen.ToString() + "\t";
                conrod += concog.ToString() + "\r\n";
            }

            // Cylinder
            string        cyl           = "";
            double        bank_ang      = double.Parse(BankAng_Val.Text);
            double        fcyl_pos      = double.Parse(fCylPos_Val.Text);
            double        cyl_dis       = double.Parse(CylDis_Val.Text);
            List <double> total_cyl_pos = new List <double>();

            List <double> fo_ang         = new List <double>();
            List <double> total_bank_ang = new List <double>();
            double        new_bank_ang   = 0;

            for (int i = 0; i < cyl_num; i++)
            {
                fo_ang.Add(0);
                if (i % 2 == 0)
                {
                    new_bank_ang = bank_ang;
                }
                else if (i % 2 == 1)
                {
                    new_bank_ang = -bank_ang;
                }
                total_bank_ang.Add(new_bank_ang);
            }

            string[]      str_ord         = Order_Val.Text.Split('/');
            string[]      str_th          = str_ord[0].Split('-');
            string[]      str_fo          = str_ord[1].Split('-');
            List <double> total_throw_ang = new List <double>();

            string idx = "";

            for (int i = 0; i < str_fo.Length; i++)
            {
                idx = (System.Math.Truncate(i * 0.5)).ToString();
                total_throw_ang.Add(double.Parse(str_th[int.Parse(idx)]));
            }

            if (stroke_type == "2")
            {
                double step = 360 / n;
                if (CrankRot_Val.Text == "CCW")
                {
                    step = -step;
                }
                int cidx = 0;
                for (int i = 0; i < str_fo.Length; i++)
                {
                    cidx         = int.Parse(str_fo[i]) - 1;
                    fo_ang[cidx] = step * i;
                }
            }
            else if (stroke_type == "4")
            {
                double ang   = 0;
                double bang  = 0;
                double thang = 0;
                int    cidx  = 0;
                double rev   = 0;
                for (int i = 0; i < str_fo.Length; i++)
                {
                    cidx  = int.Parse(str_fo[i]) - 1;
                    bang  = total_bank_ang[cidx];
                    thang = total_throw_ang[cidx];
                    if (i >= n)
                    {
                        rev = 720;
                    }
                    else
                    {
                        rev = 360;
                    }
                    if (thang != 0)
                    {
                        ang = rev - thang + bang;
                    }
                    else
                    {
                        ang = thang + bang;
                    }
                    if (CrankRot_Val.Text == "CCW")
                    {
                        if (ang > 0)
                        {
                            ang -= 720;
                        }
                        if (ang <= -720)
                        {
                            ang += 720;
                        }
                    }
                    else
                    {
                        if (ang < 0)
                        {
                            ang += 720;
                        }
                        if (ang >= 720)
                        {
                            ang -= 720;
                        }
                    }
                    fo_ang[cidx] = ang;
                }
            }

            if (stroke_type == "2")
            {
                for (int i = 0; i < cyl_num; i++)
                {
                    total_cyl_pos.Add(fcyl_pos + cyl_dis * i);
                }
            }
            else if (stroke_type == "4")
            {
                double j = 0;
                for (int i = 0; i < cyl_num; i++)
                {
                    j = System.Math.Truncate(i * 0.5);
                    if (i % 2 == 0)
                    {
                        total_cyl_pos.Add(del_mb * j + fcyl_pos);
                    }
                    else
                    {
                        total_cyl_pos.Add(del_mb * j + fcyl_pos + cyl_dis);
                    }
                }
            }

            for (int i = 0; i < cyl_num; i++)
            {
                cyl += "CYLINDER\t";
                cyl += (i + 1).ToString() + "\t";
                if (i % 2 == 0)
                {
                    cyl += bank_ang.ToString() + "\t";
                }
                else
                {
                    cyl += (-bank_ang).ToString() + "\t";
                }

                cyl += fo_ang[i].ToString() + "\t";        // firing angle
                cyl += total_cyl_pos[i].ToString() + "\t"; // axpos
                cyl += CrankMass_Val.Text + "\t";
                cyl += (i + 1).ToString() + "\t";
                cyl += (i + 1).ToString() + "\t";
                cyl += "1\r\n";
            }

            // Throw
            string th     = "";
            double cw_tol = 10;

            for (int i = 0; i < n; i++)
            {
                th += "THROW\t";
                th += (i + 1).ToString() + "\t";

                th += str_th[i] + "\t";

                th += (i + 1).ToString() + "\t";     // MB1
                th += (i + 2).ToString() + "\t";     // MB2

                th += (2 * i + 1).ToString() + "\t"; // WEB1
                th += (2 * i + 2).ToString() + "\t"; // WEB2

                List <double> web12 = new List <double>();
                web12.Add(total_web_pos[2 * i]);
                web12.Add(total_web_pos[2 * i + 1]);
                double search_cw = 0;
                for (int j = 0; j < 2; j++)
                {
                    int cw_id = 0;
                    for (int k = 0; k < _cw_list.Count; k++)
                    {
                        search_cw = System.Math.Abs(web12[j] - _cw_list[k].Position);
                        if (search_cw <= cw_tol)
                        {
                            cw_id = k + 1;
                            break;
                        }
                    }
                    if (j == 0)
                    {
                        th += cw_id.ToString() + "\t"; // CW1
                    }
                    else if (j == 1)
                    {
                        th += cw_id.ToString() + "\r\n"; // CW2
                    }
                }

                if (stroke_type == "2")
                {
                    th += "\t" + (i + 1).ToString() + "\r\n"; // cyl1
                }
                else if (stroke_type == "4")
                {
                    th += "\t" + (2 * i + 1).ToString() + "\t"; // cyl1
                    th += (2 * i + 2).ToString() + "\r\n";      // cyl2
                }
            }

            // write order
            writer.Write(th);
            writer.Write(cyl);
            writer.Write(piston);
            writer.Write(conrod);
            writer.Write(mb);
            writer.Write(web);
            writer.Write(cw);
            writer.Write(press);
            writer.Close();
        }