Professional Documents
Culture Documents
Verboncoeur1995CPC PDF
Verboncoeur1995CPC PDF
Communications
ELSEVIER Computer Physics Communications 87 (1995) 199-211
Abstract
The object-oriented paradigm provides an opportunity for advanced PIC modeling, increased flexibility, and
extensibility. Particle-in-cell codes for simulating plasmas are traditionally written in structured FORTRAN or C.
This has resulted in large legacy codes which are difficult to maintain and extend with new models. In this ongoing
research, we apply the object-oriented design technique to address these issues. The resulting code architecture,
OOPIC (object-oriented particle-in-cell), is a two-dimensional relativistic electromagnetic PIC code. The object-ori-
ented implementation of the algorithms is described, including an integral-form field solve, and a piecewisc current
deposition and particle position update. The architecture encapsulates key PIC algorithms and data into objects,
simplifying extensions such as new boundary conditions and field algorithms.
parameters, with sufficient error trapping to pre- bility in selecting algorithms and specifying the
vent fatal errors due to improper input. The code properties of the simulation. However, as the
must also protect the casual user from running a number of algorithms required to model complex
simulation with parameters which generate a devices increases, the interactions between algo-
nonphysical result. The second class, the devel- rithms becomes unwieldy.
oper, is more typical of the computational plasma The structured method, while providing lim-
physics research community. The developer must ited modularity, is flawed in addressing many of
often add an algorithm to extend the existing the most pressing problems in the computational
code to model a new phenomenon or adjust an plasma physics area. For example, global vari-
existing model because the problem at hand is ables can be (and usually are) accessed from
sensitive to the accuracy of a particular parame- many modules, making it difficult to track the
ter or method. evolution of data. The structured approach pro-
The requirements for a general plasma physics vides only weak encapsulation, resulting in close
code can be summarized as follows: couplings of unrelated functions which depend on
• Capability to accurately model the physical the internal implementation of other functions.
phenomena of interest. Many side effects can occur when modifying the
• Extensibility and reusability for adding new code for maintenance or extension. The cost of
models or modifying existing models. debugging and maintaining a structured code can
• Encapsulation of algorithms to localize the im- become prohibitive as the complexity of the code
pact of code modifications. increases. The object-oriented technology pro-
• Efficiency of algorithms and architecture, in- vides a solution to this problem through data
cluding optimization of speed and storage. encapsulation.
• Fatal error trapping to prevent user-induced Extending a structured code to include a new
crashes, including unstable regimes of opera- type of model is especially difficult, as many
tion. coupled functions must be rewritten to work with
• Error trapping or warning for simulation the algorithm. Languages such as C and FOR-
regimes characterized by inaccuracy. T R A N provide no mechanism for software exten-
Historically, computational plasma physicists sion via reuse. For example, X-Lab is studying a
have written large codes in structured languages new device which is using a new cesium-impreg-
such as F O R T R A N , and more recently, C (so- nated cathode. This cathode has properties very
called legacy codes 4). These structured programs similar to a cathode presently modeled by the
can contain 10 4 to 10 6 lines of code, excluding existing code in use at X-Lab, except the new
the user interface. Initially, these codes were cathode emits electrons with a distribution func-
written to solve a specific, specialized problem, tion dependent upon the local electric field
and required an expert to run. In many cases, the strength. If the X-Lab code is written in a tradi-
only qualified expert was the code developer. tional structured language, the new model must
More recently, general codes applicable to a fam- be written as a new function, newCathode(). The
ily of similar problems have become available, newCathodeO function will likely consist of some
including M A G I C [2], ISIS [3] and P D x l [4]. code cut and pasted from oldCathodeO, modified
These codes provide limited parameterized flexi- to model the new properties. The argument lists
for the functions are now different, since new-
Cathode() requires the local electric field vector.
Furthermore, the caller must be changed to
4 T h e term legacy codes refers to codes written using tradi- branch to the appropriate function based on a
tional structured techniques, and can often trace their ances- flag and must pass the arguments required. Now
try to the 1960s or 1970s. Maintenance of legacy codes often
consists of patching the existing code; such codes are difficult
errors introduced by the new function call and all
to rewrite because the close coupling of the structured tech- its associated changes may propagate throughout
nique m a y make modular upgrading impossible. the code, resulting in a large amount of time
J.P. Verboncoeur et al. / Computer Physics Communications 87 (1995) 199-211 201
testing and debugging before X-Lab can have tate running the code on massively parallel plat-
confidence in the updated software. Object-ori- forms.
ented technology can reduce this problem using The Plasma Device family of codes [4], PDP1,
polymorphism 5, as described below. PDC1, and PDS1, are written in C with elements
In this paper, we describe an object-oriented of object-oriented design on both the UNIX-Xll
PIC architecture designed to address the issues of and DOS platforms. These codes implement
encapsulation 6, flexibility, extensibility, and effi- polymorphic function calls using pointers to func-
ciency. In Section 2, we discuss several previous tions, and encapsulate behavior by storing func-
attempts to address these issues. In Section 3, an tion pointers within data structures. Since these
object-oriented technique for modeling device codes are implemented in C, argument type
physics is described. In Section 4, we discuss the checking cannot be performed on the 'polymor-
algorithms employed in the OOPIC (object-ori- phic' constructs. This deficiency can be remedied
ented particle-in-cell) code, followed by the archi- using an object-oriented language such as C + +.
tecture and implementation of OOPIC. In Sec- Early attempts at applying object-oriented
tion 6, we summarize the advantages a n d disad- technology to particle-in-cell simulation have re-
vantages of the object-oriented approach and dis- sulted in codes with poor performance compared
cuss future directions of the ongoing research. to traditional codes. Forslund [5] found C + + to
Beyond the scope of this paper, parallel research be a powerful language to translate WAVE, but
is ongoing to develop embedded graphical analy- found disappointing performance compared to a
sis and configuration tools and expert system similar FORTRAN code. One of Forslund's key
tools for assistance in parametric input. objectives was to employ the object-oriented
technique to simplify the parallelization of
WAVE. Forslund compared timings for both op-
2. Background timized and unoptimized code, and found that
the FORTRAN version ran about twice as fast as
Many computational physicists have realized the comparable C + + version. He attributed part
the utility of the object-oriented concept and of the difference to the finer granularity of the
used structured programming languages to C + + representation and the difficulty of opti-
achieve a limited degree of object behavior in mizing such code, and the balance of the differ-
PIC codes. More recently, developers have ence to the greater maturity of FORTRAN com-
adopted mainstream object-oriented languages pilers and libraries. Forslund also noted several
such as C + + and Object Pascal. deficiencies in the C + + specification for his
Several codes are implemented in structured application, particularly with regard to paral-
languages with some elements of object-oriented lelization and linkage to C libraries when using
technology. Eastwood [7] implemented MILO, a templates.
two-dimensional electromagnetic PIC code, in Gisler [8] implemented a particle trajectory
FORTRAN90. MILO decomposes the simulation code using Object Pascal. This code demon-
region into localized blocks, connected by bound- strated flexibility of the object method, choosing
ary conditions which Eastwood terms gluepatches. to represent particles with individual objects. The
The primary purpose of this approach is to facili- low-level representation did not prove a perfor-
mance issue due to the nature of the code; only a
small number of particle trajectories are needed
5 Polymorphism is the ability of an object to respond to a in contrast to particle-in-cell codes which require
standard message with a specialized behavior. For example, a good statistical representation of particles as
the system may send a Paint() message to both circle and
the source term for computing the electromag-
square, without knowing the specific shape it is drawing.
6Encapsulation in this context refers to the isolation of netic fields.
data within objects; the object provides a defined interface to Furnish [9] implemented a one-dimensional
access and manipulate the data. electrostatic PIC code with periodic boundaries
202 J.P. Verboncoeur et aL / Computer Physics Communications 87 (1995) 199-211
rio I
which provides an electron return current and
velocity distribution for a given incident current
and distribution.
The mathematical model may divide the de-
vice into various regimes with different physical
properties which are best described with hetero-
geneous sets of equations. In Fig. 2, the device is
divided into three regions: the emitter (region 1),
the beam circuit (region 2), and the collector
(region 3). This division is useful since the emitter
particms
):"l 1r#r
Values of gridded quantities can be approximated We define a new set of field variables which
at intermediate points by interpolation. Particles encapsulate the mesh metrics:
are discrete representations of some statistical
group of physical particles. Boundaries provide = i f , . di,
the boundary conditions necessary to complete
the equations describing the particles and fields. IQ= f H " dl,
b = f o . dS, (2)
4. Algorithms
--1 r k + l -- rk
We consider the full set of electromagnetic
fields with azimuthal symmetry. Many of the ideas Cr,j,k+l/2 = 2e.rrrk+l/2(Zj+l/2_Zj_l/2) , (4)
for the electromagnetic field representation and 2wr k
-1
solution can trace roots to Langdon [10] and
C4'j'k = e ( r k + 1/2 -- r k - 1 / 2 ) ( Zj + 1/2 -- Z j _ 1 / 2 )
Eastwood [7]. Maxwell's equations in integral
form are written as Similarly, the inductance elements for a nonuni-
form orthogonal Yee mesh in cylindrical z,r co-
sE . d S = f p dV, ordinates in O O P I C are
-- 1 Zj + 1/2 -- Z j _ 1/2
Lzj,k+l/2: /z,rr ( r 2 + 1 _ r2) '
sB- d S = O,
(1) --1 r k + 1/2 -- rk- 1/2 (5)
fE.dl= - fOtB.dS, Lrd+ l/e'k = 2tz'rrrk( zy+ 1 -- zj) '
L-1 _ 2"rrre+l/2
f H" dl = f OtD " d S + f Y " dS. ~,j+l/2,k+l/2-- ]d~(rk+l_rk)(Zj+l_Zj) "
J.P. Verboncoeur et al. / Computer Physics Communications 87 (1995) 199-211 205
-- Iz,j,k+ l/2,
tion has been described extensively; O O P I C em-
Q j , k = £)z,j + 1/2,k -- ~ ) z , j - 1 / 2 , k q- J~r,j,k + 1/2 ploys the relativistic time-centered Boris advance
[1]. The position update occurs in a rotated
- - l~r , j , k - 1/2
Cartesian frame, which eliminates the problem of
where Q = fp d V over the cell volume. The in- large angular displacements near the origin. Bird-
dices refer to locations on the Yee mesh and are sail and Langdon discuss this issue in some detail
ordered in z, r for a right-handed cylindrical [1].
coordinate system. The corresponding transverse We presently use a charge conserving current
electric (TE) set can be written as weighting algorithm, which ensures that Gauss'
law remains satisfied if it was initially satisfied.
Ot JDe,,j,k -~- I~Ir,j + 1 / 2 , k - - I ~ r , j , k + l -- I~Iz,j,k + 1/2 The current weighting is summarized in Fig. 4 for
a particle traversing multiple cells. The net parti-
+ I2Iz,j,k-1/2 - Ie,,j,k, cle motion is decomposed in segments, 6x 1 and
6x2, separated by a cell crossing. The currents for
i), JB r,j + 1 / 2 , k = JE e,,j + 1,k - - JE d~,j,k ,
(7) each segment are deposited independently, so we
i),JBz,j,k + l / 2 = -- JEe,,j,k + l + J~ e,,j,k , describe only the first segment.
Let the initial particle location be x n, and let
0 = l r,j+l/2,k - Br,j-1/2, + B ,j,k+l/2 the final location be x n* for this segment, so
~x 1 = x ~* - x n. Let the particle be location in the
- - JBz,j,k - 1 / 2 "
mesh shown in Fig. 4, where j and k are the cell
The T M and T E field equations are advanced in indices such that Xi, k • (2 or ~) < (x i or x f ) . (~ or
time using a leap frog advance [1]. The source ~) <Xj+l.k+ 1 • (~ or ~). Here, Xj,~ is the location
terms in Eqs. (6) and (7), I, are the currents of the j, k t h node of the mesh.
resulting from charged particle motion. The field Defining w~' = (x ~ - X j , k) .~ and w~ = (x ~ -
algorithms are completed by initial conditions Xj, k)-~, we can write the relations for linearly
and boundary conditions. interpolating the particle charge onto the mesh
nodes:
4.2. Particles Q~,~ = q(1 - w~)(1 - w~),
where q is the particle charge. Defining Aw = This can be achieved by setting the appropriate
w n* - w n and ~ ( w n* -~- w " ) / 2 , we can write
= capacitance matrix element, C, to zero. This al-
the change in charge at each mesh node due to lows the field solve to proceed without testing for
the motion from x n to x n* electric fields or explicitly setting the tangential
AQj,k = Qj~,~ - ojn k
fields to zero along conductors.
The field boundary conditions at the axis in
=q[-Awl(1 -w2) - (1-~1)Aw2], cylindrical coordinates follow directly from
Maxwell's equations. If ~tBz(z, r = 0) is finite,
A Q j + I , k = Q?+ l,k -- Q?+ l,k
then E ¢ ( z , r = 0 ) = 0 . If OtDz(z, r = O ) + J z ( z ,
= q[Awl(1 - - ,Aw2], r = 0) is finite, then H ¢ ( z , r = 0 ) = 0. Finally,
(9) Br(Z , r = 0) is a constant on the axis and OtDr(Z,
A Q j , k + 1 __
-- Q nj ,,k + l __ Q jn, k + l
r = O) = - J r ( z , r = 0).
=q[-Awl~2+(1-~I)AW2], The present incoming and outgoing wave
boundary conditions in O O P I C are incomplete.
AQj'+I,k+I = Q'/~-l,k+l -- Q]+x,k+l
The incoming wave boundary condition simply
= q [ A W l W 2 q- w 1 A w 2 ] . sets the fields to the desired electromagnetic
mode at the boundary of interest, which does not
One set of currents which satisfies conservation
address the outgoing wave at that surface prop-
of charge for the changes given in Eq. (9) is
erly. The outgoing wave boundary condition is a
Ii1+ 1/2,k = qAwl(1 - w 2 ) / A t , surface impedance method. It sets the ratio of
the tangential components of the electric and
ll,y+ 1/2,k + 1 = q A w l w 2 / A t,
magnetic fields to the local surface impedance of
I2,j,k+l/2 = qAw2( 1 - ~ l ) / a t , (10) the boundary medium. This method is amenable
I2,i+ 1,k + 1/2 = q A w 2 w 1 / A t , to attenuation of the high frequency components
by oJ-space reduction of historical field values.
where At is the time for the motion. Note that Particle boundary conditions include absorp-
these currents are not unique; adding a constant tion and transmission. Particles are transmitted
current around the loop formed by the cell edges by symmetry boundaries such as the axis of sym-
also satisfies the continuity equation. One sees metry in cylindrical coordinates. All other bound-
immediately that this current deposition is equiv- aries absorb particles and can optionally emit
alent to the method of Morse and Nielson [11] for secondary electrons.
a single cell particle motion. For multiple cells,
the method described here deposits current in
each cell traversed, in a manner similar to East- 5. Architecture and implementation
wood [13] and Villasenor and Buneman [14].
The code architecture is summarized in Fig. 5
4.3. Boundary conditions and 6. Fig. 5 is a schematic representation of the
flow control for a timestep. A similar flow control
The boundary conditions for fields and parti- diagram can be drawn for the traditional struc-
cles in an electromagnetic PIC code can be di- tured PIC code. After initializing the simulation,
verse and complex. Currently, O O P I C includes the parameters are used to construct the simula-
boundary conditions for the electric fields at the tion. Once constructed, the simulation is ad-
surface of ideal conductors, the cylindrical axis, vanced in discrete units of time.
and incoming and outgoing wave ports. We make The fields are advanced using the field and
no attempt here at a general discussion of elec- source values from previous times, including the
tromagnetic boundary conditions. appropriate boundary conditions. The field ad-
For the ideal conductor, the component of the vance consists of a half timestep advance for B,
electric field tangential to the surface is zero. followed by a full timestep advance for E, fol-
J.P. Verboncoeuret al. / Computer Physics Communications 87 (1995) 199-211 207
one to one asscQabon
lowed by application of the boundary conditions ~-- manyto one assooa~on
for E, and a final half timestep advance for B. I ve=~ I I I O-' aggregate
The half timestep splitting of the magnetic field I V,,~r3 'i'I
advance results in electric and magnetic fields at I "= I
integral timesteps at the end of the field solve, I . ,
while taking advantage of the accuracy of the | I ,~oalJalRegioo r I ~dialRegionldst I
Y
time-centered difference equations. The updated I i ,
fields are then interpolated to the node points of
the mesh from the locations shown in Fig. 3.
Next, the forces on particles are computed by
interpolating the fields to the particle position,
and they are used to update the particle velocity, ! ! I
PO , I I S~m~ I i
and subsequently t h e particle position. The posi-
Y
tion update occurs in conjunction with the depo- ~lemalQmult I c,~aacaJt~s
scalar quantity such as the mass or charge of a message, sent by SpatialRegion, updates the field
particle. Vector2 and Vector3 representation of a equations in time. The translateAccumulate()
scalar quantity such as the mass or charge of a method advances the particle position using
particle. Vector2 and Vector3 represent two- and Grid::differentialMove() and simultaneously de-
three-component vector objects, respectively. The posits the particle current while checking particle
List is a simple yet versatile container class, which boundary conditions as it crosses cell edges. Some
is used for storing singly linked lists as well as may argue that this is a less object-oriented way
stacks of objects. The Maxwellian class represents of updating particle position and current, but the
a maxwellian distribution function, useful for de- performance gain which results from the simulta-
scribing the particle emission properties of a neous operations is substantial since the accumu-
cathode, for example. lation of source current is a performance bottle-
The vector classes provide component storage neck.
as well as overloaded operators and common The Grid class represents the discretization
vector operations such as dot and cross products. mesh for a SpatialRegion. This class stores the
Although other authors, including Furnish [9], positions of the mesh nodes in physical units for
concluded there was little benefit in a vector both nonuniform and nonorthogonal general
class, we find the notation compact and powerful, quadrilaterals. The field algorithms for general
resulting in a more readable and maintainable nonorthogonal quadrilaterals are not yet imple-
code. Care must be exercised in the design of mented in OOPIC. It also stores an array of cell
fundamental classes such as Vector2 and Vector3 edges with boundary conditions. Grid provides
for performance critical situations, particularly the coordinate transformations between logical,
with regard to creation of temporary intermedi- or code, coordinates and physical coordinates us-
ate objects for function return values [15]. ing the methods getMKS() and getGridCoords().
The SpatialRegion class represents a defined The interpolateBilinear() method interpolates a
region of the discrete model. A device can be discrete vector field onto a specified location in
divided into SpatialRegions based on time and the mesh. One could add additional interpolation
space scales as well as for parallel processing or methods to change the order of the splines used
for reduction of the number of empty cells for for particle-grid interactions without affecting
nonrectangular devices. For example, a kiystron the code outside Grid. A number of methods
cavity may force a rectangular mesh to waste provide integrals along grid lines and surface
many cells inside metal. The SpatialRegion pro- integrals used for normalized variables in the
vides a single interface to the objects it "contains". code, enabling the developer to effect a coordi-
Each SpatialRegion has its own Fields and Grid nate system change from within the Grid object
objects. In addition, each has its own list of with minimal impact on the external code. The
boundaries which border the region, Bound- translateO method computes logical coordinates
aryList, and its own list of particles stored in for a relative displacement in physical units using
ParticleGroupList. It stores the local simulation a step-wise cell-intersection method, eliminating
time, and provides a single public interface for the need for a cell search algorithm [16,17] when
advancing all its constituents in time, advance(). the grid is nonuniform or nonorthogonal. The
The advance() message initiates the sequence of differentialMove() method computes a relative
events shown in Fig. 5. physical displacement for a given velocity and
The Fields class represents the electromag- performs a coordinate rotation on the velocity
netic fields on the mesh for a given SpatialRegion. vector in cylindrical coordinates [1].
The fields include electric, magnetic, and current. The ParticleGroup class represents a group of
It can also store the charge density and the scalar similar particles. This class stores the particles in
potential in space. Fields provides a public inter- an array format and stores the common mass,
face to the fields at arbitrary locations using the charge, and numerical particle weighting. This
interpolation capability of Grid. The advance() class provides a number of overloaded add()
J.P. Verboncoeuret aL/ ComputerPhysicsCommunications 87 (1995) 199-211 209
methods for adding new particles to a group, a rithms in each region. Boundary objects store the
gamma( m e t h o d to compute the relativistic mass, location of the boundary condition on the grid,
and an advance() method to advance the equa- the location of the associated Fields object, and a
tions of motion for this ParticleGroup. linked list of the Particle objects associated with
The Particle class describes an individual par- the Boundary. A Particle is attached to a Bound-
title, including its position, m o m e n t u m , mass, ary when it is collected, or when it is queued for
charge, and numerical weight. Particle objects emission. Presently, Boundary objects can apply
provide a flexible mechanism for passing particles three boundary conditions. The applyFields()
between Boundary and ParticleGroup objects. method operates on the electromagnetic fields,
This construct is only used when flexibility out- applying all field-related boundary conditions ex-
weighs p e r f o r m a n c e considerations for a small cept passive boundary conditions. Passive bound-
n u m b e r of particles. ary conditions are only applied at initialization,
The choice of grouping particles based on a and include setting C -1 to zero for conductors.
c o m m o n charge to mass ratio is critical to perfor- The collect() method collects particles which pass
mance; this ratio must be computed for each through the boundary surface, placing them in a
particle to advance the equations of motion each list. The collected particles may be used for diag-
timestep. Both the expense of the division and nostics, transmission to another SpatialRegion,
the cost of accessing the data scale linearly with etc. T h e emit() method emits particles from the
the n u m b e r of particles if grouping is not used. If boundary, including emitting, transmitting, and
stored independently, additional redundant stor- symmetry boundaries. This method uses the same
age for the mass, charge, and numerical weight is mechanism to u p d a t e the particle position as
required, and the noncontiguous m e m o r y loca- ParticleGroup::advance(), ensuring a consistent
tions will neither cache nor vectorize well. Fur- treatment of particle equations of motion and
thermore, if particles are taken as true objects, current deposition.
each must have its own polymorphic advance() The Boundary class is an abstract class which
method, with the consequence of a virtual func- provides a polymorphic base for its derivatives.
tion call per particle per timestep. Note that The Boundary subclasses are shown in Fig. 6.
there are two a p p a r e n t grouping mechanisms The use of inheritance s and polymorphism pro-
which provide the best performance: arrays for vides a significant benefit when implementing
the position, x, and velocity, v; or arrays of a new boundary conditions. We have often mod-
particle object which includes only particle data, eled a new boundary condition in this scheme by
without functions, For the latter, it is critical that adding only a few lines of code, while taking
the particle data is incorporated directly into the advantage of the existing well-tested functional-
object, rather than pointers to the data. A good ity. To add a new boundary condition in O O P I C ,
compiler can optimize references to the data one may overload one or m o r e of the existing
included directly to an offset from the base ad- methods described above and place the boundary
dress of the object, increasing cache hits and object in the boundary list for the appropriate
eliminating further dereferencing. Both grouping SpatialRegion; the applyField(), collect(), and
techniques can provide a p e r f o r m a n c e equivalent
to that of a structured representation such as
multi-dimensional arrays.
s Inheritance enables a derived class (also called subclass or
The Boundary class represents both physical child class) to inherit properties (data) and behaviors (meth-
and logical boundary conditions for fields and ods or functions) from a base class (also called superclass or
particles. Physical boundary conditions include parent class). The derived class may then specialize by adding
conductive walls, waveguide ports, and emitting or modifying properties and behaviors. Inheritance can occur
over many levels forming a hierarchy analogous to the classifi-
surfaces. Logical boundaries refer to boundaries cation hierarchy of biology, with kingdom, phylum, subphy-
placed between SpatialRegions for purposes of lum, ,..., and species. Inheritance from more than one base
separating the regions and localizing the algo- class is called multiple inheritance.
210 J.P. Verboncoeuret al. / Computer Physics Communications 87 (1995) 199-211
e m i t ( ) messages are automatically passed to the present set of models. For example, the Ze-
new boundary object at the proper time. roFieldEmitter class, shown in the O O P I C class
This architecture is implemented in O O P I C hierarchy (Fig. 6), describes a surface which emits
using Borland C + + on the 80x86 PC platform, electrons due to physics quite different from the
with a G U I operating under Windows 3.1 [18]. In B e a m E m i t t e r class, which simply injects a given
addition, X O O P I C is the X l l - b a s e d Unix version current. The difference is analogous to a voltage
written in G N U G + + , using the XGrafix user source versus a current source in an electrical
interface [19]. The physics source code is identi- circuit. Both ZeroFieldEmitter and B e a m E m i t t e r
cal in both cases, making use of inline 9 and are subclasses of the Emitter class and inherit the
virtual 10 functions, inheritance, and templates 11. basic emitter behavior, as well as sharing a com-
There is presently neither exception handling nor mon model for the collection of particles and a
run-time type support in G + + , so these features common boundary condition for the electromag-
have not yet been implemented in OOPIC. netic fields. Thus, only the e m i t ( ) function must
be overloaded, and an appropriate constructor
and destructor code provided. The balance of the
6. C o n c l u s i o n s and future work code does not need to distinguish between spe-
cific Boundary subclasses, using the polymorphic
We have found that one of the principal ad- nature of the design to hide the implementation
vantages of the object-oriented method is the details so all boundaries are treated alike.
potential for rapid extension and enhancement of The notation and operator overloading of
the code. After a design period of about six C + + enables the developer to write a code in a
months, followed by six months of initial develop- notation very similar to the mathematical model.
ment and design revision, we have found that O O P I C was written using vector operations where
adding a new code requires far less effort than possible to reduce the lines of code, with the
testing and verifying the new algorithms. It is consequence of reducing the probability of error
important to note that O O P I C is also serving as a and increasing code readability. The convenient
platform for testing novel electromagnetic PIC encapsulation of objects makes O O P I C resemble
algorithms and techniques, so the effort in testing the physical device much more closely, leading to
the algorithms is usually unrelated to the object- more a intuitive extension and use of the code.
oriented paradigm. We have not yet formally optimized OOPIC,
We are now seeing the payoff of the object- so performance is only addressed in a qualitative
oriented technology in the ease of extending the manner here. However, we believe the code can
achieve the same level of performance as a struc-
tured code. Some object-oriented constructs re-
9Inline functions are functions whose code is placed at the duce the performance, most notably virtual func-
origin of the cell. This eliminates the overhead of a function
tions and the construction of temporaries. Con-
call, improving speed. Note that inline functions often in-
crease the executable image size, although short inline func- versely, standard C + + provides several perfor-
tions can reduce the size when the function code is smaller mance-enhancing features, such as inline func-
than the overhead to set up the stack and call a noninline tions, templates, and reference types for parame-
function. ter passing. We have avoided using virtual func-
lo Virtual functions are C++ mechanisms for providing
polymorphism. Virtual functions are resolved dynamicallyat tions in loops, and we make liberal use of inline
run time by searching a hash table, potentially impacting functions, particularly within looping constructs.
performance. For example, the vector classes are comprised
11 Templates are C++ mechanisms for providing type safety entirely of inline functions, since they have a
for generic classes. For example, OOPIC uses templates to strong impact on performance.
implement linked lists and stacks of such objects as Particles
It is clear to us that object-oriented design is
and Boundaries. Although all lists have the same base code,
templates enforce type checking on list elements to ensure superior for this type of computational code. We
that only the proper data type is used. have developed many PIC codes using the struc-
J.P. Verboncoeur et al. /Computer Physics Communications 87 (1995) 199-211 211
tured programming paradigm, and have found [2] B. Goplen, L. Ludeking, D. Smithe and G. Warren,
that the object-oriented approach results in in- MAGIC Users Manual, Mission Research Corp. report
no. MRC/WDC-R-282, Newington, VA (1991).
creased productivity and code quality. Another [3] K. Birman, R. Cooper, T. Joseph, K. Kane and F.
important facet of a PIC code is the extensibility. Schmuck, The ISIS System Manual, Version 1.2 (1989).
We have found OOPIC to be far easier to extend [4] P D x l (Plasma Device 1 Dimensional, x ={P = planar,
than any of our previous codes due to the reduc- C=cylindrical, S =spherical)}, PDC1, and PDS1 are
tion of interactions and elegance of notation. For available from the Industrial Liason Program, University
of California, Berkeley, CA 94720, soflware@eecs.Berke-
example, adding a slow wave structure consisting ley.EDU (1993).
of three azimuthally symmetric vanes to a cylin- [51 D.W. Forslund, C. Wingate, P. Ford, J. Jackson and S.C.
drical beam-cavity simulation required only three Pope, Experiences in Writing a Distributed Particle Sim-
lines of code to describe the location of each ulation Code in C + + , in: Proc. 1990 USENIX C + +
vane, and the vanes automatically collected parti- Conf. (1990).
[6] J. Rumbaugh, M. Blaha, W. Premerlani, F. Eddy and W.
cles and shorted tangential fields.
Lorensen, Object-Oriented Modeling and Design (Pren-
The primary purpose of this architecture is to tice-Hall, Englewood Cliffs, NJ, 1991).
provide a testbed for new plasma simulation algo- [7] J.W. Eastwood, Finite Element EM PIC, in: Proc. 1st
rithms, making modeling extensions effortless. OOPIC Workshop, Fairfax, V A (1992), unpublished.
Ongoing research includes building the capability [8] G. Gisler, Simulations of Charged Particles in Time
Dependent Electromagnetic Fields Using Object Pro-
to simulate multiple SpatialRegions, consideration
gramming, in: Proc. 1st OOPIC Workshop, Fairfax, VA
of parallel processing issues, and addition of (1992), unpublished.
models for boundary conditions, field solution, [9] G. Furnish and M.G. Gray, Distributed Plasma Simula-
fluid representations, and collisions. Extension of tion Using ESP, in: Proc. 1st OOPIC Workshop, Fairfax,
the present model to Cartesian and r, q5 cylindri- VA (1992), unpublished.
[101 A.B. Langdon, On Enforcing Conservation Laws in Elec-
cal coordinates on nonuniform, nonorthogonal tromagnetic Particle-in-Cell Codes, in: Proc. 14th Int.
body fitted meshes continues; the next logical Conf. Num. Sim. Plasmas, Annapolis, MD (1991).
step is the extension to three dimensions. A [11] K.S. Yee, Numerical solution of initial boundary value
graphical expert system is under development to problems involving Maxwell's equations in isotropic me-
aid the user in configuring and running a simula- dia, IEEE Trans. Antennas Propag. 14 (1966) 302-307.
[121 R.L. Morse and C.W. Nielson, Numerical simulation of
tion, and both real time and postprocess graphics
the Weibel instability in one and two dimensions, Phys.
developments continue. In addition, we continue Fluids 14 (1971) 830-840.
to refine and optimize the architecture. [13] J.W. Eastwood, The virtual particle electromagnetic par-
ticle-mesh method, Comput. Phys. Commun. 64 (1991)
252-266.
Acknowledgements [141 J. Villasenor and O. Buneman, Rigorous charge conser-
vation for local electromagnetic field solvers, Comput.
This research was supported by the Air Force Phys. Commun. 69 (1992) 306-316.
[15] R.M. Adams, Temporary object management through
Office of Scientific Research under grant F49620- dual classes, C Users J. 12 (5) (1994) 27-36.
92-J0487. We gratefully acknowledge the contri- [16] D. Seldner and T. Westermann, Algorithms for interpo-
butions of C.K. Birdsall, W. Peter, K. Cartwright, lation and localization in irregular 2D Meshes, J. Com-
mad P. Mardahl, as well as the contributions of put. Phys. 79 (1988) 1-11.
[17] T. Westermann, Localization schemes in 2D boundary-
our coworkers at George Mason University and
fitted grids, J. Comput. Phys. 101 (1992) 307-313.
FM Technologies. [18] J. Acquah, The OOPIC Visualization & GUI Frame-
work, in: Proc: 4th OOPIC Workshop, Los Gatos, CA
(1994), unpublished.
References [191 V. Vahedi and J.P. Verboncoeur, XGrafix: An X-
Windows Environment for Real-Time Interactive Simula-
[1] C.K. Birdsall and A.B. Langdon, Plasma Physics Via tions, in: Proc. 14th Int. Conf. Num. Sim. Plasmas, An-
Computer Simulation (Adam Hilger, Bristol, 1991). napolis, MD (1991).