In this final project, you will develop, to specifications, a Python function that will solve the one-dimensional, time-dependent Schroedinger Equation.
Background
Section 9.2 of the textbook gives some background on the Schroedinger equation, the foundation of quantum mechanics. (Non-physicists, please don't panic at this;hereandhereis some additional background information if you want to know more about what is going on.) A key thing to know is that, for a particle governed by the 1-D Schroedinger equation, the interpretation of the wave function is that:
|ψ(x,t)|2dxdt=ψ(x,t)ψ∗(x,t)dxdt
(where the*means "complex conjugate")
gives the probability of finding the particle betweenxandx + dxat times betweentandt + dt.
Statement of Task
Your task for this project is to write and document a function that will solve the one-dimensional, time-dependent Schroedinger Equation, using either the explicit FTCS or the Crank-Nicholson scheme (equations 9.32 and 9.40 in the text;you should read Section 9.2 of the text carefully for more information on numerical solutions to the Schroedinger Equation). Your main function can call additional functions that you write, if you find this a useful way to write your code.
The calling sequence of the main function should besch_eqn(nspace, ntime, tau, method='ftcs', length=200, potential = [], wparam = [10, 0, 0.5])
. In the argument list,nspace
is the number of spatial grid points,ntime
is the number of time steps to be evolved, andtau
is the time step to be used (note thattau
is not a relative timestep).
The optional arguments are
method
: string, eitherftcs
orcrank
length
: float, size of spatial grid. Default to 200 (grid extends from -100 to +100)potential
: 1-D array giving the spatial index values at which the potentialV(x)should be set to 1. Default to empty. For example,[25, 50]
will setV[25] = V[50] = 1
.wparam
: list of parameters for initial condition[sigma0, x0, k0]
. Default[10, 0, 0.5]
.
If the FTCS method is chosen by the user, a matrix-stability analysis of the evolution matrix should be performed (as in Lab 10). If the evolution is determined to be unstable, a warning should be given to the user and the time integration should not be performed. If the Crank-Nicolson scheme is selected, no matrix-stability check is required as this method is unconditionally stable for allτ.
The initial condition should be a free particle represented by a Gaussian wave packet at timet = 0, Equation 9.42 in the text; see your lab solutions.
Your routine should implement periodic boundary conditions. For simplicity, you can takeh= 1and assumem = 1/2so thath2/2m = 1. Set the potential,V, to zero everywhere by default (but see thepotential
argument above).
sch_eqn
should return a 2D array givingψ(x,t),two 1-D arrays giving thexandtgrid values, and a 1-D array that gives the total probability computed for each timestep (which should be conserved).
The code you hand in should also contain asch_plot
function that uses the output of yoursch_eqn
function to visualize your results. The plotting function should make one of two possible plots and optionally save the plot to a file:
psi
, a plot of the real part ofψ(x)at a specific timet.prob
, a plot of the particle probability densityψ ψ*(x) at a specific time;numpy.conjugate
can be used to do complex conjugation.
You should define the calling sequence for this function yourself.
Your functions should contain docstrings which concisely explain what they do and how to use them. In addition, your submission should contain a document (in PDF format) with more detailed user documentation. This should clearly describe all function inputs and outputs. Examples of use should also be given, with example plot output.
Ground rules
For this project, it's acceptable (and encouraged) to adapt code from previous labs and/or from theNM4P
programs. Use comments in your code to describe its origins.
While this is an individual project and you may not copy project code or documentation from another class member, it's acceptable and encouraged for you to help one another, for example by assisting with debugging and/or testing each other's code. If you have questions about what is or isn't allowed, please ask. Please use code comments to acknowledge any assistance.
Submission instructions
Submit your project via OWL, including the Python fileLastName_Firstname_project4.py
and your reportLastName_Firstname_project4.pdf
. The report should contain both user documentation (structured in a similar manner to thescipy.integrate.solve_ivppage) and a report on how you tested your functions. Both parts should be written using complete sentences with correctly spelled words. While some discussion of the equations and numerical methods should be included, you do not need to include equations in the documentation.
The quality of the code you write is is part of the evaluation for this project. Some hints on writing good Python functions can be foundhere. While you don't need to adhere strictly to the PythonPEP8standard, following it will help you write more readable code. See also Section 2 of"Good Enough Practices in Scientific Computing"for good information on programming standards.
Evaluation
This final project is designed to be a more realistic example of the kind of coding work performed in the real world. Often the developer does not really know how their code will be used by the end user. The only defense you have is good documentation and well-structured anddefensively-writtenPython functions. Your project will be evaluated by reading your documentation file and running your code on three problems to be chosen by the instructor (and not specified to you in advance). The problems are such that any correct implementation following the guidelines above will be able to produce correct results.