private void GenerateSarSimulationInput() { // Constants double unit = 1e-3; double c0 = 299792458.0; double lambda0 = c0 / m_f0; double f_c = 500e6; double lambdaMin = c0 / (m_f0 + f_c); Compound simulationSpace = new Compound("space"); Compound solidSpace = new Compound("solid-space"); simulationSpace.Add(solidSpace); solidSpace.Add(m_endo); var headPhantom = new CSXCAD.Ara.HeadPhantom(); headPhantom.Transformations.Add(new TRotateX(Math.PI / 2)); headPhantom.Transformations.Add(new TTranslate(32.0, 80.0, -headPhantom.Width / 2 - 7.0)); // TODO: Make endo width/height accessibles solidSpace.Add(headPhantom); // Set up simulation grid, nf2ff and SAR Logger.WriteInfo("Constructing FDTD simulation grid..."); double airBox = 40; double envResolution = Math.Round(lambdaMin / 20 / unit); double maxRatio = 1.5; RectilinearGrid grid = new BoundingGrid_6x3(); #region openems_workaround // openEMS v0.0.31 seems to handle transformations on excitation (lumped port), // SAR and NF2FF simulation components incorrectly. // Applied workarounds: // 1. The entire design is moved so that the antenna feedpoint is in the origin // 2. The SAR and NF2FF boxes are added late, w/o transformations Vector3D dutPosition = new Vector3D( m_antenna.AbsoluteTransformation.X, m_antenna.AbsoluteTransformation.Y, m_antenna.AbsoluteTransformation.Z); solidSpace.Transformations.Add(new TTranslate(-dutPosition)); grid.Move(-dutPosition); grid.Add(new Vector3D(0, 0, 0)); grid.ZLines.Add(-(m_antenna.Parent as CSXCAD.Ara.PCB).Thickness); grid.Sort(); grid.SmoothMesh(m_dutResolution, maxRatio); grid.Add(headPhantom.BoundingBox.P1); grid.Add(headPhantom.BoundingBox.P2); grid.SmoothMesh(m_sarResolution, maxRatio); grid.AddAirbox(airBox); grid.SmoothMesh(envResolution, maxRatio); simulationSpace.Add(new SARBox("SAR", m_f0, new Vector3D(headPhantom.XGridPoints.First(), headPhantom.YGridPoints.First(), headPhantom.ZGridPoints.First()), new Vector3D(headPhantom.XGridPoints.Last(), headPhantom.YGridPoints.Last(), headPhantom.ZGridPoints.Last()))); simulationSpace.Add(new NF2FFBox("nf2ff", new Vector3D(grid.XLines.First(), grid.YLines.First(), grid.ZLines.First()), new Vector3D(grid.XLines.Last(), grid.YLines.Last(), grid.ZLines.Last()), lambdaMin / 15 / unit)); #endregion grid.AddPML(8); Simulation fdtd = new Simulation(); fdtd.Excitation = new GaussExcitation(m_f0, m_fc); // Export XDocument doc = new XDocument( new XDeclaration("1.0", "utf-8", "yes"), new XComment("CyPhy generated openEMS simulation file"), new XElement("openEMS", fdtd.ToXElement(), new XElement("ContinuousStructure", new XAttribute("CoordSystem", 0), simulationSpace.ToXElement(), grid.ToXElement() ) ) ); string openEmsInput = Path.Combine(mainParameters.OutputDirectory, "openEMS_input.xml"); doc.Save(openEmsInput); string nf2ffInput = Path.Combine(mainParameters.OutputDirectory, "nf2ff_input.xml"); var nf2ff = new Postprocess.NF2FF(m_f0); nf2ff.ToXDocument().Save(nf2ffInput); }
private void GenerateDirectivitySimulationInput() { // Constants double unit = 1e-3; double c0 = 299792458.0; double lambda0 = c0 / m_f0; double lambdaMin = c0 / (m_f0 + m_fc); Compound simulationSpace = new Compound("space"); Compound solidSpace = new Compound("solid-space"); simulationSpace.Add(solidSpace); Compound dut; if (m_excludeEndo == true) { dut = m_endo.GetModule(m_slotIndex); } else { dut = m_endo; } solidSpace.Add(dut); // modifies dut parent (!) // Set up simulation grid, nf2ff and SAR Logger.WriteInfo("Constructing FDTD simulation grid..."); double airBox = 40; double maxRes = Math.Round(lambdaMin / 20 / unit); double maxRatio = 1.5; RectilinearGrid grid = new RectilinearGrid(); grid.Add(dut.BoundingBox.P1); grid.Add(dut.BoundingBox.P2); #region openems_workaround // openEMS v0.0.31 seems to handle transformations on excitation (lumped port), // SAR and NF2FF simulation components incorrectly. // Applied workarounds: // 1. The entire design is moved so that the antenna feedpoint is in the origin // 2. The SAR and NF2FF boxes are added late, w/o transformations Vector3D antennaPosition = new Vector3D( m_antenna.AbsoluteTransformation.X, m_antenna.AbsoluteTransformation.Y, m_antenna.AbsoluteTransformation.Z); solidSpace.Transformations.Add(new TTranslate(-antennaPosition)); grid.Move(-antennaPosition); grid.Add(new Vector3D(0, 0, 0)); grid.ZLines.Add(-(m_antenna.Parent as CSXCAD.Ara.PCB).Thickness); grid.Sort(); grid.SmoothMesh(m_dutResolution, maxRatio); grid.AddAirbox(airBox); grid.SmoothMesh(maxRes, maxRatio); simulationSpace.Add(new NF2FFBox("nf2ff", new Vector3D(grid.XLines.First(), grid.YLines.First(), grid.ZLines.First()), new Vector3D(grid.XLines.Last(), grid.YLines.Last(), grid.ZLines.Last()), lambdaMin / 15 / unit)); #endregion grid.AddPML(8); Simulation fdtd = new Simulation(); fdtd.Excitation = new GaussExcitation(m_f0, m_fc); // Export XDocument doc = new XDocument( new XDeclaration("1.0", "utf-8", "yes"), new XComment("CyPhy generated openEMS simulation file"), new XElement("openEMS", fdtd.ToXElement(), new XElement("ContinuousStructure", new XAttribute("CoordSystem", 0), simulationSpace.ToXElement(), grid.ToXElement() ) ) ); if (dut is CSXCAD.Ara.Module) { dut.Parent = m_endo; } string openEmsInput = Path.Combine(mainParameters.OutputDirectory, "openEMS_input.xml"); doc.Save(openEmsInput); string nf2ffInput = Path.Combine(mainParameters.OutputDirectory, "nf2ff_input.xml"); var nf2ff = new Postprocess.NF2FF(m_f0); nf2ff.ToXDocument().Save(nf2ffInput); }