//Macro to build a dipole antenna made of PEC in XF //J. Potter -- 06/17 var path = "/users/PAS0654/osu8742/Evolved_Dipole/handshake.csv"; var file = new File(path); file.open(1); var hands = file.readAll(); //hands=hands.replace(/,/g, ''); //hands=hands.replace(/[(]/g, ''); //hands=hands.replace(/[)]/g, ''); //Output.println(hands); var radii=[]; var lengths=[]; //Only take the lines with functions var lines = hands.split('\n'); for(var i = 0;i < lines.length;i++){ if(i>=8) { var params = lines[i].split(","); radii[i-8]=params[0]; lengths[i-8]=params[1]; Output.println(radii[i-8]); Output.println(lengths[i-8]); } } file.close(); // set variables for length of the dipoles, radius of the dipoles and units for the lengths var dipoleLength = 10; var dipoleRadius = 5; var connectorLength=1.0; var gridSize = .25; var units = " cm" //don't delete the space var frequency = .5; //App.saveCurrentProjectAs("C:/Users/Jordan/Desktop/Emacs_Scripts/XFScripts/XFDipoleTest1.xf"); function CreateDipole() { App.getActiveProject().getGeometryAssembly().clear(); //create a new sketch var dipole = new Sketch(); var base = new Ellipse( new Cartesian3D(0,0,0), new Cartesian3D( dipoleRadius + units,0,0 ), 1.0, 0.0, Math.PI*2 ); dipole.addEdge(base); //add depth to the circle var extrude = new Extrude( dipole, dipoleLength + units ); //create a recipe and model -- still need to figure what a recipe is... var dipoleRecipe = new Recipe(); dipoleRecipe.append(extrude); var dipoleModel = new Model(); dipoleModel.setRecipe(dipoleRecipe); dipoleModel.name = "Dipole Antenna Test"; //set locations of the left and right dipole segments dipoleModel.getCoordinateSystem().translate( new Cartesian3D(0,0,1 + units)); var dipoleInProject1 = App.getActiveProject().getGeometryAssembly().append(dipoleModel); dipoleModel.getCoordinateSystem().translate(new Cartesian3D(0,0,(-1 - dipoleLength) + units)); var dipoleInProject2 = App.getActiveProject().getGeometryAssembly().append(dipoleModel); // Now set the material for the Dipole: var pecMaterial = App.getActiveProject().getMaterialList().getMaterial( "PEC" ); if( null == pecMaterial ) { Output.println( "\"PEC\" material was not found, could not associate with the antenna." ); } else { App.getActiveProject().setMaterial( dipoleInProject1, pecMaterial ); App.getActiveProject().setMaterial( dipoleInProject2, pecMaterial ); } //zoom to view the extent of the creation View.zoomToExtents(); } function CreatePEC() //borrowed from XF demo { //Make the material. We will use PEC, or Perfect Electrical Conductor: var pec = new Material(); pec.name = "PEC"; var pecProperties = new PEC(); // This is the electric properties that defines PEC var pecMagneticFreespace = new MagneticFreespace(); // We could make a material that acts as PEC and PMC, but in this case we just care about electrical components. var pecPhysicalMaterial = new PhysicalMaterial(); pecPhysicalMaterial.setElectricProperties( pecProperties ); pecPhysicalMaterial.setMagneticProperties( pecMagneticFreespace ); pec.setDetails( pecPhysicalMaterial ); // PEC is historically a "white" material, so we can easily change its appearance: var pecBodyAppearance = pec.getAppearance(); var pecFaceAppearance = pecBodyAppearance.getFaceAppearance(); // The "face" appearance is the color/style associated with the surface of geometry objects pecFaceAppearance.setColor( new Color( 255, 255, 255, 255 ) ); // Set the surface color to white. (255 is the maximum intensity, these are in order R,G,B,A). // Check for an existing material if( null != App.getActiveProject().getMaterialList().getMaterial( pec.name ) ) { App.getActiveProject().getMaterialList().removeMaterial( pec.name ); } App.getActiveProject().getMaterialList().addMaterial( pec ); } function CreateAntennaSource() { // Here we will create our waveform, create our circuit component definition for the feed, and create // a CircuitComponent that will attach those to our current geometry. var waveformList = App.getActiveProject().getWaveformList(); // clear the waveform list waveformList.clear(); var parameterList = App.getActiveProject().getParameterList(); parameterList.clear(); parameterList.addParameter("freq",".5"); // Create a sinusoidal input wave var waveform = new Waveform(); var sine = new RampedSinusoidWaveformShape(); //sine.setFrequency("freq" + " GHz"); //Uncomment if using parameter sweep sine.setFrequency(frequency + " GHz"); //Comment if no parameter sweep waveform.setWaveformShape( sine ); waveform.name ="Sinusoid"; var waveformInList = waveformList.addWaveform( waveform ); // Now to create the circuit component definition: var componentDefinitionList = App.getActiveProject().getCircuitComponentDefinitionList(); // clear the list componentDefinitionList.clear(); // Create our Feed var feed = new Feed(); feed.feedType = Feed.Voltage; // Set its type enumeration to be Voltage. // Define a 50-ohm resistance for this feed var rlc = new RLCSpecification(); rlc.setResistance( "50 ohm" ); rlc.setCapacitance( "0" ); rlc.setInductance( "0" ); feed.setImpedanceSpecification( rlc ); feed.setWaveform( waveformInList ); // Make sure to use the reference that was returned by the list, or query the list directly feed.name = "50-Ohm Voltage Source"; var feedInList = componentDefinitionList.addCircuitComponentDefinition( feed ); // Now create a circuit component that will be the feed point for our simulation var componentList = App.getActiveProject().getCircuitComponentList(); componentList.clear(); var component = new CircuitComponent(); component.name = "Source"; component.setAsPort( true ); // Define the endpoints of this feed - these are defined in world position, but you can also attach them to edges, faces, etc. var coordinate1 = new CoordinateSystemPosition( 0, 0,0 ); var coordinate2 = new CoordinateSystemPosition( 0, 0, "1" + units ); component.setCircuitComponentDefinition( feedInList ); component.setEndpoint1( coordinate1 ); component.setEndpoint2( coordinate2 ); componentList.addCircuitComponent( component ); } function CreateGrid() { // Set up the grid spacing for the dipole antenna var grid = App.getActiveProject().getGrid(); var cellSizes = grid.getCellSizesSpecification(); cellSizes.setTargetSizes( Cartesian3D( gridSize + units, gridSize + units, gridSize + units ) ); // And we need to set the Minimum Sizes - these are the minimum deltas that we will allow in this project. // We'll use the scalar ratio of 20% here. cellSizes.setMinimumSizes( Cartesian3D( ".5", ".5", ".5" ) ); cellSizes.setMinimumIsRatioX( true ); cellSizes.setMinimumIsRatioY( true ); cellSizes.setMinimumIsRatioZ( true ); grid.specifyPaddingExtent( Cartesian3D( "20", "20", "20" ), Cartesian3D( "20", "20", "20" ), true, true ); } function CreateSensors() { // Here we will create a sensor definition and attach it to a near-field sensor on the surface of one of our objects. var sensorDataDefinitionList = App.getActiveProject().getSensorDataDefinitionList(); sensorDataDefinitionList.clear(); // Create a sensor var farSensor = new FarZoneSensor(); farSensor.retrieveTransientData = true; farSensor.setAngle1IncrementRadians(Math.PI/12.0); farSensor.setAngle2IncrementRadians(Math.PI/12.0); farSensor.name = "Far Zone Sensor"; var FarZoneSensorList = App.getActiveProject().getFarZoneSensorList(); FarZoneSensorList.clear(); FarZoneSensorList.addFarZoneSensor( farSensor ); } function CreateAntennaSimulationData() { // This function modifies the NewSimulationData parameters of the project. // They're called "New" because they get applied every time we create an instance of this // project and place it on our simulation queue. var simData = App.getActiveProject().getNewSimulationData(); // These should already be set, however just to make sure the current project is set up correctly simData.excitationType = NewSimulationData.DiscreteSources; simData.enableSParameters = false; // Set convergence threshold to -40 dB, and maximum number of timesteps to 10000. var terminationCriteria = simData.getTerminationCriteria(); terminationCriteria.convergenceThreshold = -40; terminationCriteria.setMaximumSimulationTime( "20000*timestep" ); // Do not attempt to collect steady-state data simData.getFOIParameters().collectSteadyStateData = true; // Construct parameter sweep //var sweep = simData.getParameterSweep(); //sweep.parameterName = "freq"; //sweep.setParameterValuesByCount(.1, 2, 5); //(start value ,end value, # of steps) //simData.enableParameterSweep = true; } function QueueSimulation() { // Create and start the simulation. Project must be saved in order to run. var simulation = App.getActiveProject().createSimulation( true ); Output.println( "Successfully created the simualtion." ); var projectId = simulation.getProjectId(); var simulationId = simulation.getSimulationId(); var numRuns = simulation.getRunCount(); } for(var i = 0;i < 5;i++){ var dipoleLength = lengths[i]; var dipoleRadius = radii[i]; //Actually create the material and then the dipole CreatePEC(); CreateDipole(); CreateAntennaSource(); CreateGrid(); CreateSensors(); CreateAntennaSimulationData(); QueueSimulation(); }