Top Banner
From Physical Concept to Software Object: SNS/ARCS Software Workshop Caltech, Dec. 13, 2002 Illustration of a class design process
19

From Physical Concept to Software Object: SNS/ARCS Software Workshop Caltech, Dec. 13, 2002 Illustration of a class design process.

Dec 20, 2015

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: From Physical Concept to Software Object: SNS/ARCS Software Workshop Caltech, Dec. 13, 2002 Illustration of a class design process.

From Physical Concept toSoftware Object:

SNS/ARCS Software Workshop Caltech, Dec. 13, 2002

Illustration of a class design process

Page 2: From Physical Concept to Software 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.

Page 3: From Physical Concept to Software Object: SNS/ARCS Software Workshop Caltech, Dec. 13, 2002 Illustration of a class design process.

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

Page 4: From Physical Concept to Software Object: SNS/ARCS Software Workshop Caltech, Dec. 13, 2002 Illustration of a class design process.

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”

Page 5: From Physical Concept to Software Object: SNS/ARCS Software Workshop Caltech, Dec. 13, 2002 Illustration of a class design process.

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.

Page 6: From Physical Concept to Software Object: SNS/ARCS Software Workshop Caltech, Dec. 13, 2002 Illustration of a class design process.

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

Page 7: From Physical Concept to Software Object: SNS/ARCS Software Workshop Caltech, Dec. 13, 2002 Illustration of a class design process.

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…

Page 8: From Physical Concept to Software Object: SNS/ARCS Software Workshop Caltech, Dec. 13, 2002 Illustration of a class design process.

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.

Page 9: From Physical Concept to Software Object: SNS/ARCS Software Workshop Caltech, Dec. 13, 2002 Illustration of a class design process.

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

Page 10: From Physical Concept to Software Object: SNS/ARCS Software Workshop Caltech, Dec. 13, 2002 Illustration of a class design process.

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!

Page 11: From Physical Concept to Software Object: SNS/ARCS Software Workshop Caltech, Dec. 13, 2002 Illustration of a class design process.

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?

Page 12: From Physical Concept to Software Object: SNS/ARCS Software Workshop Caltech, Dec. 13, 2002 Illustration of a class design process.

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

Page 13: From Physical Concept to Software Object: SNS/ARCS Software Workshop Caltech, Dec. 13, 2002 Illustration of a class design process.

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

Page 14: From Physical Concept to Software Object: SNS/ARCS Software Workshop Caltech, Dec. 13, 2002 Illustration of a class design process.

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

Page 15: From Physical Concept to Software Object: SNS/ARCS Software Workshop Caltech, Dec. 13, 2002 Illustration of a class design process.

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

Page 16: From Physical Concept to Software Object: SNS/ARCS Software Workshop Caltech, Dec. 13, 2002 Illustration of a class design process.

• 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…

Page 17: From Physical Concept to Software Object: SNS/ARCS Software Workshop Caltech, Dec. 13, 2002 Illustration of a class design process.

Putting it together:

UnitCellSiteCollection

cell parametersInFirstBZ( )

SiteAtom

Vector

Atomsymbolmassbcoh

binc

abs

Vectorx, y, z

BondAtom1Atom2Vector

CrystalStructureBondCollection

UnitCellFindBondLengths( )FillBondCollection( )

Page 18: From Physical Concept to Software Object: SNS/ARCS Software Workshop Caltech, Dec. 13, 2002 Illustration of a class design process.

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…

Page 19: From Physical Concept to Software Object: SNS/ARCS Software Workshop Caltech, Dec. 13, 2002 Illustration of a class design process.

CrystalStructure ForceConstantList

ForceConstantTensor

loop over q space to compute

phonon modeland i.n.s.

cross section

...but we’ve started well.