ϕ π ϕ Modeling of Materials with Pythonconference.scipy.org/static/wiki/guyer_fipy.pdfπ ϕ ϕπ...

57
ϕ π ϕ Modeling of Materials with Python J. E. Guyer, D. Wheeler & J. A. Warren www.ctcms.nist.gov/fipy Metallurgy Division & Center for Theoretical and Computational Materials Science Materials Science and Engineering Laboratory

Transcript of ϕ π ϕ Modeling of Materials with Pythonconference.scipy.org/static/wiki/guyer_fipy.pdfπ ϕ ϕπ...

Page 1: ϕ π ϕ Modeling of Materials with Pythonconference.scipy.org/static/wiki/guyer_fipy.pdfπ ϕ ϕπ 1 NIST: Origins “Uniformity in the currency, weights, and measures of the United

!"!"

1

Modeling of Materials with Python

J. E. Guyer, D. Wheeler & J. A. Warren

www.ctcms.nist.gov/fipy

Metallurgy Division &

Center for Theoretical and Computational Materials Science

Materials Science and Engineering Laboratory

Page 2: ϕ π ϕ Modeling of Materials with Pythonconference.scipy.org/static/wiki/guyer_fipy.pdfπ ϕ ϕπ 1 NIST: Origins “Uniformity in the currency, weights, and measures of the United

!"!"

1

NIST: Origins

“Uniformity in the currency, weights, and measures of the United States is an object of great importance, and will, I am persuaded, be duly attended to.”

George Washington, State of the Union Address, 1790

U. S. Constitution, Article I, Section 8

Page 3: ϕ π ϕ Modeling of Materials with Pythonconference.scipy.org/static/wiki/guyer_fipy.pdfπ ϕ ϕπ 1 NIST: Origins “Uniformity in the currency, weights, and measures of the United

!"!"

1

NIST: Origins

National Bureau of Standards Established by Congress in 1901

•Eight different “authoritative’ values for the gallon

•Nascent electrical industry needed standards

•American instruments sent abroad for calibration

•Consumer products and construction materials uneven in quality and unreliable

Na

tional A

rchiv

es

Page 4: ϕ π ϕ Modeling of Materials with Pythonconference.scipy.org/static/wiki/guyer_fipy.pdfπ ϕ ϕπ 1 NIST: Origins “Uniformity in the currency, weights, and measures of the United

!"!"

1

NIST: Rigorous and Objective

Page 5: ϕ π ϕ Modeling of Materials with Pythonconference.scipy.org/static/wiki/guyer_fipy.pdfπ ϕ ϕπ 1 NIST: Origins “Uniformity in the currency, weights, and measures of the United

!"!"

1

NIST: World-Class Staff

Eric Cornell2001 Nobel Prize

in Physics

John Cahn1998 National Medal of

Science

Debbie Jin2003 MacArthur Fellowship

Bill Phillips1997 Nobel Prize

in Physics

Jan Hall2005 Nobel Prize

in Physics

Anneke Sengers 2003 L’Oréal-UNESCO

Women in Science Award

Page 6: ϕ π ϕ Modeling of Materials with Pythonconference.scipy.org/static/wiki/guyer_fipy.pdfπ ϕ ϕπ 1 NIST: Origins “Uniformity in the currency, weights, and measures of the United

!"!"

1

NIST: Trusted Investigator

Great Baltimore Fire,1904

Silver Bridge Collapse, 1967

World Trade Center Collapse 9/11/2001

Page 7: ϕ π ϕ Modeling of Materials with Pythonconference.scipy.org/static/wiki/guyer_fipy.pdfπ ϕ ϕπ 1 NIST: Origins “Uniformity in the currency, weights, and measures of the United

!"!"

1

NIST: Today !2900 employees

!2600 associates and facilities users

!1600 field staff in partner organizations

!400 NIST staff serving on 1000 national and

international standards committees

Gaithersburg, MD

Courtesy HDR Architecture, Inc./Steve Hall ©Hedrich Blessing

Boulder, CO

©Geoffrey Wheeler

!100 Standard Reference Data sets!1300 Standard Reference Materials!16000 calibration tests per year!800 accreditations per year

Page 8: ϕ π ϕ Modeling of Materials with Pythonconference.scipy.org/static/wiki/guyer_fipy.pdfπ ϕ ϕπ 1 NIST: Origins “Uniformity in the currency, weights, and measures of the United

!"!"

1

Materials Science

Processing Structure Properties

Page 9: ϕ π ϕ Modeling of Materials with Pythonconference.scipy.org/static/wiki/guyer_fipy.pdfπ ϕ ϕπ 1 NIST: Origins “Uniformity in the currency, weights, and measures of the United

!"!"

1

Materials Science

Processing Structure Properties

Performance

Page 10: ϕ π ϕ Modeling of Materials with Pythonconference.scipy.org/static/wiki/guyer_fipy.pdfπ ϕ ϕπ 1 NIST: Origins “Uniformity in the currency, weights, and measures of the United

!"!"

1

Materials And Models

Atomic scale Micro scale Component scale

2 nm

Millimeter scale

Page 11: ϕ π ϕ Modeling of Materials with Pythonconference.scipy.org/static/wiki/guyer_fipy.pdfπ ϕ ϕπ 1 NIST: Origins “Uniformity in the currency, weights, and measures of the United

!"!"

1

Materials And Models

Atomic scale Micro scale Component scale

2 nm

Millimeter scale

Page 12: ϕ π ϕ Modeling of Materials with Pythonconference.scipy.org/static/wiki/guyer_fipy.pdfπ ϕ ϕπ 1 NIST: Origins “Uniformity in the currency, weights, and measures of the United

!"!"

1

Modeling is the basis of Measurement Science

Electronic Properties

Heat and Energy

Strength

Diffusion

Page 13: ϕ π ϕ Modeling of Materials with Pythonconference.scipy.org/static/wiki/guyer_fipy.pdfπ ϕ ϕπ 1 NIST: Origins “Uniformity in the currency, weights, and measures of the United

!"!"

1

Modeling is the basis of Measurement Science

Electronic Properties

Heat and Energy

Strength

DiffusionV = IR

dE = TdS ! PdV + µdN

!ij = Cijkl"kl

!c

!t= D

!2c

!x2

Page 14: ϕ π ϕ Modeling of Materials with Pythonconference.scipy.org/static/wiki/guyer_fipy.pdfπ ϕ ϕπ 1 NIST: Origins “Uniformity in the currency, weights, and measures of the United

!"!"

1

Center for Theoretical and Computational Materials Science

Provides the infrastructure for Theory, Modeling and Simulation in MSEL

• By providing hardware, and a collaborative work environment (space)

• By developing new measurement paradigms using simulation and theory

• By encouraging the development of software tools, both for internal use and to aid in the dissemination of existing results

Page 15: ϕ π ϕ Modeling of Materials with Pythonconference.scipy.org/static/wiki/guyer_fipy.pdfπ ϕ ϕπ 1 NIST: Origins “Uniformity in the currency, weights, and measures of the United

!"!"

1

Why a common code?

•PDEs are ubiquitous in materials science

•Many codes for solving materials science problems at NIST

•Dissemination to other researchers is “difficult”

Page 16: ϕ π ϕ Modeling of Materials with Pythonconference.scipy.org/static/wiki/guyer_fipy.pdfπ ϕ ϕπ 1 NIST: Origins “Uniformity in the currency, weights, and measures of the United

!"!"

1

Why a common code?

•PDEs are ubiquitous in materials science

•Many codes for solving materials science problems at NIST

•Dissemination to other researchers is “difficult”

Page 17: ϕ π ϕ Modeling of Materials with Pythonconference.scipy.org/static/wiki/guyer_fipy.pdfπ ϕ ϕπ 1 NIST: Origins “Uniformity in the currency, weights, and measures of the United

!"!"

1

Why Scripting?

• hard-code

: :common /params/temperature,steps,tolerance,…

data temperature,steps,tolerance/273.15,10000,1.d-3,…/ : :

Page 18: ϕ π ϕ Modeling of Materials with Pythonconference.scipy.org/static/wiki/guyer_fipy.pdfπ ϕ ϕπ 1 NIST: Origins “Uniformity in the currency, weights, and measures of the United

!"!"

1

Why Scripting?

• hard-code

: :common /params/temperature,steps,tolerance,…

data temperature,steps,tolerance/273.15,10000,1.d-3,…/ : :

• batch file

273.15100001.d-3 : :

Page 19: ϕ π ϕ Modeling of Materials with Pythonconference.scipy.org/static/wiki/guyer_fipy.pdfπ ϕ ϕπ 1 NIST: Origins “Uniformity in the currency, weights, and measures of the United

!"!"

1

Why Scripting?

• hard-code

: :common /params/temperature,steps,tolerance,…

data temperature,steps,tolerance/273.15,10000,1.d-3,…/ : :

• batch file

273.15100001.d-3 : :

• comment character

273.15 # temperature (K)10000 # steps1.d-3 # tolerance : :

Page 20: ϕ π ϕ Modeling of Materials with Pythonconference.scipy.org/static/wiki/guyer_fipy.pdfπ ϕ ϕπ 1 NIST: Origins “Uniformity in the currency, weights, and measures of the United

!"!"

1

Finite Volume Method•Solve a general PDE on a given domain for a field !

!

"""""#

a11 a12

a21 a22. . .

. . . . . . . . .. . . ann

$

%%%%%&

!

"""#

!1

!2...

!n

$

%%%&=

!

"""#

b1

b2...

bn

$

%%%&

"(#!)"t' () *

transient

+! · ($u!)' () *convection

= ! · (!!!)' () *di!usion

+ S!'()*source

+

V

"(#!)"t

dV

' () *transient

++

S($n · $u)! dS

' () *convection

=+

S!($n ·!!) dS

' () *di!usion

++

VS! dV

' () *source

#!V " (#!V )old

"t' () *

transient

+,

face

[($n · $u)A!]face' () *

convection

=,

face

[!A$n ·!!]face' () *

di!usion

+ V S!

'()*source

1

domain

!("#)!t! "# $

transient

! [" · (!i")]n#! "# $

di!usion

! " · ($u#)! "# $convection

! S!

!"#$source

= 0

%

V

!("#)!t

dV

! "# $transient

!%

S!n($n ·" {· · · }) dS

! "# $di!usion

!%

S($n · $u)# dS

! "# $convection

!%

VS! dV

! "# $source

= 0

"#V ! ("#V )old

"t! "# $

transient

!&

face

[!nA$n ·" {· · · }]face! "# $

di!usion

!&

face

[($n · $u)A#]face! "# $

convection

! V S!

!"#$source

= 0

4

Page 21: ϕ π ϕ Modeling of Materials with Pythonconference.scipy.org/static/wiki/guyer_fipy.pdfπ ϕ ϕπ 1 NIST: Origins “Uniformity in the currency, weights, and measures of the United

!"!"

1

Finite Volume Method•Solve a general PDE on a given domain for a field

•Integrate PDE over arbitrary control volumes

!!

"""""#

a11 a12

a21 a22. . .

. . . . . . . . .. . . ann

$

%%%%%&

!

"""#

!1

!2...

!n

$

%%%&=

!

"""#

b1

b2...

bn

$

%%%&

"(#!)"t' () *

transient

+! · ($u!)' () *convection

= ! · (!!!)' () *di!usion

+ S!'()*source

+

V

"(#!)"t

dV

' () *transient

++

S($n · $u)! dS

' () *convection

=+

S!($n ·!!) dS

' () *di!usion

++

VS! dV

' () *source

#!V " (#!V )old

"t' () *

transient

+,

face

[($n · $u)A!]face' () *

convection

=,

face

[!A$n ·!!]face' () *

di!usion

+ V S!

'()*source

1

controlvolume

!("#)!t! "# $

transient

! [" · (!i")]n#! "# $

di!usion

! " · ($u#)! "# $convection

! S!

!"#$source

= 0

%

V

!("#)!t

dV

! "# $transient

!%

S!n($n ·" {· · · }) dS

! "# $di!usion

!%

S($n · $u)# dS

! "# $convection

!%

VS! dV

! "# $source

= 0

"#V ! ("#V )old

"t! "# $

transient

!&

face

[!nA$n ·" {· · · }]face! "# $

di!usion

!&

face

[($n · $u)A#]face! "# $

convection

! V S!

!"#$source

= 0

4

Page 22: ϕ π ϕ Modeling of Materials with Pythonconference.scipy.org/static/wiki/guyer_fipy.pdfπ ϕ ϕπ 1 NIST: Origins “Uniformity in the currency, weights, and measures of the United

!"!"

1

Finite Volume Method•Solve a general PDE on a given domain for a field

•Integrate PDE over arbitrary control volumes

•Evaluate PDE over polyhedral control volumes

!!

"""""#

a11 a12

a21 a22. . .

. . . . . . . . .. . . ann

$

%%%%%&

!

"""#

!1

!2...

!n

$

%%%&=

!

"""#

b1

b2...

bn

$

%%%&

"(#!)"t' () *

transient

+! · ($u!)' () *convection

= ! · (!!!)' () *di!usion

+ S!'()*source

+

V

"(#!)"t

dV

' () *transient

++

S($n · $u)! dS

' () *convection

=+

S!($n ·!!) dS

' () *di!usion

++

VS! dV

' () *source

#!V " (#!V )old

"t' () *

transient

+,

face

[($n · $u)A!]face' () *

convection

=,

face

[!A$n ·!!]face' () *

di!usion

+ V S!

'()*source

1

face

cell

vertex

!("#)!t! "# $

transient

! [" · (!i")]n#! "# $

di!usion

! " · ($u#)! "# $convection

! S!

!"#$source

= 0

%

V

!("#)!t

dV

! "# $transient

!%

S!n($n ·" {· · · }) dS

! "# $di!usion

!%

S($n · $u)# dS

! "# $convection

!%

VS! dV

! "# $source

= 0

"#V ! ("#V )old

"t! "# $

transient

!&

face

[!nA$n ·" {· · · }]face! "# $

di!usion

!&

face

[($n · $u)A#]face! "# $

convection

! V S!

!"#$source

= 0

4

Page 23: ϕ π ϕ Modeling of Materials with Pythonconference.scipy.org/static/wiki/guyer_fipy.pdfπ ϕ ϕπ 1 NIST: Origins “Uniformity in the currency, weights, and measures of the United

!"!"

1

Finite Volume Method•Solve a general PDE on a given domain for a field

•Integrate PDE over arbitrary control volumes

•Evaluate PDE over polyhedral control volumes

•Obtain a large coupled set of linear equations in

!!

"""""#

a11 a12

a21 a22. . .

. . . . . . . . .. . . ann

$

%%%%%&

!

"""#

!1

!2...

!n

$

%%%&=

!

"""#

b1

b2...

bn

$

%%%&

"(#!)"t' () *

transient

+! · ($u!)' () *convection

= ! · (!!!)' () *di!usion

+ S!'()*source

+

V

"(#!)"t

dV

' () *transient

++

S($n · $u)! dS

' () *convection

=+

S!($n ·!!) dS

' () *di!usion

++

VS! dV

' () *source

#!V " (#!V )old

"t' () *

transient

+,

face

[($n · $u)A!]face' () *

convection

=,

face

[!A$n ·!!]face' () *

di!usion

+ V S!

'()*source

1

!!

"""""#

a11 a12

a21 a22. . .

. . . . . . . . .. . . ann

$

%%%%%&

!

"""#

!1

!2...

!n

$

%%%&=

!

"""#

b1

b2...

bn

$

%%%&

"(#!)"t' () *

transient

+! · ($u!)' () *convection

= ! · (!!!)' () *di!usion

+ S!'()*source

+

V

"(#!)"t

dV

' () *transient

++

S($n · $u)! dS

' () *convection

=+

S!($n ·!!) dS

' () *di!usion

++

VS! dV

' () *source

#!V " (#!V )old

"t' () *

transient

+,

face

[($n · $u)A!]face' () *

convection

=,

face

[!A$n ·!!]face' () *

di!usion

+ V S!

'()*source

1

!!

"""""#

a11 a12

a21 a22. . .

. . . . . . . . .. . . ann

$

%%%%%&

!

"""#

!1

!2...

!n

$

%%%&=

!

"""#

b1

b2...

bn

$

%%%&

"(#!)"t' () *

transient

+! · ($u!)' () *convection

= ! · (!!!)' () *di!usion

+ S!'()*source

+

V

"(#!)"t

dV

' () *transient

++

S($n · $u)! dS

' () *convection

=+

S!($n ·!!) dS

' () *di!usion

++

VS! dV

' () *source

#!V " (#!V )old

"t' () *

transient

+,

face

[($n · $u)A!]face' () *

convection

=,

face

[!A$n ·!!]face' () *

di!usion

+ V S!

'()*source

1

Page 24: ϕ π ϕ Modeling of Materials with Pythonconference.scipy.org/static/wiki/guyer_fipy.pdfπ ϕ ϕπ 1 NIST: Origins “Uniformity in the currency, weights, and measures of the United

!"!"

1

Cahn-Hilliard Example

!"

!t!" · D"

!!f

!"! #2"2"

"= 0

f =a2

2"2(1! ")2

$n ·"" = 0 on all boundaries

$n ·"3" = 0 on all boundaries

!"

!t#$%&transient

!" · Da2 [1! 6" (1! ")]""# $% &

2nd order di!usion

+ " · D"#2"2"# $% &4th order di!usion

= 0

!"

!t= " · D"

!!f

!"! #2"2"

"

f =a2

2"2(1! ")2

$n ·"" = 0 on all boundaries

$n ·"3" = 0 on all boundaries

!"

!t#$%&transient

= " · Da2 [1! 6" (1! ")]""# $% &

2nd order di!usion

! " · D"#2"2"# $% &4th order di!usion

3

!"

!t!" · D"

!!f

!"! #2"2"

"= 0

f =a2

2"2(1! ")2

$n ·"" = 0 on all boundaries

$n ·"3" = 0 on all boundaries

!"

!t#$%&transient

!" · Da2 [1! 6" (1! ")]""# $% &

2nd order di!usion

+ " · D"#2"2"# $% &4th order di!usion

= 0

!"

!t= " · D"

!!f

!"! #2"2"

"

f =a2

2"2(1! ")2

$n ·"" = 0 on all boundaries

$n ·"3" = 0 on all boundaries

!"

!t#$%&transient

= " · Da2 [1! 6" (1! ")]""# $% &

2nd order di!usion

! " · D"#2"2"# $% &4th order di!usion

3

Page 25: ϕ π ϕ Modeling of Materials with Pythonconference.scipy.org/static/wiki/guyer_fipy.pdfπ ϕ ϕπ 1 NIST: Origins “Uniformity in the currency, weights, and measures of the United

!"!"

1

Cahn-Hilliard Example

from fipy import *

mesh = Grid2D(nx=1000, ny=1000, dx=0.25, dy=0.25)

phi = CellVariable(name=r"$\phi$", mesh=mesh)

phi.setValue(GaussianNoiseVariable(mesh=mesh,

mean=0.5,

variance=0.01))

PHI = phi.getArithmeticFaceValue()

D = a = epsilon = 1.

eq = (TransientTerm()

== DiffusionTerm(coeff=D * a**2 * (1 - 6 * PHI * (1 - PHI)))

- DiffusionTerm(coeff=(D, epsilon**2)))

viewer = Viewer(vars=(phi,), datamin=0., datamax=1.)

dexp = -5

elapsed = 0.

while elapsed < 1000.:

dt = min(100, exp(dexp))

elapsed += dt

dexp += 0.01

eq.solve(phi, dt=dt)

viewer.plot()

!"

!t!" · D"

!!f

!"! #2"2"

"= 0

f =a2

2"2(1! ")2

$n ·"" = 0 on all boundaries

$n ·"3" = 0 on all boundaries

!"

!t#$%&transient

!" · Da2 [1! 6" (1! ")]""# $% &

2nd order di!usion

+ " · D"#2"2"# $% &4th order di!usion

= 0

!"

!t= " · D"

!!f

!"! #2"2"

"

f =a2

2"2(1! ")2

$n ·"" = 0 on all boundaries

$n ·"3" = 0 on all boundaries

!"

!t#$%&transient

= " · Da2 [1! 6" (1! ")]""# $% &

2nd order di!usion

! " · D"#2"2"# $% &4th order di!usion

3

Page 26: ϕ π ϕ Modeling of Materials with Pythonconference.scipy.org/static/wiki/guyer_fipy.pdfπ ϕ ϕπ 1 NIST: Origins “Uniformity in the currency, weights, and measures of the United

!"!"

1

Cahn-Hilliard Example

from fipy import *

mesh = Grid2D(nx=1000, ny=1000, dx=0.25, dy=0.25)

phi = CellVariable(name=r"$\phi$", mesh=mesh)

phi.setValue(GaussianNoiseVariable(mesh=mesh,

mean=0.5,

variance=0.01))

PHI = phi.getArithmeticFaceValue()

D = a = epsilon = 1.

eq = (TransientTerm()

== DiffusionTerm(coeff=D * a**2 * (1 - 6 * PHI * (1 - PHI)))

- DiffusionTerm(coeff=(D, epsilon**2)))

viewer = Viewer(vars=(phi,), datamin=0., datamax=1.)

dexp = -5

elapsed = 0.

while elapsed < 1000.:

dt = min(100, exp(dexp))

elapsed += dt

dexp += 0.01

eq.solve(phi, dt=dt)

viewer.plot()

!"

!t!" · D"

!!f

!"! #2"2"

"= 0

f =a2

2"2(1! ")2

$n ·"" = 0 on all boundaries

$n ·"3" = 0 on all boundaries

!"

!t#$%&transient

!" · Da2 [1! 6" (1! ")]""# $% &

2nd order di!usion

+ " · D"#2"2"# $% &4th order di!usion

= 0

!"

!t= " · D"

!!f

!"! #2"2"

"

f =a2

2"2(1! ")2

$n ·"" = 0 on all boundaries

$n ·"3" = 0 on all boundaries

!"

!t#$%&transient

= " · Da2 [1! 6" (1! ")]""# $% &

2nd order di!usion

! " · D"#2"2"# $% &4th order di!usion

3

Page 27: ϕ π ϕ Modeling of Materials with Pythonconference.scipy.org/static/wiki/guyer_fipy.pdfπ ϕ ϕπ 1 NIST: Origins “Uniformity in the currency, weights, and measures of the United

!"!"

1

Cahn-Hilliard Example

!"

!t!" · D"

!!f

!"! #2"2"

"= 0

f =a2

2"2(1! ")2

$n ·"" = 0 on all boundaries

$n ·"3" = 0 on all boundaries

!"

!t#$%&transient

!" · Da2 [1! 6" (1! ")]""# $% &

2nd order di!usion

+ " · D"#2"2"# $% &4th order di!usion

= 0

!"

!t= " · D"

!!f

!"! #2"2"

"

f =a2

2"2(1! ")2

$n ·"" = 0 on all boundaries

$n ·"3" = 0 on all boundaries

!"

!t#$%&transient

= " · Da2 [1! 6" (1! ")]""# $% &

2nd order di!usion

! " · D"#2"2"# $% &4th order di!usion

3

Page 28: ϕ π ϕ Modeling of Materials with Pythonconference.scipy.org/static/wiki/guyer_fipy.pdfπ ϕ ϕπ 1 NIST: Origins “Uniformity in the currency, weights, and measures of the United

!"!"

1

Cahn-Hilliard Example

!"

!t!" · D"

!!f

!"! #2"2"

"= 0

f =a2

2"2(1! ")2

$n ·"" = 0 on all boundaries

$n ·"3" = 0 on all boundaries

!"

!t#$%&transient

!" · Da2 [1! 6" (1! ")]""# $% &

2nd order di!usion

+ " · D"#2"2"# $% &4th order di!usion

= 0

!"

!t= " · D"

!!f

!"! #2"2"

"

f =a2

2"2(1! ")2

$n ·"" = 0 on all boundaries

$n ·"3" = 0 on all boundaries

!"

!t#$%&transient

= " · Da2 [1! 6" (1! ")]""# $% &

2nd order di!usion

! " · D"#2"2"# $% &4th order di!usion

3

mesh = Grid2D(nx=1000, ny=1000, dx=0.25, dy=0.25)

mesh = GmshImporter2DIn3DSpace("""

radius = 5.0;

cellSize = 0.3;

// create inner 1/8 shell

Point(1) = {0, 0, 0, cellSize};

Point(2) = {-radius, 0, 0, cellSize};

Point(3) = {0, radius, 0, cellSize};

Point(4) = {0, 0, radius, cellSize};

Circle(1) = {2, 1, 3};

Circle(2) = {4, 1, 2};

Circle(3) = {4, 1, 3};

Line Loop(1) = {1, -3, 2} ;

Ruled Surface(1) = {1};

// create remaining 7/8 inner shells

t1[] = Rotate {{0,0,1},{0,0,0},Pi/2} {Duplicata{Surface{1};}};

t2[] = Rotate {{0,0,1},{0,0,0},Pi} {Duplicata{Surface{1};}};

t3[] = Rotate {{0,0,1},{0,0,0},Pi*3/2} {Duplicata{Surface{1};}};

t4[] = Rotate {{0,1,0},{0,0,0},-Pi/2} {Duplicata{Surface{1};}};

t5[] = Rotate {{0,0,1},{0,0,0},Pi/2} {Duplicata{Surface{t4[0]};}};

t6[] = Rotate {{0,0,1},{0,0,0},Pi} {Duplicata{Surface{t4[0]};}};

t7[] = Rotate {{0,0,1},{0,0,0},Pi*3/2} {Duplicata{Surface{t4[0]};}};

// create entire inner and outer shell

Surface Loop(100)={1,t1[0],t2[0],t3[0],t7[0],t4[0],t5[0],t6[0]};

""").extrude(extrudeFunc=lambda r: 1.1 * r)

Page 29: ϕ π ϕ Modeling of Materials with Pythonconference.scipy.org/static/wiki/guyer_fipy.pdfπ ϕ ϕπ 1 NIST: Origins “Uniformity in the currency, weights, and measures of the United

!"!"

1

Cahn-Hilliard Example

!"

!t!" · D"

!!f

!"! #2"2"

"= 0

f =a2

2"2(1! ")2

$n ·"" = 0 on all boundaries

$n ·"3" = 0 on all boundaries

!"

!t#$%&transient

!" · Da2 [1! 6" (1! ")]""# $% &

2nd order di!usion

+ " · D"#2"2"# $% &4th order di!usion

= 0

!"

!t= " · D"

!!f

!"! #2"2"

"

f =a2

2"2(1! ")2

$n ·"" = 0 on all boundaries

$n ·"3" = 0 on all boundaries

!"

!t#$%&transient

= " · Da2 [1! 6" (1! ")]""# $% &

2nd order di!usion

! " · D"#2"2"# $% &4th order di!usion

3

mesh = Grid2D(nx=1000, ny=1000, dx=0.25, dy=0.25)

mesh = GmshImporter2DIn3DSpace("""

radius = 5.0;

cellSize = 0.3;

// create inner 1/8 shell

Point(1) = {0, 0, 0, cellSize};

Point(2) = {-radius, 0, 0, cellSize};

Point(3) = {0, radius, 0, cellSize};

Point(4) = {0, 0, radius, cellSize};

Circle(1) = {2, 1, 3};

Circle(2) = {4, 1, 2};

Circle(3) = {4, 1, 3};

Line Loop(1) = {1, -3, 2} ;

Ruled Surface(1) = {1};

// create remaining 7/8 inner shells

t1[] = Rotate {{0,0,1},{0,0,0},Pi/2} {Duplicata{Surface{1};}};

t2[] = Rotate {{0,0,1},{0,0,0},Pi} {Duplicata{Surface{1};}};

t3[] = Rotate {{0,0,1},{0,0,0},Pi*3/2} {Duplicata{Surface{1};}};

t4[] = Rotate {{0,1,0},{0,0,0},-Pi/2} {Duplicata{Surface{1};}};

t5[] = Rotate {{0,0,1},{0,0,0},Pi/2} {Duplicata{Surface{t4[0]};}};

t6[] = Rotate {{0,0,1},{0,0,0},Pi} {Duplicata{Surface{t4[0]};}};

t7[] = Rotate {{0,0,1},{0,0,0},Pi*3/2} {Duplicata{Surface{t4[0]};}};

// create entire inner and outer shell

Surface Loop(100)={1,t1[0],t2[0],t3[0],t7[0],t4[0],t5[0],t6[0]};

""").extrude(extrudeFunc=lambda r: 1.1 * r)

Page 30: ϕ π ϕ Modeling of Materials with Pythonconference.scipy.org/static/wiki/guyer_fipy.pdfπ ϕ ϕπ 1 NIST: Origins “Uniformity in the currency, weights, and measures of the United

!"!"

1

compare, e.g.,youtube.com/watch?v=kDsFP67_ZSE

Cahn-Hilliard Example

!"

!t!" · D"

!!f

!"! #2"2"

"= 0

f =a2

2"2(1! ")2

$n ·"" = 0 on all boundaries

$n ·"3" = 0 on all boundaries

!"

!t#$%&transient

!" · Da2 [1! 6" (1! ")]""# $% &

2nd order di!usion

+ " · D"#2"2"# $% &4th order di!usion

= 0

!"

!t= " · D"

!!f

!"! #2"2"

"

f =a2

2"2(1! ")2

$n ·"" = 0 on all boundaries

$n ·"3" = 0 on all boundaries

!"

!t#$%&transient

= " · Da2 [1! 6" (1! ")]""# $% &

2nd order di!usion

! " · D"#2"2"# $% &4th order di!usion

3

mesh = Grid2D(nx=1000, ny=1000, dx=0.25, dy=0.25)

mesh = GmshImporter2DIn3DSpace("""

radius = 5.0;

cellSize = 0.3;

// create inner 1/8 shell

Point(1) = {0, 0, 0, cellSize};

Point(2) = {-radius, 0, 0, cellSize};

Point(3) = {0, radius, 0, cellSize};

Point(4) = {0, 0, radius, cellSize};

Circle(1) = {2, 1, 3};

Circle(2) = {4, 1, 2};

Circle(3) = {4, 1, 3};

Line Loop(1) = {1, -3, 2} ;

Ruled Surface(1) = {1};

// create remaining 7/8 inner shells

t1[] = Rotate {{0,0,1},{0,0,0},Pi/2} {Duplicata{Surface{1};}};

t2[] = Rotate {{0,0,1},{0,0,0},Pi} {Duplicata{Surface{1};}};

t3[] = Rotate {{0,0,1},{0,0,0},Pi*3/2} {Duplicata{Surface{1};}};

t4[] = Rotate {{0,1,0},{0,0,0},-Pi/2} {Duplicata{Surface{1};}};

t5[] = Rotate {{0,0,1},{0,0,0},Pi/2} {Duplicata{Surface{t4[0]};}};

t6[] = Rotate {{0,0,1},{0,0,0},Pi} {Duplicata{Surface{t4[0]};}};

t7[] = Rotate {{0,0,1},{0,0,0},Pi*3/2} {Duplicata{Surface{t4[0]};}};

// create entire inner and outer shell

Surface Loop(100)={1,t1[0],t2[0],t3[0],t7[0],t4[0],t5[0],t6[0]};

""").extrude(extrudeFunc=lambda r: 1.1 * r)

Page 31: ϕ π ϕ Modeling of Materials with Pythonconference.scipy.org/static/wiki/guyer_fipy.pdfπ ϕ ϕπ 1 NIST: Origins “Uniformity in the currency, weights, and measures of the United

!"!"

1

Kirkendall effect

Heumann & Ruth © IWF, Göttingen 1986

Cu Sb

Page 32: ϕ π ϕ Modeling of Materials with Pythonconference.scipy.org/static/wiki/guyer_fipy.pdfπ ϕ ϕπ 1 NIST: Origins “Uniformity in the currency, weights, and measures of the United

!"!"

1

Kirkendall effect‘expanding case’

(m) X!!B = 0.92 (n) X!!

B = 0.98

‘squeezing case’

(o) X!!B = 0.92 (p) X!!

B = 0.98

‘expanding case’

!5 !4 !3 !2 !1 0 1 2 3 4 50

0.2

0.4

0.6

0.8

1

z ( µm)

t/

(10

4 s

)(i) X!!

B = 0.92

!5 !4 !3 !2 !1 0 1 2 3 4 50

0.2

0.4

0.6

0.8

1

z ( µm)

t/

(10

4 s

)

(j) X!!B = 0.98

‘squeezing case’

!5 !4 !3 !2 !1 0 1 2 3 4 50

0.2

0.4

0.6

0.8

1

z ( µm)

t/

(10

4 s

)

(k) X!!B = 0.92

!5 !4 !3 !2 !1 0 1 2 3 4 50

0.2

0.4

0.6

0.8

1

z ( µm)

t/

(10

4 s

)

(l) X!!B = 0.98

W. J. Boettinger, J. E. Guyer, C. E. Campbell & G. B. McFadden,

Proceedings of the Royal Society A: Mathematical 463 (2007) 3347–3373

Cahn-Hilliard treatment

both Eulerian and Lagrangian

compared with sharp interface similarity solution

and DICTRA calculations

!XB

!t=

!

!z

!M̃(XB)

!

!z

"!!(XB !XA) + RT (lnXB ! lnXA)! 2K

!2XB

!z2

#$

v(z, t) = XAXB [MB !MA]!

!z

!!!(XB !XA) + RT (lnXB ! lnXA)! 2K

!2XB

!z2

"

!Z(z, t)!t

= !v!Z(z, t)

!z

M̃ = XAXB [XBMA + XAMB ]MA = M0[!1(1!XB) + !2XB ]MB = M0[!2(1!XB) + !1XB ]

Page 33: ϕ π ϕ Modeling of Materials with Pythonconference.scipy.org/static/wiki/guyer_fipy.pdfπ ϕ ϕπ 1 NIST: Origins “Uniformity in the currency, weights, and measures of the United

!"!"

1

Kirkendall effect‘expanding case’

(m) X!!B = 0.92 (n) X!!

B = 0.98

‘squeezing case’

(o) X!!B = 0.92 (p) X!!

B = 0.98

‘expanding case’

!5 !4 !3 !2 !1 0 1 2 3 4 50

0.2

0.4

0.6

0.8

1

z ( µm)

t/

(10

4 s

)(i) X!!

B = 0.92

!5 !4 !3 !2 !1 0 1 2 3 4 50

0.2

0.4

0.6

0.8

1

z ( µm)

t/

(10

4 s

)

(j) X!!B = 0.98

‘squeezing case’

!5 !4 !3 !2 !1 0 1 2 3 4 50

0.2

0.4

0.6

0.8

1

z ( µm)

t/

(10

4 s

)

(k) X!!B = 0.92

!5 !4 !3 !2 !1 0 1 2 3 4 50

0.2

0.4

0.6

0.8

1

z ( µm)

t/

(10

4 s

)

(l) X!!B = 0.98

W. J. Boettinger, J. E. Guyer, C. E. Campbell & G. B. McFadden,

Proceedings of the Royal Society A: Mathematical 463 (2007) 3347–3373

Cahn-Hilliard treatment

both Eulerian and Lagrangian

compared with sharp interface similarity solution

and DICTRA calculations

!XB

!t=

!

!z

!M̃(XB)

!

!z

"!!(XB !XA) + RT (lnXB ! lnXA)! 2K

!2XB

!z2

#$

v(z, t) = XAXB [MB !MA]!

!z

!!!(XB !XA) + RT (lnXB ! lnXA)! 2K

!2XB

!z2

"

!Z(z, t)!t

= !v!Z(z, t)

!z

M̃ = XAXB [XBMA + XAMB ]MA = M0[!1(1!XB) + !2XB ]MB = M0[!2(1!XB) + !1XB ]

FiPy implementation of Cahn-Hilliard model for“Computation of the Kirkendall Velocity and Displacement Field in a 1-D

Binary Di!usion Couple with a Moving Interface”

W. J. Boettinger1, J. E. Guyer1, C. E. Campbell1, and G. B. McFadden2

1Metallurgy Division, Materials Science and Engineering Laboratory,and

2Mathematical and Computational Sciences Division, Information Technology Laboratory,

National Institute of Standards and Technology, Gaithersburg, MD 20899, USASeptember 11, 2007

Module kirkendall

Attention!

This software was developed at the National Institute of Standards and Technology by employees of theFederal Government in the course of their o!cial duties. Pursuant to title 17 Section 105 of the United StatesCode this software is not subject to copyright protection and is in the public domain. kirkendall.py is anexperimental system. NIST assumes no responsibility whatsoever for its use by other parties, and makes noguarantees, expressed or implied, about its quality, reliability, or any other characteristic. We would appreciateacknowledgement if the software is used.This software can be redistributed and/or modified freely provided that any derivative works bear some noticethat they are derived from it, and any modified versions bear some notice that they have been modified.

FiPy implementation of Cahn-Hilliard model for Kirkendall di!usion.

Note

Information about FiPy can be found at http://www.ctcms.nist.gov/fipyThis script was tested with revision 2108 of the FiPy source code, available fromhttps://www.matforge.org/fipy/browser/trunk

We solve for the concentration XB on a 1D domain of length L = 10 with 2000 evenly spaced mesh points.

>>> from fipy import *

>>> L = 10.>>> nx = 2000

>>> mesh = Grid1D(nx=nx, dx=L / nx)

>>> xB = CellVariable(name="X_B", mesh=mesh, hasOld=1)>>> xA = 1. - xB

We set the initial conditions of

XB =

!"

#0 for ! ! L/2

0.92 for ! > L/2

where ! is the position within the domain (at this stage, we don’t attach any particular interpretation tothe frame of !):

1

Computation of the Kirkendall velocity anddisplacement fields in a one-dimensional

binary diffusion couple with a moving interface

BY W. J. BOETTINGER1, J. E. GUYER

1,*, C. E. CAMPBELL1

AND G. B. MCFADDEN2

1Metallurgy Division, Materials Science and Engineering Laboratory, and2Mathematical and Computational Sciences Division, Information Technology

Laboratory, National Institute of Standards and Technology,Gaithersburg, MD 20899, USA

The moving interface problem in a one-dimensional binary a/b diffusion couple is studiedusing sharp and diffuse interface (Cahn–Hilliard) approaches. With both methods, wecalculate the solute field and the Kirkendall marker velocity and displacement fields. Inthe sharp interface treatment, the velocity field is generally discontinuous at theinterphase boundary, but can be integrated to obtain a displacement field that iscontinuous everywhere. The diffuse interface approach avoids this discontinuity,simplifies the integration and yet gives the same qualitative behaviour. Special featuresobserved experimentally and reported in the literature are also studied with the twomethods: (i) multiple Kirkendall planes, where markers placed on the initial compositionaldiscontinuity of the diffusion couple bifurcate into two locations, and (ii) a Kirkendallplane that coincides with the interphase interface. These situations occur with specialvalues of the interdiffusion coefficients and starting couple compositions. The details of thedeformation in these special situations are given using both methods and are discussed interms of the stress-free strain rate associated with the Kirkendall effect.

Keywords: diffusion; deformation; similarity solution; Boltzmann–Matano;phase field; DICTRA

1. Introduction

The Kirkendall effect involves both diffusion and deformation. In general, thedeformation of a material can be defined by the change in position with time of aset of inert markers (real or imagined) embedded in the material. The Kirkendalleffect refers to changes in the marker positions that are observed as markersmove in response to diffusion in the material. For diffusion that occurs primarilyin a single direction, markers that are initially aligned in a plane perpendicular tothe diffusion direction tend to move in concert, defining marker planes as thematerial deforms unidirectionally.

Proc. R. Soc. A (2007) 463, 3347–3373doi:10.1098/rspa.2007.1904

Published online 9 October 2007

Electronic supplementary material is available at http://dx.doi.org/10.1098/rspa.2007.1904 or viahttp://www.journals.royalsoc.ac.uk.

*Author for correspondence ([email protected]).

Received 29 March 2007Accepted 11 September 2007 3347 This journal is q 2007 The Royal Society

Page 34: ϕ π ϕ Modeling of Materials with Pythonconference.scipy.org/static/wiki/guyer_fipy.pdfπ ϕ ϕπ 1 NIST: Origins “Uniformity in the currency, weights, and measures of the United

!"!"

1

Dendrites

What Are Dendrites:

A vast amount of the products and devices that we use everyday,everything from aluminum foil and soda cans, to cars, jet engines andcomputers, are made from metals and alloys. Early in the creation of allthese products the metals are in a liquid, or molten state, that freezes toform a solid, just like water freezes to form ice. Now, if you were to lookat some just frozen, or freshly solidified metallic alloy with a strongmagnifying glass you would see that its structure is not uniform, but ismade up of tiny individual crystalline grains. Moreover, If you were able tolook even more carefully at the individual grains through a powerfulmicroscope, you would see that each grain is made up from what looks likea bunch of tiny metallic snowflakes crowding and growing into each other.Scientists and engineers call these tiny metallic snowflakes dendrites. Thepicture to the right shows what a surface cut through a "forest" of dendrites in a metal would look likethrough a microscope.

The term dendrite comes from the Greek word "dendron", which means a tree.This description is appropriate because we often describe the form and structure ofa metallic dendrite as that of a tree (see figure to left), with a main branch or trunk,from which grow side branches, from which grow smaller side branches, and soon, until all the main branches and the side branches grow into each other and thereis no room for any more branches to grow. The figure to

the right shows a few dendrites growing out of the surface of a metal. Infact, almost all freshly crystallized alloys are composed of many thousands,or even millions of dendritic crystals all stuck together. What's mostimportant is that the shape, size, and speed of growth of these dendrites areall factors that profoundly influence the final properties of cast and weldedmetals.For example, the dendrites affect how hard or soft a material is, howstretchable or springy it behaves, and how much you can bend or stretch itbefore it breaks. The dendrites also affect both how long and under whatenvironmental conditions you can use an alloy before it wears out or rusts.The dendrites affect whether the material is a good or a poor conductor of electricity. The dendriteseven affect how easily you can weld one piece of metal to another, and what's the best way to do thewelding. In short, the dendritic pattern formed during solidification profoundly influences a material'smechanical, electrical, and chemical properties.

Phase Field Example!!T

!t= DT!2!T +

!"

!t

#!!"

!t= ! · D!" + "(1" ")

!"" 1

2" $1

%arctan ($2!T )

"

D = !2 (1 + c")

!1 + c" !c !"

!#

c !"!# 1 + c"

"! =

1! !2

1 + !2

! = tan!

N

2"

"

" = # + arctan$%/$y

$%/$x

Page 35: ϕ π ϕ Modeling of Materials with Pythonconference.scipy.org/static/wiki/guyer_fipy.pdfπ ϕ ϕπ 1 NIST: Origins “Uniformity in the currency, weights, and measures of the United

!"!"

1

Dendrites

What Are Dendrites:

A vast amount of the products and devices that we use everyday,everything from aluminum foil and soda cans, to cars, jet engines andcomputers, are made from metals and alloys. Early in the creation of allthese products the metals are in a liquid, or molten state, that freezes toform a solid, just like water freezes to form ice. Now, if you were to lookat some just frozen, or freshly solidified metallic alloy with a strongmagnifying glass you would see that its structure is not uniform, but ismade up of tiny individual crystalline grains. Moreover, If you were able tolook even more carefully at the individual grains through a powerfulmicroscope, you would see that each grain is made up from what looks likea bunch of tiny metallic snowflakes crowding and growing into each other.Scientists and engineers call these tiny metallic snowflakes dendrites. Thepicture to the right shows what a surface cut through a "forest" of dendrites in a metal would look likethrough a microscope.

The term dendrite comes from the Greek word "dendron", which means a tree.This description is appropriate because we often describe the form and structure ofa metallic dendrite as that of a tree (see figure to left), with a main branch or trunk,from which grow side branches, from which grow smaller side branches, and soon, until all the main branches and the side branches grow into each other and thereis no room for any more branches to grow. The figure to

the right shows a few dendrites growing out of the surface of a metal. Infact, almost all freshly crystallized alloys are composed of many thousands,or even millions of dendritic crystals all stuck together. What's mostimportant is that the shape, size, and speed of growth of these dendrites areall factors that profoundly influence the final properties of cast and weldedmetals.For example, the dendrites affect how hard or soft a material is, howstretchable or springy it behaves, and how much you can bend or stretch itbefore it breaks. The dendrites also affect both how long and under whatenvironmental conditions you can use an alloy before it wears out or rusts.The dendrites affect whether the material is a good or a poor conductor of electricity. The dendriteseven affect how easily you can weld one piece of metal to another, and what's the best way to do thewelding. In short, the dendritic pattern formed during solidification profoundly influences a material'smechanical, electrical, and chemical properties.

Phase Field Examplefrom fipy import *dx = dy = 0.025; nx = ny = 500mesh = Grid2D(dx=dx, dy=dy, nx=nx, ny=ny)dt = 5e-4

phase = CellVariable(name=r'$\phi$', mesh=mesh, hasOld=True)dT = CellVariable(name=r'$\Delta T$', mesh=mesh, hasOld=True)heatEq = (TransientTerm() == DiffusionTerm(2.25) + (phase - phase.getOld()) / dt)

alpha = 0.015; c = 0.02; N = 6.; theta = pi / 8.psi = theta + arctan2(phase.getFaceGrad()[1], phase.getFaceGrad()[0])Phi = tan(N * psi / 2)PhiSq = Phi**2beta = (1. - PhiSq) / (1. + PhiSq)DbetaDpsi = -N * 2 * Phi / (1 + PhiSq)Ddia = (1.+ c * beta)Doff = c * DbetaDpsiD = alpha**2 * (1.+ c * beta) * (Ddia * (( 1, 0), ( 0, 1)) + Doff * (( 0,-1), ( 1, 0)))tau = 3e-4; kappa1 = 0.9; kappa2 = 20.phaseEq = (TransientTerm(tau) == DiffusionTerm(D) + ImplicitSourceTerm((phase - 0.5 - kappa1 / pi * arctan(kappa2 * dT)) * (1 - phase)))radius = dx * 5.C = (nx * dx / 2, ny * dy / 2)x, y = mesh.getCellCenters()phase.setValue(1., where=((x - C[0])**2 + (y - C[1])**2) < radius**2)dT.setValue(-0.5)

viewer = DendriteViewer(phase=phase, dT=dT, title=r"%s & %s" % (phase.name, dT.name), datamin=-0.1, datamax=0.05)for i in range(10000): phase.updateOld() dT.updateOld() phaseEq.solve(phase, dt=dt) heatEq.solve(dT, dt=dt) if i % 10 == 0: viewer.plot()

!!T

!t= DT!2!T +

!"

!t

#!!"

!t= ! · D!" + "(1" ")

!"" 1

2" $1

%arctan ($2!T )

"

D = !2 (1 + c")

!1 + c" !c !"

!#

c !"!# 1 + c"

"! =

1! !2

1 + !2

! = tan!

N

2"

"

" = # + arctan$%/$y

$%/$x

Page 36: ϕ π ϕ Modeling of Materials with Pythonconference.scipy.org/static/wiki/guyer_fipy.pdfπ ϕ ϕπ 1 NIST: Origins “Uniformity in the currency, weights, and measures of the United

!"!"

1

Dendrites

What Are Dendrites:

A vast amount of the products and devices that we use everyday,everything from aluminum foil and soda cans, to cars, jet engines andcomputers, are made from metals and alloys. Early in the creation of allthese products the metals are in a liquid, or molten state, that freezes toform a solid, just like water freezes to form ice. Now, if you were to lookat some just frozen, or freshly solidified metallic alloy with a strongmagnifying glass you would see that its structure is not uniform, but ismade up of tiny individual crystalline grains. Moreover, If you were able tolook even more carefully at the individual grains through a powerfulmicroscope, you would see that each grain is made up from what looks likea bunch of tiny metallic snowflakes crowding and growing into each other.Scientists and engineers call these tiny metallic snowflakes dendrites. Thepicture to the right shows what a surface cut through a "forest" of dendrites in a metal would look likethrough a microscope.

The term dendrite comes from the Greek word "dendron", which means a tree.This description is appropriate because we often describe the form and structure ofa metallic dendrite as that of a tree (see figure to left), with a main branch or trunk,from which grow side branches, from which grow smaller side branches, and soon, until all the main branches and the side branches grow into each other and thereis no room for any more branches to grow. The figure to

the right shows a few dendrites growing out of the surface of a metal. Infact, almost all freshly crystallized alloys are composed of many thousands,or even millions of dendritic crystals all stuck together. What's mostimportant is that the shape, size, and speed of growth of these dendrites areall factors that profoundly influence the final properties of cast and weldedmetals.For example, the dendrites affect how hard or soft a material is, howstretchable or springy it behaves, and how much you can bend or stretch itbefore it breaks. The dendrites also affect both how long and under whatenvironmental conditions you can use an alloy before it wears out or rusts.The dendrites affect whether the material is a good or a poor conductor of electricity. The dendriteseven affect how easily you can weld one piece of metal to another, and what's the best way to do thewelding. In short, the dendritic pattern formed during solidification profoundly influences a material'smechanical, electrical, and chemical properties.

Phase Field Examplefrom fipy import *dx = dy = 0.025; nx = ny = 500mesh = Grid2D(dx=dx, dy=dy, nx=nx, ny=ny)dt = 5e-4

phase = CellVariable(name=r'$\phi$', mesh=mesh, hasOld=True)dT = CellVariable(name=r'$\Delta T$', mesh=mesh, hasOld=True)heatEq = (TransientTerm() == DiffusionTerm(2.25) + (phase - phase.getOld()) / dt)

alpha = 0.015; c = 0.02; N = 6.; theta = pi / 8.psi = theta + arctan2(phase.getFaceGrad()[1], phase.getFaceGrad()[0])Phi = tan(N * psi / 2)PhiSq = Phi**2beta = (1. - PhiSq) / (1. + PhiSq)DbetaDpsi = -N * 2 * Phi / (1 + PhiSq)Ddia = (1.+ c * beta)Doff = c * DbetaDpsiD = alpha**2 * (1.+ c * beta) * (Ddia * (( 1, 0), ( 0, 1)) + Doff * (( 0,-1), ( 1, 0)))tau = 3e-4; kappa1 = 0.9; kappa2 = 20.phaseEq = (TransientTerm(tau) == DiffusionTerm(D) + ImplicitSourceTerm((phase - 0.5 - kappa1 / pi * arctan(kappa2 * dT)) * (1 - phase)))radius = dx * 5.C = (nx * dx / 2, ny * dy / 2)x, y = mesh.getCellCenters()phase.setValue(1., where=((x - C[0])**2 + (y - C[1])**2) < radius**2)dT.setValue(-0.5)

viewer = DendriteViewer(phase=phase, dT=dT, title=r"%s & %s" % (phase.name, dT.name), datamin=-0.1, datamax=0.05)for i in range(10000): phase.updateOld() dT.updateOld() phaseEq.solve(phase, dt=dt) heatEq.solve(dT, dt=dt) if i % 10 == 0: viewer.plot()

!!T

!t= DT!2!T +

!"

!t

#!!"

!t= ! · D!" + "(1" ")

!"" 1

2" $1

%arctan ($2!T )

"

D = !2 (1 + c")

!1 + c" !c !"

!#

c !"!# 1 + c"

"! =

1! !2

1 + !2

! = tan!

N

2"

"

" = # + arctan$%/$y

$%/$x

import pylabclass DendriteViewer(Matplotlib2DGridViewer): def __init__(self, phase, dT, title=None, limits={}, **kwlimits): self.phase = phase self.contour = None Matplotlib2DGridViewer.__init__(self, vars=(dT,), title=title, cmap=pylab.cm.hot, limits=limits, **kwlimits)

def _plot(self): Matplotlib2DGridViewer._plot(self)

if self.contour is not None: for c in self.contour.collections: c.remove()

mesh = self.phase.getMesh() shape = mesh.getShape() x, y = mesh.getCellCenters() z = self.phase.getValue() x, y, z = [a.reshape(shape, order="FORTRAN") for a in (x, y, z)]

self.contour = pylab.contour(x, y, z, (0.5,))

Page 37: ϕ π ϕ Modeling of Materials with Pythonconference.scipy.org/static/wiki/guyer_fipy.pdfπ ϕ ϕπ 1 NIST: Origins “Uniformity in the currency, weights, and measures of the United

!"!"

1

“Superfill”D. Josell, D. Wheeler, W. H. Huber & T. P. Moffat

Physical Review Letters 87(1) (2001) 016102

Dmn̂ ·!cm =v

!on ! = 0

D!n̂ ·!c! = "k!c!!(1" !) on " = 0

v =i!nF

i = i0cim

c!mexp

!!!F

RT"

"

i0(#) = b0 + b1#

$cm

$t= " · Dm"cm

Dm =

#DL

m when % # 0,0 when % < 0

Dmn̂ ·"cm =v

!on % = 0

$c!

$t= " · D!"c!

D! =

#DL

! when % # 00 when % < 0

D!n̂ ·"c! = !kc!(1! #) on % = 0

$#

$t= Jv# + (k0 + k3"

3)ci!(1! #)

v =!nF

(b0 + b1#)cim

c!mexp

!!!F

RT"

"

$%

$t+ vext|"%| = 0

$#

$t! Jv# ! k!c

i!(1! #) = 0

$cm

$t!" · Dm"cm = 0

$c!

$t!" · D!"c! = 0

Dmn̂ ·"cm =v

!on % = 0

D!n̂ ·"c! = !k!c!"(1! #) on % = 0

2

v =i!nF

i = i0cim

c!mexp

!!!F

RT"

"

i0(#) = b0 + b1#

$cm

$t= " · Dm"cm

Dm =

#DL

m when % # 0,0 when % < 0

Dmn̂ ·"cm =v

!on % = 0

$c!

$t= " · D!"c!

D! =

#DL

! when % # 00 when % < 0

D!n̂ ·"c! = !kc!(1! #) on % = 0

$#

$t= Jv# + (k0 + k3"

3)ci!(1! #)

v =!nF

(b0 + b1#)cim

c!mexp

!!!F

RT"

"

$%

$t+ vext|"%| = 0

$#

$t! Jv# ! k!c

i!(1! #) = 0

$cm

$t!" · Dm"cm = 0

$c!

$t!" · D!"c! = 0

Dmn̂ ·"cm =v

!on % = 0

D!n̂ ·"c! = !k!c!"(1! #) on % = 0

2

v =i!nF

i = i0cim

c!mexp

!!!F

RT"

"

i0(#) = b0 + b1#

$cm

$t= " · Dm"cm

Dm =

#DL

m when % # 0,0 when % < 0

Dmn̂ ·"cm =v

!on % = 0

$c!

$t= " · D!"c!

D! =

#DL

! when % # 00 when % < 0

D!n̂ ·"c! = !kc!(1! #) on % = 0

$#

$t= Jv# + (k0 + k3"

3)ci!(1! #)

v =!nF

(b0 + b1#)cim

c!mexp

!!!F

RT"

"

$%

$t+ vext|"%| = 0

$#

$t! Jv# ! k!c

i!(1! #) = 0

$cm

$t!" · Dm"cm = 0

$c!

$t!" · D!"c! = 0

|"%| = 1

Dmn̂ ·"cm =v

!on % = 0

D!n̂ ·"c! = !k!c!"(1! #) on % = 0

2

with “leveler”

no “leveler”

Level Set method(combination of PDE

and algorithmic solution)Superconformal deposition in an SPS–PEG–Cl

electrolyte

In conventional damascene processing, electroplating is

performed in an electrolyte containing both an inhibitor

and a catalyst. Galvanostatic control is used in many

commercial processes, and programs implementing

controlled variation of current (e.g., current stepping,

with lower starting currents) have also been implemented.

The direct objective of such a process is repair of seed

layers prior to superfilling. Nonetheless, it should be

recognized that such growth programs can also result in

uptake of adsorbed catalyst prior to significant metal

deposition in a manner analogous to the electrode-

derivatization experiments described in the previous

section.

In contrast to industrial practice, potentiostaticregulation was used for this study. This avoids theambiguity of interpreting the spatially varying currentdistribution within the filling features that is inherent inthe superfill process, and permits unambiguous controlof the reaction supersaturation and associated surfacechemistry. Trench- and via-filling experiments wereperformed by immersion of wafer fragments in the SPS–PEG–Cl electrolyte containing 6.4-lmol/L SPS with the!0.25 V growth potential already applied. The experimentsare compared with shape-change simulations.

Trench-filling experimentsInterface evolution during copper deposition in trenchesof differing aspect ratio is shown in Figure 10. Thesubstrates were silicon wafer fragments that had beenpatterned using standard electron beam lithography ofspin-coated PMMA and coated with a copper seed layerusing electron beam evaporation. The trenches were about400 nm in height and 350, 250, 200, 150, and 100 nmin width, corresponding respectively to aspect ratios of1.14, 1.67, 2.0, 2.67, and 4.0. Each specimen contained sixgroups of this five-trench pattern, and each specimen wasrepolished and examined by FE–SEM three times;in combination this provided a total of eighteen crosssections of each size feature for analysis, allowing apreliminary assessment of repeatability. In contrastto the electroanalytical experiments, these specimenswere suspended in the electrolyte by hand duringmetal deposition. As a consequence one would notexpect a steady-state boundary layer to form, owing touncontrolled specimen motion. Nevertheless, the imagesof Figure 10 reveal a sequence of interface morphologiesthat are quite similar to those observed in thederivatization experiments and simulations shown inFigures 8 and 9, respectively.

Examination of the deposition in the 350-nm-widetrench at 25 s reveals the development of a 458 slope at thebottom corners, the earliest stage of superfilling. By 30 sthe 458 corner segments have reached one another at thebottom, forming a V-notch. This is followed by thecreation and subsequent rapid advance of a new bottomsurface that is approaching the field by 40 s. Continuedgrowth reveals an inversion of curvature over the featureby 50 s and significant bump formation above the trenchby 70 s.

Temporal evolution of the 250-nm feature isqualitatively similar. The movement of the catalyst-enriched bottom surface between 30 s and 35 s is morerapid, transiting almost half the trench height in thisperiod. Only minor sidewall motion is evident. The sametransition appears to have occurred in the 200-nm-widetrench between 25 s and 30 s. Shorter deposition timesare required to assay the filling of the small features.

SEM images of shape evolution accompanying trench filling. The trench widths are 350 nm, 250 nm, 200 nm, 150 nm, and 100 nm from left to right. For these processing conditions, robust super-filling was limited to an aspect ratio of less than 2.

Figure 10

70 s

50 s

40 s

35 s

30 s

25 s

1 m!

T. P. MOFFAT ET AL. IBM J. RES. & DEV. VOL. 49 NO. 1 JANUARY 2005

32

Page 38: ϕ π ϕ Modeling of Materials with Pythonconference.scipy.org/static/wiki/guyer_fipy.pdfπ ϕ ϕπ 1 NIST: Origins “Uniformity in the currency, weights, and measures of the United

!"!"

1

Photovoltaics

J. E. Guyer & D. Josell

0 = !" · (µnn"!n) + G! U

0 = " · (µpp"!p) + G! U

G = "! (0 = " · !#c + "c!, !|z=0 = !0)

U =pn! n2

i

$p0(n + n!) + $n0(p + p!)

n = ni exp!

V ! !n

kT

"

p = ni exp!

!p ! V

kT

"

0 = ! · !!V + p" n + N+D "N!

A

Scharfetter-Gummel discretizationNewton-Block SOR sweeping

!"#$%&'()*+&,-&)".//&0&1(2"-#3&($&%4.&53.'%"('4.67'#3&8('7.%*&&

0

2000

4000

6000

8000

10000

20 25 30 35 40 45 50

As Deposited

Annealed

Inte

nsi

ty, cp

s

!"

CdTe

CdTe

CdTe

AuAu

Fig. 6

Fig. 7

measure model

Page 39: ϕ π ϕ Modeling of Materials with Pythonconference.scipy.org/static/wiki/guyer_fipy.pdfπ ϕ ϕπ 1 NIST: Origins “Uniformity in the currency, weights, and measures of the United

!"!"

1

Reactive Wetting

D. Wheeler, J. A. Warren & W. J. Boettinger

!"1

!t+ !j ("1uj) = !j

!M

T!j

"µNC

1 ! µNC2

#$

!"2

!t+ !j ("2uj) = !j

!M

T!j

"µNC

2 ! µNC1

#$

! ("ui)!t

+ !j ("uiuj) = !j (# [!jui + !iuj ])! !iP

+ $1T"1!i!2j "1 + $2T"2!i!

2j "2 ! $!T!i%!2

j %

!%

!t+ uj!j% = $!M!!2

j %! M!

T

!F

!%

Coupled solutionParallel

Page 40: ϕ π ϕ Modeling of Materials with Pythonconference.scipy.org/static/wiki/guyer_fipy.pdfπ ϕ ϕπ 1 NIST: Origins “Uniformity in the currency, weights, and measures of the United

!"!"

1

don’t invent when you can steal

Pysparse

Gmsh

SciPy

Page 41: ϕ π ϕ Modeling of Materials with Pythonconference.scipy.org/static/wiki/guyer_fipy.pdfπ ϕ ϕπ 1 NIST: Origins “Uniformity in the currency, weights, and measures of the United

!"!"

1

Variable>>> A = Variable(value=3)>>> B = Variable(value=4)>>> C = A * B**2>>> C(Variable(value=array(3)) * (pow(Variable(value=array(4)), 2)))>>> print C48>>> B.setValue(5)>>> print C75

•Contains, but doesn’t inherit from, NumPy array

•MeshVariable holds field of values; Mesh holds geometry and topology

•units (mostly stolen from Konrad Hinsen)

>>> (Variable("1 ft*lb*gn") / "2 wk").inUnitsOf('N*m/s')PhysicalField(1.12088124035e-06,'m*N/s')

•supports automatic weave inlining

>>> C._getCstring()'(var0 * (pow(var10, var11)))'

Page 42: ϕ π ϕ Modeling of Materials with Pythonconference.scipy.org/static/wiki/guyer_fipy.pdfπ ϕ ϕπ 1 NIST: Origins “Uniformity in the currency, weights, and measures of the United

!"!"

1

Design: test-based development

298 Module fipy.variables.variable

ge (self, other)

Test if a Variable is greater than or equal to another quantity>>> a = Variable(value = 3)>>> b = (a >= 4)>>> b(Variable(value = 3) >= 4)>>> b()0>>> a.setValue(4)>>> b()1>>> a.setValue(5)>>> b()1

getitem (self, index )

“Evaluate” the variable and return the specified element>>> a = Variable(value = ((3.,4.),(5.,6.)), unit = "m") + "4 m">>> print a[1,1]10.0 m

It is an error to slice a Variable whose value is not sliceable>>> Variable(value = 3)[2]Traceback (most recent call last):

...TypeError: unsubscriptable object

gt (self, other)

Test if a Variable is greater than another quantity>>> a = Variable(value = 3)>>> b = (a > 4)>>> b(Variable(value = 3) > 4)>>> b()0>>> a.setValue(5)>>> b()1

• hundreds of major tests, comprising thousands of low-level tests

• Tests are documentation (and vice versa)

Page 43: ϕ π ϕ Modeling of Materials with Pythonconference.scipy.org/static/wiki/guyer_fipy.pdfπ ϕ ϕπ 1 NIST: Origins “Uniformity in the currency, weights, and measures of the United

!"!"

1

Design: test-based development

• hundreds of major tests, comprising thousands of low-level tests

• Tests are documentation (and vice versa)

6.2. Module examples.di!usion.mesh20x20 83

to the top-left and bottom-right corners. Neumann boundary conditions are automatically applied to thetop-right and bottom-left corners.

>>> x, y = mesh.getFaceCenters()>>> facesTopLeft = ((mesh.getFacesLeft() & (y > L / 2))... | (mesh.getFacesTop() & (x < L / 2)))>>> facesBottomRight = ((mesh.getFacesRight() & (y < L / 2))... | (mesh.getFacesBottom() & (x > L / 2)))

>>> BCs = (FixedValue(faces=facesTopLeft, value=valueTopLeft),... FixedValue(faces=facesBottomRight, value=valueBottomRight))

We create a viewer to see the results

>>> if name == ’ main ’:... viewer = Viewer(vars=phi, datamin=0., datamax=1.)... viewer.plot()

and solve the equation by repeatedly looping in time:

>>> timeStepDuration = 10 * 0.9 * dx**2 / (2 * D)>>> steps = 10>>> for step in range(steps):... eq.solve(var=phi,... boundaryConditions=BCs,... dt=timeStepDuration)... if name == ’ main ’:... viewer.plot()

0 5 10 15 200

5

10

15

20solution variable

0.0

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

1.0

solu

tion

varia

ble

We can test the value of the bottom-right corner cell.

Page 44: ϕ π ϕ Modeling of Materials with Pythonconference.scipy.org/static/wiki/guyer_fipy.pdfπ ϕ ϕπ 1 NIST: Origins “Uniformity in the currency, weights, and measures of the United

!"!"

1

www.ctcms.nist.gov/fipy

Page 46: ϕ π ϕ Modeling of Materials with Pythonconference.scipy.org/static/wiki/guyer_fipy.pdfπ ϕ ϕπ 1 NIST: Origins “Uniformity in the currency, weights, and measures of the United

!"!"

1

www.matforge.org/fipy

Page 47: ϕ π ϕ Modeling of Materials with Pythonconference.scipy.org/static/wiki/guyer_fipy.pdfπ ϕ ϕπ 1 NIST: Origins “Uniformity in the currency, weights, and measures of the United

!"!"

1

www.matforge.org/fipy

Page 48: ϕ π ϕ Modeling of Materials with Pythonconference.scipy.org/static/wiki/guyer_fipy.pdfπ ϕ ϕπ 1 NIST: Origins “Uniformity in the currency, weights, and measures of the United

!"!"

1

A Sampling of External Users

• NIST – gold nanoparticle hyperthermia

• U. of Central Florida – thermomigration and precipitate growth

• U. of Maine – water percolation through peat bogs

• Silesian University of Technology – solar irradiation of soil

• U. C. Berkeley – mRNA reaction-diffusion in fruitfly embryos

• Seagate Technologies – heat conduction in magnetic devices

• Princeton Satellite Systems – wind turbine development

• Rensselaer Polytechnic Institute – fuel cells

• Purdue University – stresses in photodiodes

Page 49: ϕ π ϕ Modeling of Materials with Pythonconference.scipy.org/static/wiki/guyer_fipy.pdfπ ϕ ϕπ 1 NIST: Origins “Uniformity in the currency, weights, and measures of the United

!"!"

1

Virtual Kinetics of Materials Library

M. Waters • A. Bartol • Prof. R. E. GarcíaPurdue University

nanohub.org/tools/vkmlggsnanohub.org/tools/vkmlpsgg

nanohub.org/tools/vkmlsdnanohub.org/tools/vkmlsd3d

Page 50: ϕ π ϕ Modeling of Materials with Pythonconference.scipy.org/static/wiki/guyer_fipy.pdfπ ϕ ϕπ 1 NIST: Origins “Uniformity in the currency, weights, and measures of the United

!"!"

1

Parallel

•2007! Max Gibiansky - Harvey Mudd - SURF student

•Integrate FiPy with PyTrilinos

Matrix solves in parallel…

…but builds in serial

•2008! Olivia Buzek - U of Maryland - SURF student

!Daniel Stiles - Montgomery Blair High School

•Build matrix in parallel with PyTrilinos, too

•Pervasive changes to every FiPy data type to make “parallel aware”

•Fragile and poor scaling performance

•Presently

•Leave FiPy alone (mostly)

•Break processes into separate FiPy problems with limited overlap

•PyTrilinos (and a little mpi4py) for communication and parallel solution

Page 51: ϕ π ϕ Modeling of Materials with Pythonconference.scipy.org/static/wiki/guyer_fipy.pdfπ ϕ ϕπ 1 NIST: Origins “Uniformity in the currency, weights, and measures of the United

!"!"

1

Parallel

• presently a Trilinos & PySparse hybrid

• doctests

• conditional tests?

• zero-element arraysnumpy:ticket:1171

mpirun -np 8 python examples/phase/anisotropy.py

Page 52: ϕ π ϕ Modeling of Materials with Pythonconference.scipy.org/static/wiki/guyer_fipy.pdfπ ϕ ϕπ 1 NIST: Origins “Uniformity in the currency, weights, and measures of the United

!"!"

1

Parallel: Partitioning• Presently only support primitive slices of Grid meshes

• PyMetis - “hard to install”

• Zoltan (Trilinos) - no Python wrapper

• Gmsh (uses Metis) - easy to install and use, but how to efficiently obtain overlaps?

• NetworkX?

Page 53: ϕ π ϕ Modeling of Materials with Pythonconference.scipy.org/static/wiki/guyer_fipy.pdfπ ϕ ϕπ 1 NIST: Origins “Uniformity in the currency, weights, and measures of the United

!"!"

1

Future Work: Coupled Equations

• Now

eqA = TransientTerm() == DiffusionTerm(coeff=DAA) + (DAB * B.getFaceGrad()).getDivergence()

eqB = TransientTerm() == (DBA * A.getFaceGrad()).getDivergence() DiffusionTerm(coeff=DBB)

for step in range(steps):

resA = resB = 1e10

while resA > 1e-3 or resB > 1e-3:

resA = eqA.sweep(var=A)

resB = eqB.sweep(var=B)

• Soon

eqA = TransientTerm()(A) == DiffusionTerm(coeff=DAA)(A) + DiffusionTerm(coeff=DAB)(B)

eqB = TransientTerm()(B) == DiffusionTerm(coeff=DBA)(A) + DiffusionTerm(coeff=DBB)(B)

eqs = CoupledEquations((eqA, eqB))

for step in range(steps):

eqs.solve(vars=(A, B))

!A

!t= ! · DAA!A +! · DAB!B

!B

!t= ! · DBA!A +! · DBB!B

Page 54: ϕ π ϕ Modeling of Materials with Pythonconference.scipy.org/static/wiki/guyer_fipy.pdfπ ϕ ϕπ 1 NIST: Origins “Uniformity in the currency, weights, and measures of the United

!"!"

1

Future Work

• Solvers

• SciPy sparse

• PyAMG - they’ve already done it!

• FEMhub

• Sphinx

• VisIt

• Autonomous viewers

• CorePy? Cython?

Page 55: ϕ π ϕ Modeling of Materials with Pythonconference.scipy.org/static/wiki/guyer_fipy.pdfπ ϕ ϕπ 1 NIST: Origins “Uniformity in the currency, weights, and measures of the United

!"!"

1

Summary•Cross-platform, Open Source code for phase transformation problems

•Capable of solving multivariate, coupled, non-linear PDEs

•Extensive documentation, dozens of examples, hundreds of tests

•Object-oriented structure easy to adapt to unique problems

•Slower to run than hand-tailored FORTRAN or C…

•…but much faster to write

•Python is great, but…

•…scientific Python community is our real enabling technology

FiPy 2.0 - released 2/9/2009www.ctcms.nist.gov/fipy

“FiPy: PDEs with Python”J. E. Guyer, D. Wheeler & J. A. Warren

Computing in Science and Engineering May/June (2009) 6

FiPy workshop, Winter 2009/2010

Page 56: ϕ π ϕ Modeling of Materials with Pythonconference.scipy.org/static/wiki/guyer_fipy.pdfπ ϕ ϕπ 1 NIST: Origins “Uniformity in the currency, weights, and measures of the United

!"!"

1

Major Contributers

• Alex Mont - Montgomery Blair High School

• Gmsh import

• Katie Travis - Smith College

• automated weave inlining

• Max Gibiansky - Harvey Mudd College

• Trilinos solvers

• Andrew Reeve - U of Maine

• anisotropic diffusion

• Olivia Buzek - U of Maryland

• parallel

• Daniel Stiles - Montgomery Blair High School

• parallel

• Mayavi2

• Gmsh partitioning

Page 57: ϕ π ϕ Modeling of Materials with Pythonconference.scipy.org/static/wiki/guyer_fipy.pdfπ ϕ ϕπ 1 NIST: Origins “Uniformity in the currency, weights, and measures of the United

!"!"

1

random thoughts on scientific Python

•Installation much easier, but…

•Be careful about licenses

•Don’t just wrap

•Python is a great cross-platform equalizer, but…

•GPUs are very platform specific

•Embrace 1.0!

•What becomes of SciPy if Python “dies”?

•What if it’s our fault?