{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Undulator Power Density\n", "\n", "This is a simple example of how to calculate a power density distribution from an undulator." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Plots inline for notebook\n", "%matplotlib inline\n", "\n", "# Import the OSCARS SR module\n", "import oscars.sr\n", "\n", "# Optionally import the plotting tools (matplotlib)\n", "from oscars.plots_mpl import *" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Create a new OSCARS object. Default to 8 threads and always use the GPU if available\n", "osr = oscars.sr.sr(nthreads=8, gpu=1)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Undulator Field\n", "\n", "Create a simple undulator field" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "# Clear all existing fields and create an undulator field\n", "osr.clear_bfields()\n", "osr.add_bfield_undulator(bfield=[0, 1, 0], period=[0, 0, 0.050], nperiods=31)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Particle Beam and Trajectory\n", "\n", "Define a particle beam, in this case a 3 [GeV] electron beam. You must also define the start and stop times for the calculation." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "# Define simple electron beam\n", "osr.set_particle_beam(energy_GeV=3, x0=[0, 0, -1], current=0.5)\n", "\n", "# Define the start and stop times for the calculation\n", "osr.set_ctstartstop(0, 2)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Calculate Power Density\n", "\n", "Calculate the spectrum 30 [m] downstream from the center of the device on a rectangular surface." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "# Calculate spectrum at 30 [m]. Note use of the nthreads argument.\n", "power_density = osr.calculate_power_density_rectangle(\n", " plane='XY',\n", " width=[0.05, 0.05],\n", " npoints=[101, 101],\n", " translation=[0, 0, 30]\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Plot Power Density\n", "\n", "With the oscars.plots_mpl module you can plot the power density (and many other things)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Plot power density\n", "plot_power_density(power_density)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] } ], "metadata": { "anaconda-cloud": {}, "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.1" } }, "nbformat": 4, "nbformat_minor": 1 }