Пример #1
0
 public SAR(string fileName)
 {
     FileName  = fileName;
     Frequency = HDF5.ReadAttribute(fileName, @"/FieldData/FD", "frequency");
     Mesh      = HDF5.ReadMesh(fileName);
     Field     = HDF5.ReadFieldData3D(fileName);
 }
Пример #2
0
        public void ReadHDF5Result()
        {
            ReadHDF5Mesh();
            ReadHDF5FieldData();

            m_frequency   = HDF5.ReadAttribute(m_resultFile, "/nf2ff", "Frequency");
            RadiatedPower = HDF5.ReadAttribute(m_resultFile, "/nf2ff", "Prad");
            Directivity   = HDF5.ReadAttribute(m_resultFile, "/nf2ff", "Dmax");
        }
Пример #3
0
        public void ReadHDF5FieldData()
        {
            double[,] re = HDF5.ReadFieldData2D(m_resultFile, "/nf2ff/E_theta/FD/f0_real");
            double[,] im = HDF5.ReadFieldData2D(m_resultFile, "/nf2ff/E_theta/FD/f0_imag");

            ETheta = new Complex[re.GetLength(0), re.GetLength(1)];
            for (int i = 0; i < re.GetLength(0); i++)
            {
                for (int j = 0; j < re.GetLength(1); j++)
                {
                    ETheta[i, j] = new Complex(re[i, j], im[i, j]);
                }
            }

            re = HDF5.ReadFieldData2D(m_resultFile, "/nf2ff/E_phi/FD/f0_real");
            im = HDF5.ReadFieldData2D(m_resultFile, "/nf2ff/E_phi/FD/f0_imag");

            EPhi = new Complex[re.GetLength(0), re.GetLength(1)];
            for (int i = 0; i < re.GetLength(0); i++)
            {
                for (int j = 0; j < re.GetLength(1); j++)
                {
                    EPhi[i, j] = new Complex(re[i, j], im[i, j]);
                }
            }

            ENorm = new double[re.GetLength(0), re.GetLength(1)];
            for (int i = 0; i < re.GetLength(0); i++)
            {
                for (int j = 0; j < re.GetLength(1); j++)
                {
                    ENorm[i, j] = Math.Sqrt(Complex.Abs(ETheta[i, j]) * Complex.Abs(ETheta[i, j])
                                            + Complex.Abs(EPhi[i, j] * Complex.Abs(EPhi[i, j])));
                }
            }

            PRadiated = HDF5.ReadFieldData2D(m_resultFile, "/nf2ff/P_rad/FD/f0");
        }
Пример #4
0
        private void ReadHDF5Mesh()
        {
            double[][] meshes    = new double[3][];
            string[]   meshNames = { "phi", "r", "theta" };

            H5FileId fileId = H5F.open(m_resultFile, H5F.OpenMode.ACC_RDONLY);

            if (HDF5.ReadAttribute(m_resultFile, "/Mesh", "MeshType") != 2)
            {
                Console.WriteLine("Error: Invalid NF2FF mesh type in <{0}>", m_resultFile);
                return;
            }

            for (int i = 0; i < meshNames.Length; i++)
            {
                H5DataSetId  dsId = H5D.open(fileId, "/Mesh/" + meshNames[i]);
                H5DataTypeId dtId = H5D.getType(dsId);

                if (!H5T.equal(dtId, H5T.copy(H5T.H5Type.NATIVE_FLOAT)))
                {
                    Console.WriteLine("Error: Invalid dataset type, expected {0}", H5T.H5Type.NATIVE_FLOAT);
                }

                float[] mesh = new float[H5D.getStorageSize(dsId) / H5T.getSize(dtId)];
                H5D.read(dsId, dtId, new H5Array <float>(mesh));

                meshes[i] = mesh.Select(x => (double)x).ToArray();

                H5D.close(dsId);
                H5T.close(dtId);
            }

            H5F.close(fileId);

            m_theta = meshes[2];
            m_phi   = meshes[0];
        }
Пример #5
0
        static void ProcessSAR(string inputFileName)
        {
            // Constants
            XElement xDoc    = XElement.Load(inputFileName);
            double   f0      = Convert.ToDouble(xDoc.Element("FDTD").Element("Excitation").Attribute("f0").Value);
            var      leQuery = from xe in xDoc.Element("ContinuousStructure").Element("Properties").Elements("LumpedElement")
                               where xe.Attribute("Name").Value.Contains("resist")
                               select xe;
            double r = Convert.ToDouble(leQuery.First().Attribute("R").Value);

            // Port calculations
            double[] freqs      = Utility.LinearSpace(f0 / 2, f0 * 3 / 2, 501);
            var      lumpedPort = new LumpedPort(0, 1, r, new Vector3D(-10, -1, -1), new Vector3D(10, 1, 1), ENormDir.X, true);

            lumpedPort.ReadResults(freqs);
            double Pin_f0 = lumpedPort.GetPFdInAt(f0);

            Console.WriteLine();

            // SAR
            string sarFileName = @"SAR.h5";
            var    sarDump     = new Postprocess.SAR(sarFileName);
            double totalPower  = HDF5.ReadAttribute(sarFileName, @"/FieldData/FD/f0", "power");

            Console.WriteLine("Field maximum: {0:e4}", sarDump.MaxValue);
            Console.WriteLine("Field maximum location: ({0})", String.Join(",", sarDump.MaxCoordinates.Select(x => String.Format("{0:f2}", x))));

            Console.WriteLine("Exporting SAR dump slices to PNG files...");
            string filenameSarX = "SAR-X.png";
            string filenameSarY = "SAR-Y.png";
            string filenameSarZ = "SAR-Z.png";

            sarDump.ToPNG(filenameSarX, Postprocess.SAR.ENormDir.X, sarDump.MaxCoordinates[0]);
            sarDump.ToPNG(filenameSarY, Postprocess.SAR.ENormDir.Y, sarDump.MaxCoordinates[1]);
            sarDump.ToPNG(filenameSarZ, Postprocess.SAR.ENormDir.Z, sarDump.MaxCoordinates[2]);
            Console.WriteLine("Exporting SAR to VTK file...");
            sarDump.ToVTK(inputFileName);

            // NF2FF
            Console.WriteLine("Calculating antenna parameters...");
            var nf2ff = new Postprocess.NF2FF(f0);

            try
            {
                nf2ff.ReadHDF5Result();

                Console.WriteLine("Maximum SAR:    {0:f3} W/kg (normalized to 1 W accepted power)", sarDump.MaxValue / Pin_f0);
                Console.WriteLine("Accepted power: {0:e4} W", Pin_f0);
                Console.WriteLine("Radiated power: {0:e4} W", nf2ff.RadiatedPower);
                Console.WriteLine("Absorbed power: {0:e4} W", totalPower);
                Console.WriteLine("Power budget:   {0:f3} %", 100 * (nf2ff.RadiatedPower + totalPower) / Pin_f0);

                Console.WriteLine("Populating manifest file...");
                var manifest = AVM.DDP.MetaTBManifest.OpenForUpdate(manifestPath);

                // Initialize Metrics list if necessary
                if (manifest.Metrics == null)
                {
                    manifest.Metrics = new List <AVM.DDP.MetaTBManifest.Metric>();
                }

                // Look for existing metric. Create a new one if not found.
                string metricName = "SAR_max";
                AVM.DDP.MetaTBManifest.Metric metric = manifest.Metrics.FirstOrDefault(m => m.Name.Equals(metricName));
                if (metric == null)
                {
                    metric = new AVM.DDP.MetaTBManifest.Metric()
                    {
                        Name = metricName
                    };
                    manifest.Metrics.Add(metric);
                }

                // Set metric attributes
                metric.DisplayedName = "SAR maximum";
                metric.Description   = "Maximum Specific Absorption Ratio (SAR) averaged over volumes containing 1 gram of tissue.";
                metric.Unit          = "W/kg";
                metric.Value         = String.Format("{0:e4}", sarDump.MaxValue / Pin_f0);

                metric.VisualizationArtifacts = new List <AVM.DDP.MetaTBManifest.Artifact>();
                metric.VisualizationArtifacts.Add(new AVM.DDP.MetaTBManifest.Artifact()
                {
                    Location = filenameSarX, Tag = "CyPhy2RF::SAR::X"
                });
                metric.VisualizationArtifacts.Add(new AVM.DDP.MetaTBManifest.Artifact()
                {
                    Location = filenameSarY, Tag = "CyPhy2RF::SAR::Y"
                });
                metric.VisualizationArtifacts.Add(new AVM.DDP.MetaTBManifest.Artifact()
                {
                    Location = filenameSarZ, Tag = "CyPhy2RF::SAR::Z"
                });

                manifest.Serialize(manifestPath);
            }
            catch (Exception e)
            {
                Console.Error.WriteLine("Error reading far-field results: {0}", e);
            }
        }