Beispiel #1
0
 public TrainingForm(Form parent)
 {
     this.parent = parent;
     InitializeComponent();
     VisualizationBox.MouseWheel += (obj, e) =>
     {
         scale += e.Delta * 0.00075f;
         VisualizationBox.Invalidate();
     };
 }
Beispiel #2
0
 private void VisualizationBox_MouseMove(object sender, MouseEventArgs e)
 {
     if (!isDown)
     {
         return;
     }
     posX    += (e.X - lastPosX);
     posY    += (e.Y - lastPosY);
     lastPosX = e.X;
     lastPosY = e.Y;
     VisualizationBox.Invalidate();
 }
Beispiel #3
0
 void GenerationPassed(object sender, GenerationEventArgs args)
 {
     scoreHistory.Add(args.Model.MeanScore);
     model = args.Model;
     Invoke((MethodInvoker)(() =>
     {
         richTextBox1.AppendText($"Generation {args.GenerationNumber}. Best fitness - {args.Model.Fitness}, best mean score - {args.Model.MeanScore}\n");
         richTextBox1.SelectionStart = richTextBox1.Text.Length;
         richTextBox1.ScrollToCaret();
         GraphsBox.Invalidate();
         VisualizationBox.Invalidate();
     }));
 }
            public static Complex[][] Finite_Radiation_Impedance_Atalla_Rect(double Xdim, double Ydim, double[] freq, double[] angles, double C_Sound, double Rho0)
            {
                Complex[][] Zr = new Complex[freq.Length][];
                double phistep = Utilities.Numerics.PiX2 / 12;
                double mindim = Math.Min(Xdim, Ydim);
                List<double> cosphi = new List<double>(), sinphi = new List<double>(), sintheta = new List<double>();

                int phi_ct = 0;

                List<double> AnglePhi = new List<double>();

                for (double phi = 0; phi < Utilities.Numerics.PiX2; phi += phistep)
                {
                    cosphi.Add(Math.Cos(phi)); sinphi.Add(Math.Sin(phi)); phi_ct++;
                    AnglePhi.Add(phi);
                }

                for (int i = 0; i < angles.Length; i++)
                {
                    sintheta.Add(Math.Abs(Math.Sin(Math.PI * angles[i] / 180)));
                }

                ///For progress feedback.
                VisualizationBox B = new VisualizationBox(-90, 90, -10, 10);
                double[] ComparisonCurve = new double[angles.Length];
                for (int j = 0; j < angles.Length; j++)
                {
                    ComparisonCurve[j] = 10 * Math.Log10(1 / (Math.Cos(angles[j] * Math.PI / 180)));
                }
                B.Show();

                for (int i = 0; i < freq.Length; i++)
                {
                    Complex Kmod = Complex.ImaginaryOne * Utilities.Numerics.PiX2 * freq[i] * Xdim / (C_Sound * 2);
                    double r = Xdim / Ydim;
                    Zr[i] = new Complex[angles.Length];
                    double lambda = C_Sound / freq[i];
                    double stepx = 1 / (4 * Xdim / (lambda / 10));
                    double stepy = 1 / (4 * Ydim / (lambda / 10));
                    Complex integral_Mod = Complex.ImaginaryOne * Rho0 * Utilities.Numerics.PiX2 * freq[i] * Ydim * stepx * stepy / (phi_ct * 4 * Math.PI);
                    Parallel.For(0, angles.Length, j =>
                    {
                        Complex FnMod = Kmod * sintheta[j];
                        for (double u = -1 + stepx / 2; u < 1; u += stepx)
                            for (double u_ = -1; u_ < 1; u_ += stepy)
                            {
                                Complex[] Zphi = new Complex[cosphi.Count];
                                double[] real = new double[cosphi.Count];
                                double[] imag = new double[cosphi.Count];
                                double u1 = u + 1, u_1 = u_ + 1;
                                double rtR = Math.Sqrt((u1) * (u1) + ((u_1 * u_1) / (r * r)));
                                Complex K = Complex.Exp(-Kmod * rtR) / rtR; //Typographical Error Identified and Fixed.

                                    for (int phi = 0; phi < cosphi.Count; phi++)
                                {
                                    Complex Fn = Complex.Exp(FnMod * (u1 * cosphi[phi] + (u_1 / r) * sinphi[phi]));
                                    Zr[i][j] += K * Fn * (1 - u) * (1 - u_);
                                }
                            }
                        Zr[i][j] *= integral_Mod;
                            /////////////
                            //Let's just try this for a moment:
                            //Zr[i][j] *= Math.Cos((angles[j]) * Math.PI / 180);
                            /////////////
                        });

                    double[] rad_eff = new double[angles.Length];
                    double[] rad_effI = new double[angles.Length];
                    double[] rad_effM = new double[angles.Length];

                    for (int j = 0; j < angles.Length; j++)
                    {
                        rad_eff[j] = 10 * Math.Log10(Zr[i][j].Real / (Rho0 * C_Sound));
                        rad_effI[j] = 10 * Math.Log10(Zr[i][j].Imaginary / (Rho0 * C_Sound));
                        rad_effM[j] = 10 * Math.Log10(Zr[i][j].Magnitude / (Rho0 * C_Sound));
                    }

                    B.Populate(angles, rad_eff, angles, rad_effI, angles, rad_effM, angles, "Angle of Incidence (theta)", "Radiation Efficiency (dB)", ComparisonCurve, 0, (int)(100f * i / freq.Length));
                }

                return Zr;
            }
            public static Complex[][] Finite_Radiation_Impedance_Rect_Longhand(double Xdim, double Ydim, double[] freq, double[] angles, double C_Sound)
            {
                Complex[][] Zr = new Complex[freq.Length][];
                double phistep = Utilities.Numerics.PiX2 / 16;
                double mindim = Math.Min(Xdim, Ydim);

                double lambda = C_Sound / freq[freq.Length - 1];
                double step = lambda / 20;
                Complex integral_Mod = Complex.ImaginaryOne * 1.2 * Utilities.Numerics.PiX2 * step * step * 0.0625 / (Xdim * Ydim);// / Area_step);
                for (int i = 0; i < freq.Length; i++)
                {
                    Zr[i] = new Complex[angles.Length];
                    for (int j = 0; j < angles.Length; j++) Zr[i][j] = new Complex();
                }
                int ct = 0;
                //for (int j = 0; j < angles.Length/2; j++)
                Parallel.For(0, (int)Math.Ceiling((double)angles.Length / 2), j =>
                {
                    ct++;
                        //Rhino.RhinoApp.CommandPrompt = string.Format("Radiation Impedance {0}% complete", Math.Round((double)ct * 200 / (double)angles.Length-1));
                        //Progress = (double)j / (double)angles.Length;
                        double k = Utilities.Numerics.PiX2 / C_Sound;
                    double kt = k * Math.Sin(Math.Abs(angles[j]) * Math.PI / 180);
                        //Parallel.For(0, (int)(Xdim / step), x =>
                        //{
                        for (double x = step / 2; x < Xdim; x += step)
                        for (double y = step / 2; y < Ydim; y += step)
                        {
                            for (double phi = 0; phi < Utilities.Numerics.PiX2; phi += phistep) //Parallel.For(0, 16, phi =>
                                {
                                double cosphi = Math.Cos(phi), sinphi = Math.Sin(phi);

                                for (double x0 = 0; x0 < Xdim; x0 += step)
                                    for (double y0 = 0; y0 < Ydim; y0 += step)
                                    {
                                        if (x == x0 && y == y0) continue;
                                        double xd = x0 - x, yd = y0 - y;
                                        double R = Math.Sqrt(xd * xd + yd * yd);
                                        Complex[] GMM = new Complex[freq.Length];
                                        Complex[] PiMPiM0 = new Complex[freq.Length];
                                        for (int i = 0; i < freq.Length; i++)
                                        {
                                            GMM[i] = Complex.Exp(-Complex.ImaginaryOne * k * freq[i] * R) / (Utilities.Numerics.PiX2 * R);
                                            PiMPiM0[i] = Complex.Exp(Complex.ImaginaryOne * kt * freq[i] * (cosphi * xd + sinphi * yd));
                                        }
                                        for (int i = 0; i < freq.Length; i++)
                                        {
                                            Zr[i][j] += GMM[i] * PiMPiM0[i];
                                        }
                                    }
                            }
                        }
                        //}//);
                        ///multiply by phistep...
                        ///By distributive property, all multipliers moved to outer loop.
                        for (int i = 0; i < freq.Length; i++)
                    {
                        Zr[i][j] *= freq[i] * integral_Mod * step * step;
                        Zr[i][35 - j] = Zr[i][j];
                    }
                        ///this is now Zr for a given angle theta.
                    });

                //////////////////////
                VisualizationBox B = new VisualizationBox(-90, 90, -30, 10);
                double[] rad_eff = new double[angles.Length];
                double[] rad_effI = new double[angles.Length];
                double[] rad_effM = new double[angles.Length];
                B.Show();

                double[] ComparisonCurve = new double[angles.Length];

                for (int j = 0; j < angles.Length; j++)
                {
                    //angles[j] += 90;
                    ComparisonCurve[j] = 10 * Math.Log10(1 / (Math.Cos(angles[j] * Math.PI / 180)));
                }
                for (int i = 0; i < Zr.Length; i++)
                {
                    for (int j = 0; j < angles.Length; j++)
                    {
                        rad_eff[j] = 10 * Math.Log10(Zr[i][j].Real / (1.2 * C_Sound));
                        rad_effI[j] = 10 * Math.Log10(Zr[i][j].Imaginary / (1.2 * C_Sound));
                        rad_effM[j] = 10 * Math.Log10(Zr[i][j].Magnitude / (1.2 * C_Sound));
                    }
                    B.Populate(angles, rad_eff, angles, rad_effI, angles, rad_effM, angles, "Angle of Incidence (theta)", "Radiation Efficiency (dB)", ComparisonCurve, 750, 100);
                }
                //////////////////////

                return Zr;
            }