Download presentation
Presentation is loading. Please wait.
1
From Physical Concept to Software Object: SNS/ARCS Software Workshop Caltech, Dec. 13, 2002 Illustration of a class design process
2
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 A var1 ____ var2 ____ op1( ){ does stuff;} a (object of type A) var1 = 5.227 var2 = “meV” op1( ){does stuff;} Object (1): software entity that can have both data and operations on data.
3
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
4
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”
5
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.
6
CrystalStructureForceConstantList ForceConstantTensor ? Immediate need: object to generate and serve crystal structure information to the rest of the program loop over q space to compute phonon model and i.n.s. cross section CrystalStructure’s neighborhood
7
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…
8
How does CrystalStructure get bonds? 1. Process input data to get bonds Given 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.
9
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
10
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!
11
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?
12
UnitCell UnitCell has additional information about the atomic positions and properties. How do we retain it and make it available? CrystalStructure BondCollection UnitCell Atoms Alternative 1 Dump UnitCell info into CS Crystal Structure BondCollection Atoms Basis Vectors Cell params
13
UnitCell, cont. Alternative 2: UnitCell serves info directly UnitCell Atoms Basis Vectors Cell params CrystalStructure BondCollection loop over q space to compute phonon model and i.n.s. cross section BondServer
14
CrystalStructure BondCollection Alternative 3: Embed UnitCell in CrystalStructure; CS serves UnitCell’s information UnitCell, cont. UnitCell Atoms Basis Vectors Cell params loop over q space to compute phonon model and i.n.s. cross section BondServer
15
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 b c
16
Keep working down the hierarchy Stop when each class clearly represents a single concept Site Atom BasisVector Wyckoff symbol Atom chem symbol mass b coh b inc abs Vector x, y, z Getting to the bottom…
17
Putting it together: UnitCell SiteCollection cell parameters InFirstBZ( ) Site Atom Vector Atom symbol mass b coh b inc abs Vector x, y, z Bond Atom1 Atom2 Vector CrystalStructure BondCollection UnitCell FindBondLengths( ) FillBondCollection( )
18
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…
19
CrystalStructureForceConstantList ForceConstantTensor loop over q space to compute phonon model and i.n.s. cross section...but we’ve started well.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.