37
PY3C01 Part a: Computational methods Lecturer: Dr Thomas Archer Office: Lloyd 221 Phone: 8455 E-mail: [email protected] http://www.tcd.ie/Physics/people/Tom/Archer/teaching If there are computer problems please E-mail [email protected]

PY3C01 Part a: Computational methods2.pdf · Solution to physical models Newtons laws of motion or relativity – Classical motion of objects Quantum mechanics – describes atoms,

  • Upload
    others

  • View
    1

  • Download
    0

Embed Size (px)

Citation preview

Page 1: PY3C01 Part a: Computational methods2.pdf · Solution to physical models Newtons laws of motion or relativity – Classical motion of objects Quantum mechanics – describes atoms,

PY3C01 Part a: Computational methods

Lecturer:Dr Thomas ArcherOffice: Lloyd 221Phone: 8455E-mail: [email protected]

http://www.tcd.ie/Physics/people/Tom/Archer/teaching

If there are computer problems please E-mail [email protected]

Page 2: PY3C01 Part a: Computational methods2.pdf · Solution to physical models Newtons laws of motion or relativity – Classical motion of objects Quantum mechanics – describes atoms,

Lecture 1

● Why computational modelling

● Where computational physics is now

● Where computational physics is going

● Coding grammar

● Development tools

– (re)Introduction to Linux

– Version control

Page 3: PY3C01 Part a: Computational methods2.pdf · Solution to physical models Newtons laws of motion or relativity – Classical motion of objects Quantum mechanics – describes atoms,

Why computational modelling?

Page 4: PY3C01 Part a: Computational methods2.pdf · Solution to physical models Newtons laws of motion or relativity – Classical motion of objects Quantum mechanics – describes atoms,

Physics now

Page 5: PY3C01 Part a: Computational methods2.pdf · Solution to physical models Newtons laws of motion or relativity – Classical motion of objects Quantum mechanics – describes atoms,

Solution to physical models

● Newtons laws of motion or relativity – Classical motion of objects

● Quantum mechanics – describes atoms, molecules, all of chemistry, solids ….

We can write the equations to describe virtually anything (black holes are still a little tricky) but how do we solve them?

Page 6: PY3C01 Part a: Computational methods2.pdf · Solution to physical models Newtons laws of motion or relativity – Classical motion of objects Quantum mechanics – describes atoms,

Classical mechanics Examples

● Weather

– chaotic

● Astrophysics

● Galaxy formation

● Solar weather ● chaotic ● Usually classical mechanics but probably requires QM or relativity

● Finite element design

– Aerodynamics

– Optimization problems

Page 7: PY3C01 Part a: Computational methods2.pdf · Solution to physical models Newtons laws of motion or relativity – Classical motion of objects Quantum mechanics – describes atoms,

Atomistic modelling● Described almost exactly by quantum theory

– Solids

– Describes all chemistry

– Physical properties

– Optical properties

– Magnetic properties

– Biological processes

– Electronic transport

● Computationally expensive

– Small systems

– Numerical approximations

– Reduce complexity – periodicity in solid sate physics

– ~10,000 atoms possible as of 2013

Page 8: PY3C01 Part a: Computational methods2.pdf · Solution to physical models Newtons laws of motion or relativity – Classical motion of objects Quantum mechanics – describes atoms,

Atomistic modelling examples

● Bulk materials – use periodicity - solid state physics

● Other systems without symmetry more computationally intensive

● Sale ~N3

Bulk Al

Page 9: PY3C01 Part a: Computational methods2.pdf · Solution to physical models Newtons laws of motion or relativity – Classical motion of objects Quantum mechanics – describes atoms,

● Beyond simulations– Simulate physical phenomena.

– Validate theoretical understanding.

– Data processing, data science

– Automation and control.

Page 10: PY3C01 Part a: Computational methods2.pdf · Solution to physical models Newtons laws of motion or relativity – Classical motion of objects Quantum mechanics – describes atoms,

Where things are going

Time Magazine

Page 11: PY3C01 Part a: Computational methods2.pdf · Solution to physical models Newtons laws of motion or relativity – Classical motion of objects Quantum mechanics – describes atoms,

What does more power allow us to do

● Reduce approximations

● Run more detailed calculations

● Study larger systems

● Study larger numbers of systems – High-throughput computing/big data

Page 12: PY3C01 Part a: Computational methods2.pdf · Solution to physical models Newtons laws of motion or relativity – Classical motion of objects Quantum mechanics – describes atoms,

Growth of big data

● Available data rapidly growing

● Not just an internet full of selfies

● Scientific databases are becoming readily available

● How do we make sense of it.– Identifying trends leads to

new science

Page 13: PY3C01 Part a: Computational methods2.pdf · Solution to physical models Newtons laws of motion or relativity – Classical motion of objects Quantum mechanics – describes atoms,

Physics future

Page 14: PY3C01 Part a: Computational methods2.pdf · Solution to physical models Newtons laws of motion or relativity – Classical motion of objects Quantum mechanics – describes atoms,

Transferable skills

Page 15: PY3C01 Part a: Computational methods2.pdf · Solution to physical models Newtons laws of motion or relativity – Classical motion of objects Quantum mechanics – describes atoms,

Coding Grammar

How many languages do you know?

Page 16: PY3C01 Part a: Computational methods2.pdf · Solution to physical models Newtons laws of motion or relativity – Classical motion of objects Quantum mechanics – describes atoms,

Flow charts

● Commands executed sequentially

Page 17: PY3C01 Part a: Computational methods2.pdf · Solution to physical models Newtons laws of motion or relativity – Classical motion of objects Quantum mechanics – describes atoms,

Universal Grammar

● Grammar if you can write a flow chart you can turn it into a code

● Universal grammar - Common to all languages

● Syntax can always be quickly looked up

How many languages do you know?

ALL OF THEM!

Page 18: PY3C01 Part a: Computational methods2.pdf · Solution to physical models Newtons laws of motion or relativity – Classical motion of objects Quantum mechanics – describes atoms,

Linux

Page 19: PY3C01 Part a: Computational methods2.pdf · Solution to physical models Newtons laws of motion or relativity – Classical motion of objects Quantum mechanics – describes atoms,

Linux

● GNU licence – free to download change and redistribute.

● Safe/secure – no viruses.

● Most new developments are built on top of Linux/UNIX.

● You have total control and scripting is built in.

Page 20: PY3C01 Part a: Computational methods2.pdf · Solution to physical models Newtons laws of motion or relativity – Classical motion of objects Quantum mechanics – describes atoms,

Linux modular design

Page 21: PY3C01 Part a: Computational methods2.pdf · Solution to physical models Newtons laws of motion or relativity – Classical motion of objects Quantum mechanics – describes atoms,

Linux distributions

A good start would behttp://www.ubuntu.com/

You can boot from CD or flash drive to avoid any changes to your existing OS

Page 22: PY3C01 Part a: Computational methods2.pdf · Solution to physical models Newtons laws of motion or relativity – Classical motion of objects Quantum mechanics – describes atoms,

All you need in this course

Page 23: PY3C01 Part a: Computational methods2.pdf · Solution to physical models Newtons laws of motion or relativity – Classical motion of objects Quantum mechanics – describes atoms,

Where are my files?

Page 24: PY3C01 Part a: Computational methods2.pdf · Solution to physical models Newtons laws of motion or relativity – Classical motion of objects Quantum mechanics – describes atoms,

File permissions

Permission User Group Size Date Modified File name

Page 25: PY3C01 Part a: Computational methods2.pdf · Solution to physical models Newtons laws of motion or relativity – Classical motion of objects Quantum mechanics – describes atoms,

Commands

Many Linux commands, some useful ones are given here:http://www.tcd.ie/Physics/people/Tom.Archer/teaching/computational_methods/lectures/cheat_sheet.pdf

Page 26: PY3C01 Part a: Computational methods2.pdf · Solution to physical models Newtons laws of motion or relativity – Classical motion of objects Quantum mechanics – describes atoms,

Commands

Page 27: PY3C01 Part a: Computational methods2.pdf · Solution to physical models Newtons laws of motion or relativity – Classical motion of objects Quantum mechanics – describes atoms,

Commands

Page 28: PY3C01 Part a: Computational methods2.pdf · Solution to physical models Newtons laws of motion or relativity – Classical motion of objects Quantum mechanics – describes atoms,

Commands

Page 29: PY3C01 Part a: Computational methods2.pdf · Solution to physical models Newtons laws of motion or relativity – Classical motion of objects Quantum mechanics – describes atoms,

Commands

Page 30: PY3C01 Part a: Computational methods2.pdf · Solution to physical models Newtons laws of motion or relativity – Classical motion of objects Quantum mechanics – describes atoms,

Arguments

● Many commands require specification of one or more arguments: arg1 [arg2]

● Most commands can be “fine-tuned” using options: command [-o] [--long-option]

● Sometimes options can also have arguments

Page 31: PY3C01 Part a: Computational methods2.pdf · Solution to physical models Newtons laws of motion or relativity – Classical motion of objects Quantum mechanics – describes atoms,

Editors

● nano [file] - simple terminal based text editor● gedit [file] - simple GUI editor ● emacs [file] - complex text editor● vi [file] - the classical unix text editor

Many other programs available

Page 32: PY3C01 Part a: Computational methods2.pdf · Solution to physical models Newtons laws of motion or relativity – Classical motion of objects Quantum mechanics – describes atoms,

Wildcards

Wildcards allow to handle many files with similar names simultaneously

* matches any string

ls *.jpg (list all files ending with '.jpg')

? matches any single character

ls file?.dat (matches file1.dat, files.dat, but not file10.dat)

[abcde] exactly one of the listed characters

ls data[137] (matches data1, data7, but not data13 or data5)

[2-7] exactly one character in the given range

ls file[a-e] (matches filea, filee, but not filez or fileaa)

{xy,linux,unix} exactly any of the given strings

Page 33: PY3C01 Part a: Computational methods2.pdf · Solution to physical models Newtons laws of motion or relativity – Classical motion of objects Quantum mechanics – describes atoms,
Page 34: PY3C01 Part a: Computational methods2.pdf · Solution to physical models Newtons laws of motion or relativity – Classical motion of objects Quantum mechanics – describes atoms,
Page 35: PY3C01 Part a: Computational methods2.pdf · Solution to physical models Newtons laws of motion or relativity – Classical motion of objects Quantum mechanics – describes atoms,

Combining commands

ls | wc -l

- counts number of files/directories

cat text.txt | grep Linux | wc -l

- counts number of lines in text.txt that contain the word “Linux”

cat word_list | sort | uniq > unique_word_list

- alphabetically sorts all lines (words) in word_list, removes duplicate lines, and

writes the resulting list into file unique_word_list

echo 3*3 | bc

- calculates 3*3=9 (echo=writes the given string to stdout)

Page 36: PY3C01 Part a: Computational methods2.pdf · Solution to physical models Newtons laws of motion or relativity – Classical motion of objects Quantum mechanics – describes atoms,

Working at home

● Cygwin● Live cd/usb stick● Virtualbox

Page 37: PY3C01 Part a: Computational methods2.pdf · Solution to physical models Newtons laws of motion or relativity – Classical motion of objects Quantum mechanics – describes atoms,

Exercise

● Get familiar with the command line:1. Go to your home directory. How many files of different type are there?2. Go one level up and list the contents of that directory3. Go to the root directory (/). Inspect its contents4. Go to the /bin directory and list its contents. Do you recognize some of the filenames?5. Inspect the contents of the /usr/bin directorty without changing to that directory

1. Using absolute pathnames2. 7. ii. Using relative pathnames

6. Go back to your home directory7. Create a directory anynameyoulike and change into it8. Create a text file yourfavoritename.txt using an editor of your choice. Write something and save it.9. Inspect your newly created file with cat, more, and less10. Copy the file to anothername.txt11. Edit the new file and save it.12. Go back to your home directory13. Go into the directory anynameyoulike14. Print the contents of yourfavoritename.txt and then redirect its content to another file ofyourchoice.txt15. Inspect the content of ofyourchoice.txt16. Create a process in the foreground using “sleep 1000”17. Suspend the foreground process18. Resume the suspended process in the foreground19. Terminate the process20. Kill the sleep process21. Check whether the sleep process was really killed