M. T. Homer Reid MIT Home Page
Physics Problems Research teaching My Music About Me Miscellany


libscuff API Documentation:
python examples

scuff-em API: python Examples
1. Electrostatics of a Spherical Shell
2. Maxwell stress tensor near a hole in a metallic plate

1. Electrostatics of a spherical shell

For our first example, we'll consider the electrostatics of a spherical dielectric shell in a constant electric field. (By "electrostatics" we really mean the low-frequency limit of a full-wave calculation, and we approximate our "constant electric field" by the field of a plane wave, which at our low frequency is essentially constant over the size of the object.) This geometry can be treated analytically, and is discussed thoroughly as an example of a scuff-scatter calculation. Our goal here will be to reproduce in python what we needed to use a shell script to do in scuff-scatter -- namely, to compute the electric field at the origin as a function of the shell permittivity.

The following script is available in the scuff-em distribution as the file share/scuff-em/examples/SphericalShell/PythonScript. Note that you need to configure your python paths to include the location of the scuff-em wrappers.

     import sys
     import scuff;
     import numpy.linalg;
     # create the geometry, preload the cache 
     G = scuff.RWGGeometry("SphericalShell.scuffgeo");

     # create the incident field 
     # read in matrix of eval-point coordinates
     # loop over shell permittivity values 
     for Eps in range(2,102,2):
        # set shell permittivity 

        # set up and solve the BEM problem
      	RHS=G.AssembleRHSVector(Omega, PW);

        # compute and print scattered fields 
        # (note Fields is a 6-element array, whose third element is Ez)
        Fields = G.GetFields(PW, KN, Omega, X );
        print Eps, Fields[0][2].real

        # clean up
        del M
        del RHS
        del KN
        del Fields

A sample run looks like this:

    % python

     Python 2.7.1+ (r271:86832, Apr 11 2011, 18:13:53) 
     [GCC 4.5.2] on linux2
     Type "help", "copyright", "credits" or "license" for more information.
     >>> execfile("PythonScript")
     2 0.911366542492
     4 0.695193402985
     6 0.551800770349
     8 0.455746982211
     10 0.387685173336
     12 0.337125356655

2. Maxwell stress tensor near a hole in a metallic plate

Core Library

Accessing the scuff-EM core library from python programs, by Homer Reid
Last Modified: 11/16/16