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)); }
static void ExportAntenna_Small_15x6mm() { double thickness = 0.01; double airBox = 5.0; double innerResolution = 0.5; double outerResolution = 5.0; var antenna = new CSXCAD.Antenna.Small_15x6mm_2400MHz(thickness); const double pcbThickness = 1.5; var lumpedPort = new LumpedPort(90, 1, 50, new Vector3D(0.0, 0.0, -pcbThickness), new Vector3D(0.0, 0.0, 0), ENormDir.Z, true); antenna.Add(lumpedPort); double margin = 2.0; double groundWidth = 5.0; var p1 = new Vector3D(antenna.BoundingBox.P1.x - margin, -groundWidth - margin, -pcbThickness); var p2 = new Vector3D(antenna.BoundingBox.P2.x + margin, antenna.BoundingBox.P2.y + margin, 0); double epsRel = 4.88; var substrate = new Dielectric("pcb", epsRel, 1e-3 * 2 * Math.PI * 2.45e9 * epsRel * Material.Eps0); substrate.EdgeColor = new Material.Color(10, 255, 10, 128); substrate.FillColor = new Material.Color(10, 255, 10, 128); var pcb = new CSXCAD.Box(null, substrate, 60, p1, p2); antenna.Add(pcb); var bottomGround = new Metal("bottom-ground"); bottomGround.EdgeColor = new Material.Color(235, 148, 7, 255); bottomGround.FillColor = bottomGround.EdgeColor; var bottomGroundPlane = new CSXCAD.Box(null, bottomGround, 100, new Vector3D(antenna.BoundingBox.P1.x - antenna.D1, antenna.D4 / 2, -pcbThickness), new Vector3D(antenna.BoundingBox.P2.x + antenna.D3, -groundWidth, -pcbThickness-0.01)); antenna.Add(bottomGroundPlane); var topGround = new Metal("top-ground"); topGround.EdgeColor = new Material.Color(235, 148, 7, 255); topGround.FillColor = topGround.EdgeColor; var topGroundPlane = new CSXCAD.Box(null, topGround, 100, new Vector3D(antenna.BoundingBox.P1.x - antenna.D1, -antenna.D4 / 2, 0), new Vector3D(antenna.BoundingBox.P2.x + antenna.D3, -groundWidth, 0.01)); antenna.Add(topGroundPlane); var viaMetal = new Metal("via"); viaMetal.EdgeColor = new Material.Color(235, 148, 7, 255); viaMetal.FillColor = viaMetal.EdgeColor; var via = new Cylinder(null, viaMetal, 100, new Vector3D(-(antenna.W1 / 2 + antenna.D5 + antenna.W2 / 2), 0, -pcbThickness), new Vector3D(-(antenna.W1 / 2 + antenna.D5 + antenna.W2 / 2), 0, 0), 0.25); antenna.Add(via); Simulation fdtd = new Simulation(); fdtd.Excitation = new GaussExcitation(2450e6, 500e6); RectilinearGrid grid = new RectilinearGrid(); ; grid.Add(new Vector3D(0, 0, 0)); grid.Add(pcb.P1); grid.Add(pcb.P2); /* foreach (var v in antenna.antennaPoly) { grid.Add(new Vector3D(v.x, v.y, 0)); } */ grid.SmoothMesh(innerResolution); grid.AddAirbox(airBox); grid.SmoothMesh(outerResolution); var nf2ff = 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())); antenna.Add(nf2ff); grid.AddPML(8); XDocument doc = new XDocument( new XDeclaration("1.0", "utf-8", "yes"), new XComment("Test XML file for CyPhy generated openEMS simulations"), new XElement("openEMS", fdtd.ToXElement(), new XElement("ContinuousStructure", new XAttribute("CoordSystem", 0), antenna.ToXElement(), grid.ToXElement() ) ) ); doc.Save("Small_15x6mm.xml"); }
static void ExportAntenna_InvertedF() { double thickness = 0.01; double airBox = 5.0; double innerResolution = 0.5; double outerResolution = 5.0; var antenna = new CSXCAD.Antenna.InvertedF_2400MHz(thickness); const double pcbThickness = 1.5; var lumpedPort = new LumpedPort(90, 1, 50, new Vector3D(0.0, 0.0, -pcbThickness), new Vector3D(0.0, 0.0, 0), ENormDir.Z, true); antenna.Add(lumpedPort); double margin = 2.0; double groundWidth = 5.0; var p1 = new Vector3D(antenna.BoundingBox.P1.x-margin, -groundWidth-margin, -pcbThickness); var p2 = new Vector3D(antenna.BoundingBox.P2.x+margin, antenna.BoundingBox.P2.y+margin, 0); var substrate = new Dielectric("pcb", 3.38, 1e-3 * 2 * Math.PI * 2.45e9 * 3.38 * Material.Eps0); substrate.EdgeColor = new Material.Color(10, 255, 10, 128); substrate.FillColor = new Material.Color(10, 255, 10, 128); var pcb = new CSXCAD.Box(null, substrate, 60, p1, p2); //antenna.Add(pcb); var topGround = new Metal("bottom-ground"); topGround.EdgeColor = new Material.Color(235, 148, 7, 255); topGround.FillColor = topGround.EdgeColor; var topGroundPlane = new CSXCAD.Box(null, topGround, 100, new Vector3D(antenna.BoundingBox.P1.x, 0, -pcbThickness), new Vector3D(antenna.BoundingBox.P2.x, -groundWidth, -pcbThickness)); antenna.Add(topGroundPlane); var bottomGround = new Metal("top-ground"); bottomGround.EdgeColor = new Material.Color(235, 148, 7, 255); bottomGround.FillColor = bottomGround.EdgeColor; var topGroundPlaneLeft = new CSXCAD.Box(null, bottomGround, 100, new Vector3D(antenna.BoundingBox.P1.x, 0, 0), new Vector3D(-0.46/2-0.45, -groundWidth, 0)); var topGroundPlaneRight = new CSXCAD.Box(null, bottomGround, 100, new Vector3D(0.46/2+0.45, 0, 0), new Vector3D(antenna.BoundingBox.P2.x, -groundWidth, 0)); antenna.Add(topGroundPlaneLeft); antenna.Add(topGroundPlaneRight); Simulation fdtd = new Simulation(); fdtd.Excitation = new GaussExcitation(2450e6, 500e6); RectilinearGrid grid = new RectilinearGrid(); ; grid.Add(new Vector3D(0,0,0)); grid.SmoothMesh(innerResolution); grid.AddAirbox(airBox); grid.SmoothMesh(outerResolution); var nf2ff = 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())); antenna.Add(nf2ff); grid.AddPML(8); XDocument doc = new XDocument( new XDeclaration("1.0", "utf-8", "yes"), new XComment("Test XML file for CyPhy generated openEMS simulations"), new XElement("openEMS", fdtd.ToXElement(), new XElement("ContinuousStructure", new XAttribute("CoordSystem", 0), antenna.ToXElement(), grid.ToXElement() ) ) ); doc.Save("InvertedF.xml"); }
public static Material FromXElement(XElement xm) { Material material; switch (xm.Name.ToString()) { case "Material": material = new Dielectric(xm.Attribute("Name").Value); break; case "Metal": material = new Metal(xm.Attribute("Name").Value); break; default: Console.WriteLine("Error: Unsupported material type " + xm.Name.ToString()); return null; } XElement xfc = xm.Element("FillColor"); if (xfc != null) { material.FillColor = new Material.Color( Convert.ToUInt32(xfc.Attribute("R").Value), Convert.ToUInt32(xfc.Attribute("G").Value), Convert.ToUInt32(xfc.Attribute("B").Value), Convert.ToUInt32(xfc.Attribute("a").Value)); } XElement xec = xm.Element("EdgeColor"); if (xec != null) { material.EdgeColor = new Material.Color( Convert.ToUInt32(xfc.Attribute("R").Value), Convert.ToUInt32(xfc.Attribute("G").Value), Convert.ToUInt32(xfc.Attribute("B").Value), Convert.ToUInt32(xfc.Attribute("a").Value)); } return material; }