public void DipoleSar_LumpedPort_MatchesReference() { // Constants from Dipole_SAR.m double f0 = 1e9; double r = 50; double[] freqs = Utility.LinearSpace(500e6, 1500e6, 501); double meshRes = 2.5; var lumpedPort = new LumpedPort(0, 1, r, new Vector3D(-0.1, -0.1, -meshRes / 2), new Vector3D(+0.1, +0.1, meshRes / 2), ENormDir.Z, true); lumpedPort.ReadResults(freqs); ReferencePort rp = new ReferencePort(); // S11 over f Assert.Equal(rp.S11_real, (from S11 in lumpedPort.S11 select String.Format("{0:e4}", S11.Real)).ToArray()); Assert.Equal(rp.S11_imag, (from S11 in lumpedPort.S11 select String.Format("{0:e4}", S11.Imaginary)).ToArray()); // Zin over f Assert.Equal(rp.Zin_real, (from Zin in lumpedPort.ZFdIn select String.Format("{0:e4}", Zin.Real)).ToArray()); Assert.Equal(rp.Zin_imag, (from Zin in lumpedPort.ZFdIn select String.Format("{0:e4}", Zin.Imaginary)).ToArray()); // Pin over f Assert.Equal(rp.Pin, (from Pin in lumpedPort.PFdIn select String.Format("{0:e4}", Pin)).ToArray()); // Pin_f0 double Pin_f0 = lumpedPort.GetPFdInAt(f0); Assert.Equal(String.Format("{0:e4}", rp.Pin_f0), String.Format("{0:e4}", Pin_f0)); }
public void DipoleSar_Sar_MatchesReference() { double f0 = 1e9; double r = 50; double refPin_f0 = 1.420492702441687e-027; double refMaxvalue = 3.336527874272695e-026; double[] freqs = Utility.LinearSpace(500e6, 1500e6, 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 dutPin_f0 = lumpedPort.GetPFdInAt(f0); string sarFileName = @"ref_dipole_sar_dump.h5"; var sarDump = new SAR(sarFileName); Assert.Equal(String.Format("{0:e15}", refPin_f0), String.Format("{0:e15}", dutPin_f0)); Assert.Equal(String.Format("{0:e15}", refMaxvalue), String.Format("{0:e15}", sarDump.MaxValue)); Assert.Equal(String.Format("{0:e15}", refMaxvalue / refPin_f0), String.Format("{0:e15}", sarDump.MaxValue / dutPin_f0)); }
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); } }
static void ProcessNF2FF(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 antennaPort = new LumpedPort(0, 1, r, new Vector3D(-10, -1, -1), new Vector3D(10, 1, 1), ENormDir.X, true); antennaPort.ReadResults(freqs); double Pin_f0 = antennaPort.GetPFdInAt(f0); // NF2FF var nf2ff = new Postprocess.NF2FF(f0); try { nf2ff.ReadHDF5Result(); nf2ff.ToVTK(fileName: "directivity_pattern.vtk"); Console.WriteLine("Radiated power: {0,15:e4} W", nf2ff.RadiatedPower); Console.WriteLine("Directivity (max): {0,15:e4} dBi", 10.0*Math.Log10(nf2ff.Directivity)); 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 = "Directivity"; 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 = "Antenna directivity"; metric.Description = "Antenna directivity."; metric.Unit = "dBi"; metric.Value = String.Format("{0:e4}", 10.0 * Math.Log10(nf2ff.Directivity)); manifest.Serialize(manifestPath); } catch (Exception e) { Console.Error.WriteLine("Error reading far-field results: {0}", e); } }