Package: pycharge
PyChargePyCharge is an open-source computational electrodynamics Python simulator that can calculate the electromagnetic fields and potentials generated by moving point charges and can self-consistently simulate dipoles modeled as Lorentz oscillators.PyCharge was developed to allow both novice and experienced users model a wide range of classical electrodynamics systems using point charges: the package can be used as a pedagogical tool for undergraduate and graduate-level EM theory courses to provide an intuitive understanding of the EM waves generated by moving point charges, and can also be used by researchers in the field of nano-optics to investigate the complex interactions of light in nanoscale environments.Key FeaturesCalculate the relativistically-correct electromagnetic fields and potentials generated by moving point charge sources in a system at specified grid points in space and time. The moving point charges can have custom trajectories.Self-consistent simulatations of dipoles modeled as Lorentz oscillators which are driven by the electric field in the system. PyCharge dynamically determines the dipole moment at each time step.Expected coupling between dipoles predicted by QED theory is captured in the simulations, and the modified radiative properties of the dipoles (radiative decay rate and frequency shift) can be extracted using the dipole's energy at each time step.Moving dipoles can be modelled by specifying the dipole's origin position as a function of time.Parallelized version of the dipole simulation method usingmpi4pyto enable the parallel execution of computationally demanding simulations on high performance computing environments to significantly improve run time.Our computational physics paper introducing the PyCharge package is available onarXivand includes an extensive review of the rich physics that govern the coupled dipole simulations.DocumentationSee the manual hosted atpycharge.readthedocs.iofor the latest documentation.InstallationPyCharge and its dependencies can be installed usingpip:pipinstallpychargeTo install in development mode, clone the GitHub repository and install with pip using the editable option:gitclonehttps://github.com/MatthewFilipovich/pycharge
pipinstall-e./pychargeUsageAn overview of the classes and methods implemented in the PyCharge package is shown in the figure below:The electromagnetic fields and potentials generated by moving point charges can be calculated using PyCharge with only a few lines of code. The following script calculates the electric field components and scalar potential along a spatial grid in the x-y plane generated by two stationary charges:importpychargeaspcfromnumpyimportlinspace,meshgridfromscipy.constantsimportesources=(pc.StationaryCharge((10e-9,0,0),e),pc.StationaryCharge((-10e-9,0,0),-e))simulation=pc.Simulation(sources)coord=linspace(-50e-9,50e-9,1001)x,y,z=meshgrid(coord,coord,0,indexing='ij')Ex,Ey,Ez=simulation.calculate_E(0,x,y,z)V=simulation.calculate_V(0,x,y,z)Two dipoles separated by 80 nm along the x-axis are simulated over 40,000 timesteps in the script below:importpychargeaspcfromnumpyimportpitimesteps=40000dt=1e-18omega_0=100e12*2*piorigins=((0,0,0),(80e-9,0,0))init_d=(0,1e-9,0)sources=(pc.Dipole(omega_0,origins[0],init_d),pc.Dipole(omega_0,origins[1],init_d))simulation=pc.Simulation(sources)simulation.run(timesteps,dt,'s_dipoles.dat')For more examples and usage, please refer to thedocumentation.ContributingWe welcome all bug reports and suggestions for future features and enhancements, which can be filed as GitHub issues. To contribute a feature:Fork it (https://github.com/MatthewFilipovich/pycharge/fork)Create your feature branch (git checkout -b feature/fooBar)Commit your changes (git commit -am 'Add some fooBar')Push to the branch (git push origin feature/fooBar)Submit a Pull RequestCiting PyChargeIf you are using PyCharge for research purposes, we kindly request that you cite the following paper:M. Filipovich and S. Hughes,PyCharge: An open-source Python package for self-consistent electrodynamics
simulations of Lorentz oscillators and moving point charges, arXiv:2107.12437.LicensePyCharge is distributed under the GNU GPLv3. SeeLICENSEfor more information.AcknowledgementsPyCharge was written as part of a graduate research project atQueen's University(Kingston, Canada) by Matthew Filipovich and supervised byStephen Hughes.