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


Codes





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
     sys.path.append("/path/to/scuff-em-installation/lib/python2.7/site-packages");
     
     import scuff;
     import numpy.linalg;
     
     # create the geometry, preload the cache 
     G = scuff.RWGGeometry("SphericalShell.scuffgeo");
     scuff.PreloadCache("SphericalShell.cache");
     Omega=0.001;

     # create the incident field 
     PW=scuff.PlaneWave([0,0,1],[1,0,0]);
     
     # read in matrix of eval-point coordinates
     X=scuff.HMatrix("CenterPoint")
     
     # loop over shell permittivity values 
     for Eps in range(2,102,2):
 
        # set shell permittivity 
     	G.SetEps("OuterSphere",Eps);

        # set up and solve the BEM problem
      	M=G.AssembleBEMMatrix(Omega);
      	RHS=G.AssembleRHSVector(Omega, PW);
      	KN=numpy.linalg.solve(M,RHS);

        # 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





scuff-em
Examples
Installation
Core Library
Applications
Reference

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