scientific programing and numerical...

18
Scientific Programing and Numerical Computation Course webpage: homepage.ntu.edu.tw/~wttsai/fortran/index.html

Upload: lamdat

Post on 29-Apr-2018

244 views

Category:

Documents


5 download

TRANSCRIPT

Page 1: Scientific Programing and Numerical Computationhomepage.ntu.edu.tw/~wttsai/fortran/ppt/1.Introduction.pdf · •Chapman, S. (2007) Fortran 95/2003 for Scientists and Engineers, 3rd

Scientific Programing andNumerical Computation

Course webpage: homepage.ntu.edu.tw/~wttsai/fortran/index.html

Page 2: Scientific Programing and Numerical Computationhomepage.ntu.edu.tw/~wttsai/fortran/ppt/1.Introduction.pdf · •Chapman, S. (2007) Fortran 95/2003 for Scientists and Engineers, 3rd

• What is this course for?

• Shall I take this course?

• How is this course taught?

1. Introduction

Page 3: Scientific Programing and Numerical Computationhomepage.ntu.edu.tw/~wttsai/fortran/ppt/1.Introduction.pdf · •Chapman, S. (2007) Fortran 95/2003 for Scientists and Engineers, 3rd

Two fundamental methodologies for scientific or engineering studies

By observing or measuring in the field or in the laboratory …

By analyzing or computing on papers or using computer …

Page 4: Scientific Programing and Numerical Computationhomepage.ntu.edu.tw/~wttsai/fortran/ppt/1.Introduction.pdf · •Chapman, S. (2007) Fortran 95/2003 for Scientists and Engineers, 3rd

Identify the physical

processes to study

Pose a model problem and formulate it using conservation laws

Solve the equations numerically or theoretically

Check if the equations are solved correctly?

Can the solutions explain the physics, or compare correctly with the measurements?

Procedure of scientific or engineering study using numerical simulation

(what I was taught, and how we are doing)

Use the “numerical model” to explore mechanisms, make prediction, optimize design, etc.

Page 5: Scientific Programing and Numerical Computationhomepage.ntu.edu.tw/~wttsai/fortran/ppt/1.Introduction.pdf · •Chapman, S. (2007) Fortran 95/2003 for Scientists and Engineers, 3rd

Assume…

• you know how to use a computer to compute;

• but have not done any serious numerical computations,

• and only know some very basic numerics.

This course will teach you…

• FORTRAN programing language to compute,

• good habits to write structural Fortran programs,

• to write test driver to test the Fortran program written by you or others,

• to use well developed and optimized libraries, such as LAPACK, FFTW,

• to do parallel computing in multi-process computer using OpenMP

• to use the these skills to solve partial differential equations governing simple

physical systems, such as Poisson equation, wave equation, heat equation.

Page 6: Scientific Programing and Numerical Computationhomepage.ntu.edu.tw/~wttsai/fortran/ppt/1.Introduction.pdf · •Chapman, S. (2007) Fortran 95/2003 for Scientists and Engineers, 3rd

… and using these basic blocks plus some extra hard work, eventually you are able to develop your own numerical program to simulate the more realistic physical system, such as …

Page 7: Scientific Programing and Numerical Computationhomepage.ntu.edu.tw/~wttsai/fortran/ppt/1.Introduction.pdf · •Chapman, S. (2007) Fortran 95/2003 for Scientists and Engineers, 3rd

This course will not teach …

• advanced Fortran language,

• parallel computing using MPI,

• advanced numerical methods.

So, do not take this course if you think you are advanced student eager to learn cutting-edge computation techniques and numerics.

… and, never, never do this in class!

Page 8: Scientific Programing and Numerical Computationhomepage.ntu.edu.tw/~wttsai/fortran/ppt/1.Introduction.pdf · •Chapman, S. (2007) Fortran 95/2003 for Scientists and Engineers, 3rd

Suggested textbooks:

• Chapman, S. (2007) Fortran 95/2003 for Scientists and Engineers, 3rd edition, McGraw-Hill

• Chivers, I. & Sleightholme, J. (2012), Introduction to Programming with Fortran, Springerhttp://link.springer.com/book/10.1007/978-0-85729-233-9/page/1 [台大圖書館電子藏書]

• Moin, P., Fundamentals of Engineering Numerical Analysis, Cambridge University Press

Format of class:

1 to 2 hours of lecture plus 1 to 2 hours of programming practice

Grading:

based on the grades of midterm quiz, and/or final quiz, and/or take-home projects

Exercise (Homework):

• In-class exercise/homework after the every class

• No need to turn in the exercise/homework

Teaching assistant: 呂冠鴻 [email protected]

Page 9: Scientific Programing and Numerical Computationhomepage.ntu.edu.tw/~wttsai/fortran/ppt/1.Introduction.pdf · •Chapman, S. (2007) Fortran 95/2003 for Scientists and Engineers, 3rd

Some notes about Fortran:

• There exist computer programming languages other than C and C++.

• C/C++ is not the only high level computer programming language being used.

(Ada, Basic, COBOL, Fortran, Pascal …)

• Fortran = Formula Translation, is mainly for general numerical computation.

• Is FORTRAN an outdated programming language?

Of course not, otherwise why there are still so many people using it; and the

language has been continuously updated since its first release in 1957!

• Who use Fortran?

• People who do number crunching, i.e., computing.

• Many of the HPC (High-Performance Computing) codes have been around

for > 20 years and are still in use today.

Page 10: Scientific Programing and Numerical Computationhomepage.ntu.edu.tw/~wttsai/fortran/ppt/1.Introduction.pdf · •Chapman, S. (2007) Fortran 95/2003 for Scientists and Engineers, 3rd

Evolution of Fortran:

• First released in 1957 by IBM

• Fortran II: 1958 (subroutine and function appeared)

• Fortran IV: 1962

• Fortran 66: 1966 (adapted as an ANSI standard)

• Fortran 77: 1977

• Fortran 90/95: 1990/1997

• Fortran 2003/2008: 2003/2008

• ……

American National Standards Institute

see “The Beginnings of FORTRAN” in YouTubehttps://www.youtube.com/watch?v=KohboWwrsXg

Modern structural programming features are introduced.But many undesirable features from earlier versions are also retained.

For backward compatibility.Do not recommended to use. (obsolescent features)‘

Page 11: Scientific Programing and Numerical Computationhomepage.ntu.edu.tw/~wttsai/fortran/ppt/1.Introduction.pdf · •Chapman, S. (2007) Fortran 95/2003 for Scientists and Engineers, 3rd

Software used in this course:

• GNU Fortran compiler or Intel Fortran

• GNU emace editor

GNU = GNU is not UNIX

• GNU project originally indented to develop a free Unix-like computer operating system, with an ultimate goal to be a complete Unix-compatible software system composed wholly of free software.

(But the current mainstream trend is to use GNU software with Linux kernel.)

• Started in 1984 by Richard Stallman who quit his job at MIT Artificial Intelligence Laboratory.

牛羚, 角馬 (南非產)

Page 12: Scientific Programing and Numerical Computationhomepage.ntu.edu.tw/~wttsai/fortran/ppt/1.Introduction.pdf · •Chapman, S. (2007) Fortran 95/2003 for Scientists and Engineers, 3rd

• Minimalist GNU for Windows (MinGW)

• a minimalist development environment for native Microsoft Windows applications

• provides a complete Open Source programming tool set, including Fortran

• a zipped folder containing MinGW, GNU Emacs and cmd to start Emacs and Fortran compiler: GNU_emacs_Fortran.zip

• in the folder \GNU_emacs_Fortran

To use GNU Fortran in Microsoft Windows

Page 13: Scientific Programing and Numerical Computationhomepage.ntu.edu.tw/~wttsai/fortran/ppt/1.Introduction.pdf · •Chapman, S. (2007) Fortran 95/2003 for Scientists and Engineers, 3rd

• in the folder \GNU_emacs_Fortran

CMD_emacs_Fortran.bat: open both command prompt console and Emacs editor

CMD_Fortran.bat: open only command prompt console

Open_emacs.bat: open only Emacs editor

command prompt console

Emacs editor

Page 14: Scientific Programing and Numerical Computationhomepage.ntu.edu.tw/~wttsai/fortran/ppt/1.Introduction.pdf · •Chapman, S. (2007) Fortran 95/2003 for Scientists and Engineers, 3rd

Use command prompt console to

• move around directories

>dir

>mkdir homework01

>cd homework01

>cd ..

• compile program

>gfortran hw01.f90

• execute program

>a.exe

Page 15: Scientific Programing and Numerical Computationhomepage.ntu.edu.tw/~wttsai/fortran/ppt/1.Introduction.pdf · •Chapman, S. (2007) Fortran 95/2003 for Scientists and Engineers, 3rd

• create a new program,

then edit the program.

Use Emacs editor to

Page 16: Scientific Programing and Numerical Computationhomepage.ntu.edu.tw/~wttsai/fortran/ppt/1.Introduction.pdf · •Chapman, S. (2007) Fortran 95/2003 for Scientists and Engineers, 3rd

open and edit an existing program.

Use Emacs editor to

Page 17: Scientific Programing and Numerical Computationhomepage.ntu.edu.tw/~wttsai/fortran/ppt/1.Introduction.pdf · •Chapman, S. (2007) Fortran 95/2003 for Scientists and Engineers, 3rd

Graphics Software

。 Gnuplot (a portable command-line driven graphing utility)

。 Octave (freeware similar to Matlab)

• Use any graphics software (e.g., Matlab, Tecplot) you prefer for plotting the computation output if needed.

• Two freeware for graphics:

Page 18: Scientific Programing and Numerical Computationhomepage.ntu.edu.tw/~wttsai/fortran/ppt/1.Introduction.pdf · •Chapman, S. (2007) Fortran 95/2003 for Scientists and Engineers, 3rd