Beispiel #1
0
        public double[][] GetFieldMesh(ENormDir direction)
        {
            double[][] mesh = new double[2][];

            switch (direction)
            {
            case ENormDir.X:
                mesh[0] = this.Mesh[1];
                mesh[1] = this.Mesh[2];
                break;

            case ENormDir.Y:
                mesh[0] = this.Mesh[0];
                mesh[1] = this.Mesh[2];
                break;

            case ENormDir.Z:
                mesh[0] = this.Mesh[0];
                mesh[1] = this.Mesh[1];
                break;

            default:
                break;
            }

            return(mesh);
        }
Beispiel #2
0
 public Probe(string name, EType type, double weight = 1.0, ENormDir dir = ENormDir.UNDEFINED)
     : base(name)
 {
     m_weight = weight;
     m_type   = type;
     m_dir    = dir;
 }
Beispiel #3
0
 public LumpedElement(string name, ENormDir dir,
                      double r = Double.NaN, double l = Double.NaN, double c = Double.NaN)
     : base(name)
 {
     m_dir = dir;
     m_r   = r;
     m_l   = l;
     m_c   = c;
 }
Beispiel #4
0
        public FieldSlice GetFieldSlice(ENormDir direction, double location)
        {
            double[,] field;
            double[][] mesh;
            SAR        dumpSlice;

            switch (direction)
            {
            case ENormDir.X:
                dumpSlice = GetFieldRange(new double[3][] { new double[] { location }, new double[] { }, new double[] { } });
                field     = new double[Mesh[1].Length, Mesh[2].Length];
                for (int y = 0; y < Mesh[1].Length; y++)
                {
                    for (int z = 0; z < Mesh[2].Length; z++)
                    {
                        field[y, z] = dumpSlice.Field[0, y, z];
                    }
                }
                mesh = new double[2][] { Mesh[1], Mesh[2] };
                break;

            case ENormDir.Y:
                dumpSlice = GetFieldRange(new double[3][] { new double[] { }, new double[] { location }, new double[] { } });
                field     = new double[Mesh[0].Length, Mesh[2].Length];
                for (int x = 0; x < Mesh[0].Length; x++)
                {
                    for (int z = 0; z < Mesh[2].Length; z++)
                    {
                        field[x, z] = dumpSlice.Field[x, 0, z];
                    }
                }
                mesh = new double[2][] { Mesh[0], Mesh[2] };
                break;

            case ENormDir.Z:
                dumpSlice = GetFieldRange(new double[3][] { new double[] { }, new double[] { }, new double[] { location } });
                field     = new double[Mesh[0].Length, Mesh[1].Length];
                for (int x = 0; x < Mesh[0].Length; x++)
                {
                    for (int y = 0; y < Mesh[1].Length; y++)
                    {
                        field[x, y] = dumpSlice.Field[x, y, 0];
                    }
                }
                mesh = new double[2][] { Mesh[0], Mesh[1] };
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            return(new FieldSlice(mesh, field));
        }
Beispiel #5
0
        /// <summary>
        /// Exports a slice of the SAR field at the plane defined by the normal direction and location parameters.
        /// </summary>
        /// <param name="fileName">Name of the output .png file.</param>
        /// <param name="direction">Normal direction of the SAR slice plane.</param>
        /// <param name="location">Location of the slice along the normal direction.</param>
        public void ToPNG(string fileName, ENormDir direction, double location)
        {
            int    imageSize = 512;   // TBD
            double clipdB    = -40.0; // TBD

            FieldSlice fieldSlice = GetFieldSlice(direction, location);

            int    pixelSizeX, pixelSizeY;
            double fieldSizeX = fieldSlice.Mesh[0].Last() - fieldSlice.Mesh[0].First();
            double fieldSizeY = fieldSlice.Mesh[1].Last() - fieldSlice.Mesh[1].First();
            double stepSize;

            if (fieldSizeX > fieldSizeY)
            {
                pixelSizeX = imageSize;
                pixelSizeY = (int)(imageSize * fieldSizeY / fieldSizeX);
                stepSize   = fieldSizeX / (imageSize - 1);
            }
            else
            {
                pixelSizeY = imageSize;
                pixelSizeX = (int)(imageSize * fieldSizeX / fieldSizeY);
                stepSize   = fieldSizeY / (imageSize - 1);
            }


            Bitmap bmp = new Bitmap(pixelSizeX, pixelSizeY, System.Drawing.Imaging.PixelFormat.Format32bppRgb);

            double fieldStartX = fieldSlice.Mesh[0][0];
            double fieldStartY = fieldSlice.Mesh[1][0];
            double fieldMax    = fieldSlice.Max();

            for (int x = 0; x < pixelSizeX; x++)
            {
                for (int y = 0; y < pixelSizeY; y++)
                {
                    double valSAR = fieldSlice.GetValueAt(
                        fieldSlice.Mesh[0][0] + x * stepSize,
                        fieldSlice.Mesh[1][0] + y * stepSize);

                    double valSARdB = 10 * Math.Log10(valSAR);
                    valSARdB -= 10 * Math.Log10(fieldMax);

                    double hueSARdB = valSARdB / clipdB * 240.0;
                    hueSARdB = hueSARdB > 240.0 ? 240.0 : hueSARdB;
                    bmp.SetPixel(x, y, ColorFromHSV(hueSARdB, 1.0, 0.9));
                }
            }

            bmp.RotateFlip(RotateFlipType.RotateNoneFlipY);
            bmp.Save(fileName, System.Drawing.Imaging.ImageFormat.Png);
        }
        public LumpedPort(uint priority, uint portNum, double r, Vector3D p1, Vector3D p2,
            ENormDir dir, bool excite = false)
            : base("port-" + portNum)
        {
            m_portNum = portNum;
            m_rInternal = Double.NaN;

            m_time = null;
            m_uTdValue = null;
            m_iTdValue = null;
            Freqs = null;
            m_uFdValue = null;
            m_iFdValue = null;

            if (p1.Coordinates[(uint)dir] == p2.Coordinates[(uint)dir])
            {
                Console.WriteLine("Error: Excitation vector normal direction component must not be zero");
                return;
            }

            double dirSign = p1.Coordinates[(uint)dir] < p2.Coordinates[(uint)dir] ? +1.0 : -1.0;

            // Lumped element
            Material le;
            if (r > 0 && r != Double.NaN)
            {
                m_rInternal = r;
                le = new LumpedElement("port_resist_" + portNum, dir, r: r, c: 1);
            }
            else
            {
                m_rInternal = Double.NaN;
                le = new Metal("port_resist_" + portNum);
            }
            m_primitives.Add(new Box(this, le, priority, p1, p2));
            ZReference = m_rInternal;

            // Excitation
            Vector3D ev = new Vector3D();
            ev[(int)dir] = 1.0;
            ExcitationField ef = new ExcitationField("port_excite_" + portNum,
                ExcitationField.EType.E_FIELD_SOFT, -dirSign * ev);
            m_primitives.Add(new Box(this, ef, priority, p1, p2));

            // Probes
            Vector3D u1 = 0.5 * (p1 + p2);
            Vector3D u2 = 0.5 * (p1 + p2);
            u1[(int)dir] = p1[(int)dir];
            u2[(int)dir] = p2[(int)dir];
            Probe probe_u = new Probe("port_ut" + portNum, Probe.EType.VOLTAGE_PROBE, -dirSign);
            m_primitives.Add(new Box(this, probe_u, priority, u1, u2));

            Vector3D i1 = new Vector3D(p1.x, p1.y, p1.z);
            Vector3D i2 = new Vector3D(p2.x, p2.y, p2.z);
            i1[(int)dir] = 0.5 * (p1[(int)dir] + p2[(int)dir]);
            i2[(int)dir] = 0.5 * (p1[(int)dir] + p2[(int)dir]);
            Probe probe_i = new Probe("port_it" + portNum, Probe.EType.CURRENT_PROBE, dirSign, dir);
            m_primitives.Add(new Box(this, probe_i, priority, i1, i2));
        }
Beispiel #7
0
        public LumpedPort(uint priority, uint portNum, double r, Vector3D p1, Vector3D p2,
                          ENormDir dir, bool excite = false)
            : base("port-" + portNum)
        {
            m_portNum   = portNum;
            m_rInternal = Double.NaN;

            m_time     = null;
            m_uTdValue = null;
            m_iTdValue = null;
            Freqs      = null;
            m_uFdValue = null;
            m_iFdValue = null;

            if (p1.Coordinates[(uint)dir] == p2.Coordinates[(uint)dir])
            {
                Console.WriteLine("Error: Excitation vector normal direction component must not be zero");
                return;
            }

            double dirSign = p1.Coordinates[(uint)dir] < p2.Coordinates[(uint)dir] ? +1.0 : -1.0;

            // Lumped element
            Material le;

            if (r > 0 && r != Double.NaN)
            {
                m_rInternal = r;
                le          = new LumpedElement("port_resist_" + portNum, dir, r: r, c: 1);
            }
            else
            {
                m_rInternal = Double.NaN;
                le          = new Metal("port_resist_" + portNum);
            }
            m_primitives.Add(new Box(this, le, priority, p1, p2));
            ZReference = m_rInternal;

            // Excitation
            Vector3D ev = new Vector3D();

            ev[(int)dir] = 1.0;
            ExcitationField ef = new ExcitationField("port_excite_" + portNum,
                                                     ExcitationField.EType.E_FIELD_SOFT, -dirSign * ev);

            m_primitives.Add(new Box(this, ef, priority, p1, p2));

            // Probes
            Vector3D u1 = 0.5 * (p1 + p2);
            Vector3D u2 = 0.5 * (p1 + p2);

            u1[(int)dir] = p1[(int)dir];
            u2[(int)dir] = p2[(int)dir];
            Probe probe_u = new Probe("port_ut" + portNum, Probe.EType.VOLTAGE_PROBE, -dirSign);

            m_primitives.Add(new Box(this, probe_u, priority, u1, u2));

            Vector3D i1 = new Vector3D(p1.x, p1.y, p1.z);
            Vector3D i2 = new Vector3D(p2.x, p2.y, p2.z);

            i1[(int)dir] = 0.5 * (p1[(int)dir] + p2[(int)dir]);
            i2[(int)dir] = 0.5 * (p1[(int)dir] + p2[(int)dir]);
            Probe probe_i = new Probe("port_it" + portNum, Probe.EType.CURRENT_PROBE, dirSign, dir);

            m_primitives.Add(new Box(this, probe_i, priority, i1, i2));
        }
 public LumpedElement(string name, ENormDir dir,
     double r = Double.NaN, double l = Double.NaN, double c = Double.NaN)
     : base(name)
 {
     m_dir = dir;
     m_r = r;
     m_l = l;
     m_c = c;
 }
 public Probe(string name, EType type, double weight = 1.0, ENormDir dir = ENormDir.UNDEFINED)
     : base(name)
 {
     m_weight = weight;
     m_type = type;
     m_dir = dir;
 }
        /// <summary>
        /// Exports a slice of the SAR field at the plane defined by the normal direction and location parameters.
        /// </summary>
        /// <param name="fileName">Name of the output .png file.</param>
        /// <param name="direction">Normal direction of the SAR slice plane.</param>
        /// <param name="location">Location of the slice along the normal direction.</param>
        public void ToPNG(string fileName, ENormDir direction, double location)
        {
            int imageSize = 512; // TBD
            double clipdB = -40.0; // TBD

            FieldSlice fieldSlice = GetFieldSlice(direction, location);

            int pixelSizeX, pixelSizeY;
            double fieldSizeX = fieldSlice.Mesh[0].Last() - fieldSlice.Mesh[0].First();
            double fieldSizeY = fieldSlice.Mesh[1].Last() - fieldSlice.Mesh[1].First();
            double stepSize;

            if (fieldSizeX > fieldSizeY)
            {
                pixelSizeX = imageSize;
                pixelSizeY = (int)(imageSize * fieldSizeY / fieldSizeX);
                stepSize = fieldSizeX / (imageSize - 1);
            }
            else
            {
                pixelSizeY = imageSize;
                pixelSizeX = (int)(imageSize * fieldSizeX / fieldSizeY);
                stepSize = fieldSizeY / (imageSize - 1);
            }
                 

            Bitmap bmp = new Bitmap(pixelSizeX, pixelSizeY, System.Drawing.Imaging.PixelFormat.Format32bppRgb);

            double fieldStartX = fieldSlice.Mesh[0][0];
            double fieldStartY = fieldSlice.Mesh[1][0];
            double fieldMax = fieldSlice.Max();

            for (int x = 0; x < pixelSizeX; x++)
            {
                for (int y = 0; y < pixelSizeY; y++)
                {
                    double valSAR = fieldSlice.GetValueAt(
                        fieldSlice.Mesh[0][0] + x * stepSize,
                        fieldSlice.Mesh[1][0] + y * stepSize);

                    double valSARdB = 10 * Math.Log10(valSAR);
                    valSARdB -= 10 * Math.Log10(fieldMax);

                    double hueSARdB = valSARdB / clipdB * 240.0;
                    hueSARdB = hueSARdB > 240.0 ? 240.0 : hueSARdB;
                    bmp.SetPixel(x, y, ColorFromHSV(hueSARdB, 1.0, 0.9));
                }
            }

            bmp.RotateFlip(RotateFlipType.RotateNoneFlipY);
            bmp.Save(fileName, System.Drawing.Imaging.ImageFormat.Png);
        }
        public double[][] GetFieldMesh(ENormDir direction)
        {
            double[][] mesh = new double[2][];

            switch (direction)
            {
                case ENormDir.X:
                    mesh[0] = this.Mesh[1];
                    mesh[1] = this.Mesh[2];
                    break;

                case ENormDir.Y:
                    mesh[0] = this.Mesh[0];
                    mesh[1] = this.Mesh[2];
                    break;

                case ENormDir.Z:
                    mesh[0] = this.Mesh[0];
                    mesh[1] = this.Mesh[1];
                    break;

                default:
                    break;
            }

            return mesh;
        }
        public FieldSlice GetFieldSlice(ENormDir direction, double location)
        {
            double[,] field;
            double[][] mesh;
            SAR dumpSlice;

            switch (direction)
            {
                case ENormDir.X:
                    dumpSlice = GetFieldRange(new double[3][] { new double[] { location }, new double[] { }, new double[] { } });
                    field = new double[Mesh[1].Length, Mesh[2].Length];
                    for (int y = 0; y < Mesh[1].Length; y++)
                    {
                        for (int z = 0; z < Mesh[2].Length; z++)
                        {
                            field[y, z] = dumpSlice.Field[0, y, z];
                        }
                    }
                    mesh = new double[2][] { Mesh[1], Mesh[2] };
                    break;

                case ENormDir.Y:
                    dumpSlice = GetFieldRange(new double[3][] { new double[] { }, new double[] { location }, new double[] { } });
                    field = new double[Mesh[0].Length, Mesh[2].Length];
                    for (int x = 0; x < Mesh[0].Length; x++)
                    {
                        for (int z = 0; z < Mesh[2].Length; z++)
                        {
                            field[x, z] = dumpSlice.Field[x, 0, z];
                        }
                    }
                    mesh = new double[2][] { Mesh[0], Mesh[2] };
                    break;

                case ENormDir.Z:
                    dumpSlice = GetFieldRange(new double[3][] { new double[] { }, new double[] { }, new double[] { location } });
                    field = new double[Mesh[0].Length, Mesh[1].Length];
                    for (int x = 0; x < Mesh[0].Length; x++)
                    {
                        for (int y = 0; y < Mesh[1].Length; y++)
                        {
                            field[x, y] = dumpSlice.Field[x, y, 0];
                        }
                    }
                    mesh = new double[2][] { Mesh[0], Mesh[1] };
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
            }

            return new FieldSlice(mesh, field);
        }