Computational Physics: Software Notes

Computational Physics: Software Notes

Computational Physics: Software Notes Leon Hostetler July 14, 2018 Version 0.5 1 Contents Contents 2 1 Preface 5 2 Linux and Unix7 2.1 General Notes...................................... 7 2.2 Bash........................................... 8 2.3 Unix Networks ..................................... 18 2.4 Vim ........................................... 19 2.5 OpenLava........................................ 19 2.6 SLURM......................................... 19 2.7 System Monitoring and Performance......................... 20 3 LaTeX 23 3.1 Installation ....................................... 23 3.2 Tables.......................................... 23 3.3 Math........................................... 24 3.4 Images.......................................... 28 3.5 Referencing....................................... 28 3.6 Tikz........................................... 29 3.7 PGFPlots........................................ 39 4 Inkscape 45 4.1 Installation ....................................... 45 5 Python 49 5.1 Installation ....................................... 49 5.2 General ......................................... 49 5.3 Style Guide....................................... 50 5.4 Plotting......................................... 50 5.5 File Cleaning ...................................... 56 5.6 Vectorization ...................................... 57 6 Fortran 63 6.1 Installation ....................................... 63 6.2 A Basic Program.................................... 63 6.3 Syntax.......................................... 64 6.4 MPI........................................... 69 7 GnuPlot 71 7.1 Basic Command Line Plot............................... 71 7.2 Plot Files ........................................ 72 7.3 Error Bars........................................ 73 7.4 Commands ....................................... 73 2 CONTENTS 3 7.5 Variable Attributes................................... 73 8 MatLab 75 8.1 Installation ....................................... 75 8.2 Miscellaneous...................................... 75 8.3 Plotting......................................... 76 8.4 Vectors ......................................... 82 8.5 Linear Algebra ..................................... 83 8.6 Statistics ........................................ 86 8.7 Numerical Differentiation ............................... 86 8.8 Integration ....................................... 87 8.9 Vector Differential Operators ............................. 89 8.10 Differential Equations ................................. 92 8.11 Quantum Mechanics.................................. 93 9 Mathematica 95 9.1 The Basics ....................................... 95 9.2 Quantum Mechanics.................................. 95 Chapter 1 Preface About These Notes These are simply the notes that I am using and occasionally adding to. Don't expect too much from them. Updates Last Updated: July 14, 2018 Version 0.5: (Jul. 14, 2018) LaTeX chapter: Updated layout and added information on package dependencies. Version |: (Dec. 12, 2017) 5 Chapter 2 Linux and Unix 2.1 General Notes This book assumes that you are using Linux. This section contains general notes on using Linux. To see the list of currently installed packages via the terminal, use the command apt list --installed For example, the python subpackages are listed as python-subpackage. To search for a package or see if it's available, use apt-cache policy packagename To see the version of the available package, use apt-cache policy packagename To uninstall an installed package, use sudo apt-get remove packagename To completely remove a package and all related stuff brought by the package, use \purge" instead of \remove". You will probably want to install the following packages via your terminal: • sshpass (for automatically backing up to password-protected remote servers) • python-pip (to manage python packages) • python-tk (required for some of my plots) • texlive-full (the full LaTeX distribution) • python-visual • gfortran (Fortran compiler) • gnuplot (plotting) • emacs (general text editor) • cpufrequtils (CPU management) • lm-sensors (CPU temperature sensors) • scidavis (statistical plotting application) 7 8 CHAPTER 2. LINUX AND UNIX • iotop (harddrive input/output) • wxmaxima (computer algebra system) • zotero (document/resources management utility) To update Ubuntu, use sudo apt-get update followed by sudo apt-get upgrade Enter \Y" to confirm the update. After these two commands, you should also run sudo apt-get dist-upgrade and enter \Y" to confirm. 2.2 Bash Basic Usage Navigation To determine your current location in the directory structure, use the command pwd To list the files in the current directory, use the command ls The ls command has a lot of useful options. For example, the following command lists the contents, also the hidden files, the property information for the files, and one line per item. ls -a -l -1 To list the files in another directory, use the command ls [path][directory] To list all directories, subdirectories, and files, use find . -ls To move to a new location, use the command cd [path] To return to your home directory, use the command 2.2. BASH 9 cd ∼ To see the help manual for a command man [command] Note: When in the shell, the up arrow can be used to re-enter the previous command without having to retype everything. Whenever you want to see the recent commands, just use history Searching To find files in a directory and all of its subdirectories by name use, for example to find files whose name contains \apple", use find /directory -name"*apple*" To find all files whose filenames contain apple in the current directory and all subdirectories, use find . -name"*apple*" To search for a text string within all files in directory dir/ and its subdirectories, use grep -R"string" dir/ To find and delete all files called ”filename.txt" in the current directory and all of its subdirectories, use find . -name filename.txt -type f -delete Wildcards To list all python files in the current directory, you would use ls *.py Files and Directories To create a directory at your current location, use the command mkdir [directory] To create a text file, just call the (nonexistent) file with the emacs, gedit, or Vim editor: emacs [filename] & gedit [filename] & vi [filename] & 10 CHAPTER 2. LINUX AND UNIX The ampersand ensures that emacs opens the file in the background instead of in the same shell window. That way you can still issue commands to the shell while also editing your file in emacs. To move a file from one location to another, use the command mv [path1][file] [path2][file] To move the all contents from one directory to another, use mv [directory1]/* [directory2] To rename a file, \move" it to the same location with a different name. mv [path][old file] [path][new file] To copy a file from one location to another location: cp [oldpath][file] [new path] To copy a file into the current directory use a period to denote the current directory. cp [path][file] . To copy a file from one location to another location and rename it: cp [old path][old file name] [new path][new file name] To copy a directory and all subdirectories and files cp -r [directory] [newname] To view (but not modify) the contents of an ASCII file in the terminal: more [path][file] Press the space bar to page through the file. To delete a file, use rm file To delete an empty directory, use rmdir [directory] To delete a directory and all files and subdirectories in it, use rm -r [directory] To get a file over http use 2.2. BASH 11 wget [url to file] To securely copy a file to or from a remote server use the secure copy command. For example, to securely copy ftp/backup.tgz from my directory on the remote server at site.edu, to wherever I currently am on my local machine, I would use scp [email protected]:∼/ftp/backup.tgz . Note the required colon after the target address. The period at the very end instructs it to copy the remote file to my current location. It will ask you for your password after connecting to the server. The general form is scp [options] username@source_host:/directory/file username@destination:/directory/filename Note that the file host comes first, and the file destination comes second. If you are copying a directory and its contents, you have to include the \-r" option. File and Output Manipulation To redirect command output to a file. If the file doesnt exist, it is created. [command] > [file] For example, ls > content, would create a file called \content" that contains a list of the contents of the current directory. To redirect command output to another command: [command1] | [command2] Notice that \>" is used to redirect the output from a command or program to a file and \j" is used to redirect the output of a command or program to another program. To see the differences between two files: diff [file1] [file2] To see the differences between two folders, whose files (and their contents) should be the same, use diff -arq [folder1] [folder2] To sort the output of a command use [command] | sort To sort numerically from smallest to largest, add the -g option to the sort command. To reverse the order, use -g -r. 12 CHAPTER 2. LINUX AND UNIX To copy the first 100 lines from one file to another file, use head -100 file1 > file2 To suppress the standard output from a script, send it to /dev/null. For example: gfortran script.f ./a.out >/dev/null Images To view an image file, use the command display image To convert an image from one format to another, use, for example convert file.eps file.png By default, the resolution of the output image

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    96 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us