public void MakeManifest( ISIS.GME.Common.Interfaces.FCO testBench, string outputDir = "", bool update = true) { Contract.Requires(testBench != null); string fullPathFileName = Path.Combine(outputDir, TESTBENCH_FILENAME); bool shouldUpdate = false; if (update && System.IO.File.Exists(fullPathFileName)) { MetaTBManifest oldManifest = Deserialize(fullPathFileName); this.CopyManifest(oldManifest); shouldUpdate = true; } this.TestBench = string.IsNullOrEmpty((testBench.Impl as MgaFCO).RegistryValue["TestBenchUniqueName"]) ? testBench.Name : (testBench.Impl as MgaFCO).RegistryValue["TestBenchUniqueName"]; this.Created = DateTime.UtcNow.ToString("o"); // FIXME: put design name here... this.DesignName = testBench.Name; if (testBench is CyPhy.BallisticTestBench) { this.TierLevel = (int)(testBench as CyPhy.BallisticTestBench).Attributes.Tier; } if (testBench is CyPhy.TestBenchType) { var testBenchType = ISIS.GME.Dsml.CyPhyML.Classes.TestBenchType.Cast(testBench.Impl); foreach (var item in testBenchType.Children.MetricCollection) { if (shouldUpdate) { var oldData = this.Metrics.FirstOrDefault(x => x.ID == item.Guid.ToString()); if (oldData != null) { this.Metrics.Remove(oldData); } } AVM.DDP.MetaTBManifest.Metric metric = new AVM.DDP.MetaTBManifest.Metric(); metric.Name = item.Name.Trim(); metric.Unit = (item.Impl as MgaReference).Referred == null ? string.Empty : (item.Impl as MgaReference).Referred.Name; // TODO: add the displayed name metric.Value = item.Attributes.Value; metric.ID = item.Guid.ToString(); metric.GMEID = item.ID; metric.Description = item.Attributes.Description; this.Metrics.Add(metric); } foreach (var item in testBenchType.Children.ParameterCollection) { if (shouldUpdate) { var oldData = this.Parameters.FirstOrDefault(x => x.ID == item.Guid.ToString()); if (oldData != null) { this.Parameters.Remove(oldData); } } AVM.DDP.MetaTBManifest.Parameter parameter = new AVM.DDP.MetaTBManifest.Parameter(); parameter.Name = item.Name; parameter.Unit = (item.Impl as MgaReference).Referred == null ? string.Empty : (item.Impl as MgaReference).Referred.Name; parameter.Description = item.Attributes.Description; parameter.GMEID = item.ID; parameter.ID = item.Guid.ToString(); parameter.Range = item.Attributes.Range; parameter.Value = item.Attributes.Value; this.Parameters.Add(parameter); } foreach (var item in testBenchType.Children.FileInputCollection) { if (shouldUpdate) { var oldData = this.FileInputs.FirstOrDefault(x => x.Name == item.Name); if (oldData != null) { this.FileInputs.Remove(oldData); } } AVM.DDP.MetaTBManifest.FileInput fileInput = new AVM.DDP.MetaTBManifest.FileInput(); fileInput.Name = item.Name; fileInput.FileName = item.Attributes.FileName != "" ? item.Attributes.FileName : fileInput.Name; this.FileInputs.Add(fileInput); } foreach (var item in testBenchType.Children.FileOutputCollection) { if (shouldUpdate) { var oldData = this.FileOutputs.FirstOrDefault(x => x.Name == item.Name); if (oldData != null) { this.FileOutputs.Remove(oldData); } } AVM.DDP.MetaTBManifest.FileOutput fileOutput = new AVM.DDP.MetaTBManifest.FileOutput(); fileOutput.Name = item.Name; fileOutput.FileName = item.Attributes.FileName != "" ? item.Attributes.FileName : item.Name; this.FileOutputs.Add(fileOutput); } // get designID string designID = null; var tlsut = testBenchType.Children.TopLevelSystemUnderTestCollection.FirstOrDefault(); var catlsut = testBenchType.Children.ComponentAssemblyCollection.FirstOrDefault(); if (tlsut != null) { // if it is a reference if (tlsut.Referred.DesignEntity != null) { designID = tlsut.Referred.DesignEntity.Properties.Guid.ToString("B"); if (tlsut.Referred.DesignEntity is CyPhy.ComponentAssembly) { catlsut = tlsut.Referred.ComponentAssembly; var cid = catlsut.Attributes.ConfigurationUniqueID; //this.ConfigurationUniqueID = cid; if (string.IsNullOrWhiteSpace(cid)) { cid = Guid.NewGuid().ToString("B"); catlsut.Attributes.ConfigurationUniqueID = cid; } if (!string.IsNullOrEmpty(cid)) { try { Guid guid = new Guid(cid); designID = guid.ToString("B"); } catch (System.FormatException ex) { Trace.TraceError("{0} is not a vaild GUID.", cid); Trace.TraceError(ex.ToString()); } } } } } else if (catlsut != null) { // if it is an instance var cid = catlsut.Attributes.ConfigurationUniqueID; if (!string.IsNullOrEmpty(cid)) { Guid guid = new Guid(cid); designID = guid.ToString("B"); } } // this.CopyTestResults = testBench.Attributes.CopyResults; this.DesignID = designID; } }
static int Main(string[] args) { if (args.Length != 1) { Usage(); return(-1); } // Parse arguments MfgBom.CostEstimation.CostEstimationRequest request; AVM.DDP.MetaTBManifest manifest; String pathResultsFolder; var result = ParseArgs(args, out request, out manifest, out pathResultsFolder); if (result != 0) { return(result); } CostEstimationResult estimationResult; try { // Process costing request estimationResult = MfgBom.CostEstimation.Estimation.ProcessRequest(request); } catch (OctopartQueryException e) { Console.Error.WriteLine(e.Message); return(2); } // Dump result to JSON var pathResult = Path.Combine(pathResultsFolder, "CostEstimationResults.json"); using (StreamWriter outfile = new StreamWriter(pathResult)) { outfile.Write(estimationResult.Serialize()); } var artifactResult = new AVM.DDP.MetaTBManifest.Artifact() { Location = "CostEstimationResults.json", Tag = "BomCostAnalysis::CostEstimationResults" }; manifest.Artifacts.Add(artifactResult); // Populate manifest metrics var metricCost = manifest.Metrics.FirstOrDefault(m => m.Name == "part_cost_per_design"); if (metricCost == null) { metricCost = new AVM.DDP.MetaTBManifest.Metric() { Name = "part_cost_per_design", DisplayedName = "Part Cost Per Design", Unit = "USD", GMEID = null }; if (manifest.Metrics == null) { manifest.Metrics = new List <AVM.DDP.MetaTBManifest.Metric>(); } manifest.Metrics.Add(metricCost); } metricCost.Value = estimationResult.per_design_parts_cost.ToString(); // Save UserBomTable var ubt = MfgBom.Converters.CostEstResult2UserBomTable.Convert(estimationResult); var pathUbt = Path.Combine(pathResultsFolder, "BomTable.csv"); using (StreamWriter outfile = new StreamWriter(pathUbt)) { outfile.Write(ubt.ToCsv()); } // Also save it as HTML, for MOT-335 var pathBomHtml = Path.Combine(pathResultsFolder, "BomTable.html"); using (StreamWriter outfile = new StreamWriter(pathBomHtml)) { outfile.Write(ubt.ToHtml()); // MOT-335 } var artifactUbt = new AVM.DDP.MetaTBManifest.Artifact() { Location = "BomTable.csv", Tag = "BomCostAnalysis::BomTable" }; manifest.Artifacts.Add(artifactUbt); // Save manifest changes manifest.Serialize(); return(0); }
public void MakeManifest( CyPhy.TestBenchType testBench, string outputDir = "", bool update = true) { Contract.Requires(testBench != null); string fullPathFileName = Path.Combine(outputDir, TESTBENCH_FILENAME); bool shouldUpdate = false; if (update && System.IO.File.Exists(fullPathFileName)) { MetaTBManifest oldManifest = Deserialize(fullPathFileName); this.CopyManifest(oldManifest); shouldUpdate = true; } this.TestBench = string.IsNullOrEmpty((testBench.Impl as MgaFCO).RegistryValue["TestBenchUniqueName"]) ? testBench.Name : (testBench.Impl as MgaFCO).RegistryValue["TestBenchUniqueName"]; this.Created = DateTime.UtcNow.ToString("o"); if (testBench is CyPhy.BallisticTestBench) { this.TierLevel = (int)(testBench as CyPhy.BallisticTestBench).Attributes.Tier; } foreach (var item in testBench.Children.MetricCollection) { if (shouldUpdate) { var oldData = this.Metrics.FirstOrDefault(x => x.ID == item.Guid.ToString()); if (oldData != null) { this.Metrics.Remove(oldData); } } AVM.DDP.MetaTBManifest.Metric metric = new AVM.DDP.MetaTBManifest.Metric(); metric.Name = item.Name.Trim(); metric.Unit = (item.Impl as MgaReference).Referred == null ? string.Empty : (item.Impl as MgaReference).Referred.Name; // TODO: add the displayed name metric.Value = item.Attributes.Value; metric.ID = item.Guid.ToString(); metric.GMEID = item.ID; metric.Description = item.Attributes.Description; this.Metrics.Add(metric); } foreach (var item in testBench.Children.ParameterCollection) { if (shouldUpdate) { var oldData = this.Parameters.FirstOrDefault(x => x.ID == item.Guid.ToString()); if (oldData != null) { this.Parameters.Remove(oldData); } } AVM.DDP.MetaTBManifest.Parameter parameter = new AVM.DDP.MetaTBManifest.Parameter(); parameter.Name = item.Name; parameter.Unit = (item.Impl as MgaReference).Referred == null ? string.Empty : (item.Impl as MgaReference).Referred.Name; parameter.Description = item.Attributes.Description; parameter.GMEID = item.ID; parameter.ID = item.Guid.ToString(); parameter.Range = item.Attributes.Range; parameter.Value = item.Attributes.Value; this.Parameters.Add(parameter); } // FIX ME: put design name here... this.DesignName = testBench.Name; // get designID string designID = null; var tlsut = testBench.Children.TopLevelSystemUnderTestCollection.FirstOrDefault(); var catlsut = testBench.Children.ComponentAssemblyCollection.FirstOrDefault(); if (tlsut != null) { // if it is a reference if (tlsut.Referred.DesignEntity != null) { designID = tlsut.Referred.DesignEntity.Properties.Guid.ToString("B"); if (tlsut.Referred.DesignEntity is CyPhy.ComponentAssembly) { catlsut = tlsut.Referred.ComponentAssembly; var cid = catlsut.Attributes.ConfigurationUniqueID; //this.ConfigurationUniqueID = cid; if (string.IsNullOrWhiteSpace(cid)) { cid = Guid.NewGuid().ToString("B"); catlsut.Attributes.ConfigurationUniqueID = cid; } if (!string.IsNullOrEmpty(cid)) { try { Guid guid = new Guid(cid); designID = guid.ToString("B"); } catch (System.FormatException ex) { Trace.TraceError("{0} is not a vaild GUID.", cid); Trace.TraceError(ex.ToString()); } } } } } else if (catlsut != null) { // if it is an instance var cid = catlsut.Attributes.ConfigurationUniqueID; if (!string.IsNullOrEmpty(cid)) { Guid guid = new Guid(cid); designID = guid.ToString("B"); } } // this.CopyTestResults = testBench.Attributes.CopyResults; this.DesignID = designID; }
static int 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); return(5); } return(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); } }
/// <summary> /// No GUI and interactive elements are allowed within this function. /// </summary> /// <param name="parameters">Main parameters for this run and GUI configuration.</param> /// <returns>Result of the run, which contains a success flag.</returns> public IInterpreterResult Main(IInterpreterMainParameters parameters) { this.mainParameters = parameters; //this.runtime = new Queue<Tuple<string, TimeSpan>>(); //this.runtime.Clear(); this.result = new InterpreterResult() { Success = true }; try { BOMVisitor visitor = new BOMVisitor() { Logger = Logger, Traceability = this.result.Traceability }; String nameFCO = null; int designQuantity = 1; List<String> listSupplierAffinity = null; MgaGateway.PerformInTransaction(delegate { // Call Elaborator var elaboratorSuccess = this.CallElaborator(this.mainParameters.Project, this.mainParameters.CurrentFCO, this.mainParameters.SelectedFCOs, this.mainParameters.StartModeParam); this.UpdateSuccess("Elaborator", elaboratorSuccess); // Parse design var tb = CyPhyClasses.TestBench.Cast(parameters.CurrentFCO); visitor.visit(tb); nameFCO = this.mainParameters.CurrentFCO.Name; var propDesignQuantity = tb.Children .PropertyCollection .FirstOrDefault(p => p.Name == "design_quantity"); if (propDesignQuantity != null) { int val; if (int.TryParse(propDesignQuantity.Attributes.Value, out val)) { designQuantity = val; } else { Logger.WriteWarning("The property <a href=\"mga:{0}\">{1}</a> has a non-integer value of \"{2}\". Setting to default of 1.", propDesignQuantity.ID, propDesignQuantity.Name, propDesignQuantity.Attributes.Value); } } else { Logger.WriteWarning("No property named \"design_quantity\" found. Assuming quantity of 1."); } var metricPartCostPerDesign = tb.Children .MetricCollection .FirstOrDefault(m => m.Name == "part_cost_per_design"); if (metricPartCostPerDesign == null) { var manifest = AVM.DDP.MetaTBManifest.OpenForUpdate(this.mainParameters.OutputDirectory); var metric = new AVM.DDP.MetaTBManifest.Metric() { Name = "part_cost_per_design", DisplayedName = "Part Cost Per Design", Unit = "USD", GMEID = null }; if (manifest.Metrics == null) { manifest.Metrics = new List<AVM.DDP.MetaTBManifest.Metric>(); } manifest.Metrics.Add(metric); manifest.Serialize(this.mainParameters.OutputDirectory); } var propSupplierAffinity = tb.Children .PropertyCollection .FirstOrDefault(p => p.Name == "supplier_affinity"); if (propSupplierAffinity != null && !String.IsNullOrWhiteSpace(propSupplierAffinity.Attributes.Value)) { listSupplierAffinity = propSupplierAffinity.Attributes .Value .Split(',') .Select(s => s.Trim()) .ToList(); } }, transactiontype_enum.TRANSACTION_NON_NESTED, abort: true); // Serialize BOM to file var bom = visitor.bom; var filenameBom = nameFCO + "_bom.json"; var pathBom = Path.Combine(this.mainParameters.OutputDirectory, filenameBom); using (StreamWriter outfile = new StreamWriter(pathBom)) { outfile.Write(bom.Serialize()); } // Create CostEstimationRequest var request = new MfgBom.CostEstimation.CostEstimationRequest() { bom = bom, design_quantity = designQuantity, supplier_affinity = listSupplierAffinity }; var filenameRequest = nameFCO + "_cost_estimate_request.json"; var pathRequest = Path.Combine(this.mainParameters.OutputDirectory, filenameRequest); using (StreamWriter outfile = new StreamWriter(pathRequest)) { outfile.Write(request.Serialize()); } var tbManifest = AVM.DDP.MetaTBManifest.OpenForUpdate(this.mainParameters.OutputDirectory); tbManifest.AddArtifact(filenameBom, "CyPhy2MfgBom::BOM"); tbManifest.AddArtifact(filenameRequest, "CyPhy2MfgBom::CostEstimationRequest"); tbManifest.Serialize(this.mainParameters.OutputDirectory); using (var batRunBomCostAnalysis = new StreamWriter(Path.Combine(this.mainParameters.OutputDirectory, "runBomCostAnalysis.bat"))) { batRunBomCostAnalysis.Write(CyPhy2MfgBom.Properties.Resources.runBomCostAnalysis); } this.result.RunCommand = "runBomCostAnalysis.bat"; if (this.result.Success) { Logger.WriteInfo("Generated files are here: <a href=\"file:///{0}\" target=\"_blank\">{0}</a>", this.mainParameters.OutputDirectory); Logger.WriteInfo("CyPhy2MfgBom has finished. [SUCCESS: {0}, Labels: {1}]", this.result.Success, this.result.Labels); } else { Logger.WriteError("CyPhy2MfgBom failed! See error messages above."); } } catch (Exception ex) { Logger.WriteError("Exception: {0}<br> {1}", ex.Message, ex.StackTrace); } return this.result; }
static int Main(string[] args) { if (args.Length != 1) { Usage(); return -1; } // Parse arguments MfgBom.CostEstimation.CostEstimationRequest request; AVM.DDP.MetaTBManifest manifest; String pathResultsFolder; var result = ParseArgs(args, out request, out manifest, out pathResultsFolder); if (result != 0) { return result; } // Process costing request var estimationResult = MfgBom.CostEstimation.Estimation.ProcessRequest(request); // Dump result to JSON var pathResult = Path.Combine(pathResultsFolder, "CostEstimationResults.json"); using (StreamWriter outfile = new StreamWriter(pathResult)) { outfile.Write(estimationResult.Serialize()); } var artifactResult = new AVM.DDP.MetaTBManifest.Artifact() { Location = "CostEstimationResults.json", Tag = "BomCostAnalysis::CostEstimationResults" }; manifest.Artifacts.Add(artifactResult); // Populate manifest metrics var metricCost = manifest.Metrics.FirstOrDefault(m => m.Name == "part_cost_per_design"); if (metricCost == null) { metricCost = new AVM.DDP.MetaTBManifest.Metric() { Name = "part_cost_per_design", DisplayedName = "Part Cost Per Design", Unit = "USD", GMEID = null }; if (manifest.Metrics == null) { manifest.Metrics = new List<AVM.DDP.MetaTBManifest.Metric>(); } manifest.Metrics.Add(metricCost); } metricCost.Value = estimationResult.per_design_parts_cost.ToString(); // Save UserBomTable var ubt = MfgBom.Converters.CostEstResult2UserBomTable.Convert(estimationResult); var pathUbt = Path.Combine(pathResultsFolder, "BomTable.csv"); using (StreamWriter outfile = new StreamWriter(pathUbt)) { outfile.Write(ubt.ToCsv()); } // Also save it as HTML, for MOT-335 var pathBomHtml = Path.Combine(pathResultsFolder, "BomTable.html"); using (StreamWriter outfile = new StreamWriter(pathBomHtml)) { outfile.Write(ubt.ToHtml()); // MOT-335 } var artifactUbt = new AVM.DDP.MetaTBManifest.Artifact() { Location = "BomTable.csv", Tag = "BomCostAnalysis::BomTable" }; manifest.Artifacts.Add(artifactUbt); // Save manifest changes manifest.Serialize(); return 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); } }
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); } }
private IInterpreterResult _Main(IInterpreterMainParameters parameters) { this.mainParameters = parameters; //this.runtime = new Queue<Tuple<string, TimeSpan>>(); //this.runtime.Clear(); this.result = new InterpreterResult() { Success = true }; try { BOMVisitor visitor = new BOMVisitor() { Logger = Logger, Traceability = this.result.Traceability }; String nameFCO = null; int designQuantity = 1; List <String> listSupplierAffinity = null; MgaGateway.PerformInTransaction(delegate { // Call Elaborator var elaboratorSuccess = this.CallElaborator(this.mainParameters.Project, this.mainParameters.CurrentFCO, this.mainParameters.SelectedFCOs, this.mainParameters.StartModeParam); this.UpdateSuccess("Elaborator", elaboratorSuccess); // Parse design var tb = CyPhyClasses.TestBench.Cast(parameters.CurrentFCO); visitor.visit(tb); nameFCO = this.mainParameters.CurrentFCO.Name; var propDesignQuantity = tb.Children .PropertyCollection .FirstOrDefault(p => p.Name == "design_quantity"); if (propDesignQuantity != null) { int val; if (int.TryParse(propDesignQuantity.Attributes.Value, out val)) { designQuantity = val; } else { Logger.WriteWarning("The property <a href=\"mga:{0}\">{1}</a> has a non-integer value of \"{2}\". Setting to default of 1.", propDesignQuantity.ID, propDesignQuantity.Name, propDesignQuantity.Attributes.Value); } } else { Logger.WriteWarning("No property named \"design_quantity\" found. Assuming quantity of 1."); } var metricPartCostPerDesign = tb.Children .MetricCollection .FirstOrDefault(m => m.Name == "part_cost_per_design"); if (metricPartCostPerDesign == null) { var manifest = AVM.DDP.MetaTBManifest.OpenForUpdate(this.mainParameters.OutputDirectory); var metric = new AVM.DDP.MetaTBManifest.Metric() { Name = "part_cost_per_design", DisplayedName = "Part Cost Per Design", Unit = "USD", GMEID = null }; if (manifest.Metrics == null) { manifest.Metrics = new List <AVM.DDP.MetaTBManifest.Metric>(); } manifest.Metrics.Add(metric); manifest.Serialize(this.mainParameters.OutputDirectory); } var propSupplierAffinity = tb.Children .PropertyCollection .FirstOrDefault(p => p.Name == "supplier_affinity"); if (propSupplierAffinity != null && !String.IsNullOrWhiteSpace(propSupplierAffinity.Attributes.Value)) { listSupplierAffinity = propSupplierAffinity.Attributes .Value .Split(',') .Select(s => s.Trim()) .ToList(); } }, transactiontype_enum.TRANSACTION_NON_NESTED, abort: true); // Serialize BOM to file var bom = visitor.bom; var filenameBom = nameFCO + "_bom.json"; var pathBom = Path.Combine(this.mainParameters.OutputDirectory, filenameBom); using (StreamWriter outfile = new StreamWriter(pathBom)) { outfile.Write(bom.Serialize()); } // Create CostEstimationRequest var request = new MfgBom.CostEstimation.CostEstimationRequest() { bom = bom, design_quantity = designQuantity, supplier_affinity = listSupplierAffinity }; var filenameRequest = nameFCO + "_cost_estimate_request.json"; var pathRequest = Path.Combine(this.mainParameters.OutputDirectory, filenameRequest); using (StreamWriter outfile = new StreamWriter(pathRequest)) { outfile.Write(request.Serialize()); } var tbManifest = AVM.DDP.MetaTBManifest.OpenForUpdate(this.mainParameters.OutputDirectory); tbManifest.AddArtifact(filenameBom, "CyPhy2MfgBom::BOM"); tbManifest.AddArtifact(filenameRequest, "CyPhy2MfgBom::CostEstimationRequest"); tbManifest.Serialize(this.mainParameters.OutputDirectory); using (var batRunBomCostAnalysis = new StreamWriter(Path.Combine(this.mainParameters.OutputDirectory, "runBomCostAnalysis.bat"))) { batRunBomCostAnalysis.Write(CyPhy2MfgBom.Properties.Resources.runBomCostAnalysis); } this.result.RunCommand = "runBomCostAnalysis.bat"; if (this.result.Success) { Logger.WriteInfo("Generated files are here: <a href=\"file:///{0}\" target=\"_blank\">{0}</a>", this.mainParameters.OutputDirectory); Logger.WriteInfo("CyPhy2MfgBom has finished. [SUCCESS: {0}, Labels: {1}]", this.result.Success, this.result.Labels); } else { Logger.WriteError("CyPhy2MfgBom failed! See error messages above."); } } catch (Exception ex) { Logger.WriteError("Exception: {0}<br> {1}", ex.Message, ex.StackTrace); } return(this.result); }