Chemical Engineering 541
Numerical Methods
Introduction
1 Family
2 Website
• All class material will be on the website: – http://ignite.byu.edu/che541
• All scores and homework will be recorded on Learning Suite – Learningsuite.byu.edu TA
• Victoria Stephens • [email protected] • Office hours: M-F @ 10:00 • Zoom link: https://byu.zoom.us/j/466515227 Trends
• PDEs à ODEs à algebraic systems • Nonlinear systems à Linear systems • One complex equation becomes many “simpler” ones. • Continuous problems become discrete – Solutions at specified locations, or times. • Domain split into a grid of points or cells. • Most realistic problems require numerical solution. – This is the rule, not the exception • (Yet this topic is still relegated to an elective course L)
5 Example Applications
• Fluid Flow / Heat Transfer – Unsteady PDEs à discretize to large system of ODEs – Implicit: solve nonlinear systems at each “timestep” • Reduce these to iterative linear systems. Iterate to “convergence.” Repeat. • Reaction Engineering – Solve (maybe large) system of nonlinear equations (ODE’s). – PFR, PSR – Add spatial depences/diffusion à PDEs – Mechanism size reduction: • Solve nonlinear and linear systems of equations. Eigenvalue analysis to reduce dimensions. • Chemical Equilibrium – Solve systems of nonlinear equations to minimize Gibbs free energy. • Pipeline design – Solve systems of nonlinear equations. • Distillation à system of nonlinear equations for tray compositions • h = h(T): given T, find h (easy); given h, find T (harder) – Often, h is nicer to work with than T (h is conserved in adiabatic systems, but T is not!)
6 Direct Solution of Turbulent Combustion
Unknowns: Auxiliary: r, Flux relations: v, Heat, Mass, eo, Momentum. Yk, Energy/temperature P Mixing relations
Equations:
EOS: 7 Numerical Solution
• Method of lines. • 8th order finite difference discretization • 4th order explicit Runge Kutta integration • Nonlinear solution of enthalpy, temperture relationship. • Optional implicit reaction integration with explicit diffusion, convection • Processing of data involves many other numerical techniques (e.g., interpolation, integration).
8 Selected Results
9 Simulation Results
10 Language Summary
Language Platform Student0Cost Professional0Cost Note
VBA Windows Free N/A0(available) Limited0numerical0functionality:0Excel Mathcad Windows $25 $1,550 Matlab All $99 $2150+ Free0versions0available.00Toolboxes0needed Python All Free Free
Maple Mathematica etc.0see0http://en.wikipedia.org/wiki/Comparison_of_numerical_analysis_software • Python, VBA, Matlab for programing – Matlab is most advanced for numerics – Python is most extensible, and broad: a “real” programing language – VBA is limited to Excel with fewer numerical/plotting tools built in • Mathcad, Matlab, Python (scipy, numpy, matplotlib) are “full featured” – Plotting, symbolic, built-in numerical tools: ODEs, functions, interpolation, plotting, etc. • Mathcad has a pretty interface, does units • Free Matlab clones: Octave, SciLab, etc. Language Trends Language Trends
Python
Julia Python—Anaconda
https://www.anaconda.com/products/individual
Use Python 3.8 (64 bit) JupyterLab Julia Matlab
• Matlab is a programming language suited to numerical analysis and problems involving vectors and matricies. – Matlab = Matrix Laboratory – Many built in functions for solution of linear systems, interpolation, integration, solution of ODEs, etc. – Straightforward syntax – No need for external compilation/linking • Built in 2D, 3D graphics, very flexible • Can interface with C++, Java, Fortran • Object oriented programming capabilities • Graphical interface. • Built-in debugging capability. • Good for rapid programming/prototyping. – Excellent learning environment, ideas carry over to faster, more flexible (and complex) languages, such as C, Fortran.
17 FreeMat, Octave, Scilab
• Freemat, Octave, and SciLab are open source, Matlab-like variants • Octave contains fewer features, but very similar syntax, and runs most Matlab scripts without modification. – Visualization is via gnuplot • Scilab has a Matlab-like look and feel. • Freemat has a nice interface, and good plotting capabilities. • www.gnu.org/software/octave, www.scilab.org, http://freemat.sourceforge.net
18 Comparison
• Compare Python, Matlab, Mathcad – Polynomial fit – Integrate function – Stiff ODE system – System of 6 nonlinear equations – Interpolation • Codes require similar length, mouse/key strokes to enter • Codes include the same key items: e.g., setup, solve, plot • Mathcad is easier to read • Python and Matlab have Very similar syntax. – Advanced and publication quality plotting • More complex: – 2D heat equation: Matlab/Python • IPython notebook – Symbolic math (Matlab too) • xlwings: Python plugins for Excel Code: fit polynomial to data
Python Matlab
Python Code: integrate function
Python Matlab
2 filesPython (optional) Code: Stiff ODE system
Python Matlab
2Python files Code: interpolation
Python Matlab
Python
2 files Code: system of nonlinear equations
Python Matlab
Python
2 files
Flow through 3 parallel pipes given total flow, pipe props Code: 2D unsteady heat equation
Python Matlab
Finite difference, Euler integration