private void Visit(CyPhyInterfaces.Component component) { var rfModel = component.Children.RFModelCollection.FirstOrDefault(); if (rfModel != null) { string resourcePath = ""; // Get all resources foreach (var resource in rfModel.SrcConnections.UsesResourceCollection.Select(c => c.SrcEnds.Resource).Union( rfModel.DstConnections.UsesResourceCollection.Select(c => c.DstEnds.Resource))) { if (resource != null && resource.Attributes.Path != String.Empty) { rfModel.TryGetResourcePath(out resourcePath, ComponentLibraryManager.PathConvention.ABSOLUTE); } break; // max. one CSXCAD file supported } if (resourcePath.Length == 0) { Logger.WriteError("No resource file specified for component {0}.", component.Name); return; } if (!System.IO.File.Exists(resourcePath)) { Logger.WriteError("Resource file {0} not found for component {1}.", resourcePath, component.Name); return; } var araModule = m_endo.GetModule(m_slotIndex); if (araModule == null) { if (m_endo.Slots[m_slotIndex].Size[0] == 2 && m_endo.Slots[m_slotIndex].Size[1] == 2) { araModule = new CSXCAD.Ara.Module_2x2(component.Name); } else { araModule = new CSXCAD.Ara.Module_1x2(component.Name); } } m_antenna = new CSXCAD.XmlCompound( null, component.Name, new Vector3D(rfModel.Attributes.X, rfModel.Attributes.Y, araModule.PCB.Thickness), (double)rfModel.Attributes.Rotation * Math.PI / 2 ); m_antenna.Parse(XElement.Load(resourcePath)); araModule.PCB.Add(m_antenna); m_endo.AddModule(m_slotIndex, araModule); } }
static void TestAraPhone() { Endo e = new Endo(null, "endo", new Vector3D(0, 0, 0), 0); Module_1x2 m1 = new Module_1x2("m1"); Module_2x2 m2 = new Module_2x2("m2"); Module_1x2 m4 = new Module_1x2("m4"); Module_2x2 m5 = new Module_2x2("m5"); Module_1x2 m6 = new Module_1x2("m6"); Module_1x2 m7 = new Module_1x2("m7"); XmlCompound u1 = new XmlCompound(m1, "u1", new Vector3D(0, 0, 0), 0); u1.Parse(XElement.Load("Box.xml")); u1.Transformations.Add(new TTranslate(20, 3, 3)); m5.Add(u1); //e.AddModule(1, m1); //e.AddModule(3, m2); //e.AddModule(4, m4); e.AddModule(5, m5); //e.AddModule(6, m6); //e.AddModule(7, m7); // Phantom Compound headPhantom = new Compound("head-phantom"); Dielectric skinMaterial = new Dielectric("skin", 50, kappa: 0.65, density: 1100); skinMaterial.FillColor = new Material.Color(245, 215, 205, 54); skinMaterial.EdgeColor = new Material.Color(255, 235, 217, 250); Sphere skin = new Sphere(null, skinMaterial, 11, new Vector3D(), 1); skin.Transformations.Add(new TScale(80, 100, 80)); headPhantom.Add(skin); Dielectric boneMaterial = new Dielectric("bone", 13, kappa: 0.1, density: 2000); boneMaterial.FillColor = new Material.Color(227, 227, 227, 54); boneMaterial.EdgeColor = new Material.Color(202, 202, 202, 250); Sphere bone = new Sphere(null, boneMaterial, 12, new Vector3D(), 1); bone.Transformations.Add(new TScale(75, 95, 75)); headPhantom.Add(bone); Dielectric brainMaterial = new Dielectric("brain", 60, kappa: 0.7, density: 1040); brainMaterial.FillColor = new Material.Color(255, 85, 127, 54); brainMaterial.EdgeColor = new Material.Color(71, 222, 179, 250); Sphere brain = new Sphere(null, brainMaterial, 13, new Vector3D(), 1); brain.Transformations.Add(new TScale(65, 85, 65)); headPhantom.Add(brain); headPhantom.Transformations.Add(new TTranslate(33, 70, 90)); Compound s = new Compound("space"); s.Add(e); s.Add(headPhantom); RectilinearGrid g = new SimpleGrid_6x3(); g.ZLines.Add(170); double airBox = 50; double maxRes = 5; double ratio = 1.5; g.AddAirbox(airBox); g.SmoothMesh(maxRes, ratio); s.Add(new SARBox("SAR", 1200e6, new Vector3D(), new Vector3D(20, 20, 20))); s.Add(new NF2FFBox("nf2ff", new Vector3D(g.XLines.First(), g.YLines.First(), g.ZLines.First()), new Vector3D(g.XLines.Last(), g.YLines.Last(), g.ZLines.Last()))); s.Add(new LumpedPort(100, 1, 50.0, new Vector3D(-0.1, -0.1, -1.25), new Vector3D(+0.1, +0.1, +1.25), ENormDir.Z, true)); Simulation fdtd = new Simulation(); fdtd.Excitation = new GaussExcitation(1e9, 1.5e9); g.AddPML(10); 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), s.ToXElement(), g.ToXElement() ) ) ); doc.Save("CSXTest.xml"); }