View
215
Download
1
Tags:
Embed Size (px)
Citation preview
From Physical Concept toSoftware Object:
SNS/ARCS Software Workshop Caltech, Dec. 13, 2002
Illustration of a class design process
Two terms:
Class: Blueprint for making objects that model a concept
• specifies what data and what operations• data typically left blank• operations filled in
Object (2): an instance of a class• fills in blanks in blueprint
class Avar1 ____var2 ____op1( ){ does stuff;}
a (object of type A)var1 = 5.227var2 = “meV”op1( ){does stuff;}
Object (1): software entity that can have both data and operations on data.
Basic phonon (atomic vibration) model
Essential inelastic neutron scattering measurement!
For periodic crystal:• Model crystal as balls & springs
• Springs described by force constants
• Finite range forces
Introducing: CrystalStructure
The problem:Compute neutron cross sections from a Born-von Kármán model for an
arbitrary crystal structure.
Immediate need:A class to acquire, store, and serve the crystal structure information needed by
the rest of the computation:
“CrystalStructure”
Design Goals
Modular– Changes to CrystalStructure leave the rest of the program invariant.– Other classes know as little as possible about CS’s internals.
Logical– structure classes to mirror the physics.
Efficient– no extraneous parts.
CrystalStructure ForceConstantList
ForceConstantTensor
?
Immediate need: object to generate and serve crystal structure information to the rest of the program
loop over q space to compute
phonon modeland i.n.s.
cross section
CrystalStructure’s neighborhood
What information does CrystalStructure serve?
Bonds!*
Each bond has:• Two atoms
• A vector from one to the other
Note: no force constant.
*Among other things…
How does CrystalStructure get bonds?
1. Process input data to get bondsGiven how many nearest-neighbor shells (n) and a unit cell, ask• what are the n distances of the nearest neighbors?• which pairs of atoms are at any of those distances?
Inputs needed: UnitCell*, number of shells
*to be defined…
2. Read a file
Result: a collection of bonds.
How do other objects get bonds from CS object?
• Other objects should not know internal details of CrystalStructure
• In particular, the other object (client) should not know how bonds are stored (e.g. array? list? associative array*?)
• But clients will need to get the complete bond collection.
• Offer an interface that hides the implementation
Solution: BondServer
Create a server class that will give one iteration through the collection of bonds
• Guarantee every bond given once
Two piece interface:• IsTheBondContainerEmpty
• GetNextBond
– returns the next bond in the container, and a flag telling if that bond is the last one.
Client: blissfully ignorant!
Downwards!
• Outline of CrystalStructure class known.
• CS knows how to acquire and serve the bond information.
But
• How will CS contain the bonds?
• “Bond contains two atoms”—what is an atom?
• What is UnitCell?
UnitCell
UnitCell has additional information about the atomic positions and properties.
How do we retain it and make it available?
CrystalStructureBondCollection
UnitC
ell
Atoms
Alternative 1Dump UnitCell info into CS
Crystal StructureBondCollection
AtomsBasis VectorsCell params
UnitCell, cont.
Alternative 2:UnitCell serves info directly
UnitCellAtoms
Basis VectorsCell params
CrystalStructureBondCollection
loop over q space to compute
phonon modeland i.n.s.
cross section
BondServer
CrystalStructureBondCollection
Alternative 3:Embed UnitCell in CrystalStructure; CS serves UnitCell’s information
UnitCell, cont.
UnitCellAtoms
Basis VectorsCell params
loop over q space to compute
phonon modeland i.n.s.
cross section
BondServer
What’s in UnitCell?
UnitCell tracks:
• Atoms
• their locations (Vectors)
• cell parameters (a, b, c, angles)
• space group symbol
• ability to tell if a vector is “in the first Brillouin zone”
Sites
More types of objects: Site, Atom, Vector
a
bc
• Keep working down the hierarchy
• Stop when each class clearly represents a single concept
SiteAtom
BasisVectorWyckoff symbol
Atomchem symbol
massbcoh
binc
abs
Vectorx, y, z
Getting to the bottom…
Putting it together:
UnitCellSiteCollection
cell parametersInFirstBZ( )
SiteAtom
Vector
Atomsymbolmassbcoh
binc
abs
Vectorx, y, z
BondAtom1Atom2Vector
CrystalStructureBondCollection
UnitCellFindBondLengths( )FillBondCollection( )
Much more to do…
Implementation: How do we • store bonds? Does each bond have two Atom objects? Pick the relevant bonds?
Interface:• How do clients get UnitCell information from CrystalStructure? Site Info? Atom info?
• How does a user create Atoms, Vectors, Sites, UnitCell? …
Critique:
• Right degree of abstraction?
• Does each object’s name match the concept it models? …
Document design, write code, test, document…