Finite Volumes Lab II: Cooking a Simulation from Scratch - PowerPoint PPT Presentation

1 / 22
About This Presentation
Title:

Finite Volumes Lab II: Cooking a Simulation from Scratch

Description:

from fipy.meshes.grid1D import Grid1D. mesh = Grid1D(nx, dx) ... John Guyer: guyer_at_nist.gov. Dan Wheeler: daniel.wheeler_at_nist.gov ... – PowerPoint PPT presentation

Number of Views:194
Avg rating:3.0/5.0
Slides: 23
Provided by: bicephalo
Category:

less

Transcript and Presenter's Notes

Title: Finite Volumes Lab II: Cooking a Simulation from Scratch


1
Finite Volumes Lab II Cooking a Simulation from
Scratch
  • R. Edwin García
  • redwing_at_purdue.edu

2
One Dimensional Diffusion
F(x, t0) 0
3
Working Scripts for Todays Class can be are
diffusionX.py
diffusionI.py
diffusionCN.py
(explicit)
(implicit)
(semi-implicit)
4
A PDE is Solved in Four Steps
  • Variables Definitions
  • Equation(s) Definition(s)
  • Boundary Condition Specification
  • Viewer Creation
  • Problem Solving

5
A PDE is Solved in Four Steps
  • Variables Definitions
  • Equation(s) Definition(s)
  • Boundary Condition Specification
  • Viewer Creation
  • Problem Solving

6
Variables Definitions
  • nx 50
  • dx 1.0/float(nx)
  • from fipy.meshes.grid1D import Grid1D
  • mesh Grid1D(nx, dx)
  • from fipy.variables.cellVariable import
    CellVariable
  • phi CellVariable(name"solution variable",
    meshmesh, value0)
  • D 1.0
  • valueLeft 1
  • valueRight 0
  • timeStepDuration 0.9(dx)2/(2D)
  • steps 900

7
A PDE is Solved in Four Steps
  • Variables Definitions
  • Equation(s) Definition(s)
  • Boundary Condition Specification
  • Viewer Creation
  • Problem Solving

8
Equation Definition
  • from fipy.terms.explicitDiffusionTerm import
    ExplicitDiffusionTerm
  • from fipy.terms.transientTerm import
    TransientTerm
  • eqX TransientTerm() ExplicitDiffusionTerm(coe
    ff D)

9
Other Equation Terms
10
A PDE is Solved in Four Steps
  • Variables Definitions
  • Equation(s) Definition(s)
  • Boundary Condition Specification
  • Viewer Creation
  • Problem Solving

11
Boundary Conditions
  • from fipy.boundaryConditions.fixedValue import
    FixedValue
  • BCs (FixedValue(faces mesh.getFacesRight(),
    valuevalueRight),
  • FixedValue(facesmesh.getFacesLeft(),va
    luevalueLeft))

12
Other Type of BCs
13
A PDE is Solved in Four Steps
  • Variables Definitions
  • Equation(s) Definition(s)
  • Boundary Condition Specification
  • Viewer Creation
  • Problem Solving

14
Viewer Creation
  • from fipy import viewers
  • viewer viewers.make(vars phi,
    limits'datamin'0.0, 'datamax'1.0)

15
A PDE is Solved in Four Steps
  • Variables Definitions
  • Equation(s) Definition(s)
  • Boundary Condition Specification
  • Viewer Creation
  • Problem Solving

16
Solving the Problem
  • for step in range(steps)
  • eqX.solve(var phi, boundaryConditions
    BCs, dt timeStepDuration)
  • viewer.plot()

17
Launching the Simulation
  • Save file under adequate name (extension must be
    .py)
  • Run it by calling python from the command line.
  • You can cancel your simulation by typing CTRL-C

short-cut CTRL-X CTRL-S
Example coolSimulation.py
Example python coolSimulation.py
18
Fun Things to Try
  • Try changing the boundary and initial conditions.
  • Try changing the Amplification factor in the time
    step.
  • Try replacing the ExplicitDiffusionTerm with an
    ImplicitDiffusionTerm

Example initialize the field to 0.5
Example set A1.1
19
Three Exercises
  • Run diffusionX.py with an amplification factor of
    0.9
  • Run diffusionX.py with an amplification factor of
    1.0
  • Run diffusionX.py with an amplification factor of
    1.1

(Explicit Method)
20
Three More Exercises
  • Run diffusionCN.py with an amplification factor
    of 1
  • Run diffusionCN.py with an amplification factor
    of 10
  • Run diffusionCN.py with an amplification factor
    of 100

(Semi-Implicit Method)
21
Three Final Exercises
  • Run diffusionI.py with an amplification factor of
    0.9
  • Run diffusionI.py with an amplification factor of
    1.0
  • Run diffusionI.py with an amplification factor of
    1.1
  • Run diffusionI.py with an amplification factor of
    2, 5, 7, 10, 100,...

(Implicit Method)
22
FiPy Resources
  • FiPy Manual (tutorials and useful examples)
  • FiPy Reference (what every single command does)
  • Mailing List fipy_at_nist.gov
  • You can also email
  • John Guyer guyer_at_nist.gov
  • Dan Wheeler daniel.wheeler_at_nist.gov
  • FiPy Website http//www.ctcms.nist.gov/fipy/
Write a Comment
User Comments (0)
About PowerShow.com