Skip to content

Commit 91b89c9

Browse files
author
Quarto GHA Workflow Runner
committed
Built site for gh-pages
1 parent a5c237b commit 91b89c9

File tree

3 files changed

+33
-34
lines changed

3 files changed

+33
-34
lines changed

.nojekyll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
d5168748
1+
f6782d05

experiments/schrodingers/index.html

Lines changed: 31 additions & 32 deletions
Large diffs are not rendered by default.

search.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"href": "experiments/schrodingers/index.html#calculations",
2626
"title": "Schrödinger’s Equation",
2727
"section": "Calculations",
28-
"text": "Calculations\nWith this we can finally start on the calculations. Start by defining a Potential (Noting this is really potenetial energy and not electric potential). The potential is then the potential energy of an electron in an atom of hydrogen which is \\[\nV(r) = -\\frac{e^2}{4 \\pi \\epsilon_0 r} = -\\frac{1}{ma_0 r},\\, a_0 = \\frac{4\\pi\\epsilon_0\\hbar^2}{e^2m}\\approx 5.29 \\times 10^-11m\n\\] This allows us to define the radius in terms of the bohr radius \\(a_0\\). We can then rearange the equation to solve for \\(m\\delta^2V(x)\\) and write our function as \\[\nm\\delta^2V(x)= -\\frac{\\delta^2}{a_0 r} = -\\frac{(\\delta/a_0)^2}{(r/a_0)}\n\\] Changing the units to a_0 by dividing by \\(a_0/a_0\\)\nStart by defining values for our grid and delta\n\nN = 120\n# Note that both the coordinates and delta are measured in units of a_0\nX,Y,Z = np.mgrid[-25:25:N*1j,-25:25:N*1j,-25:25:N*1j] # create a grid from -25 to 25 a_0\ndelta = np.diff(X[:,0,0])[0] # get the step size\n\nNow we write a function to get the potential as follows\n\ndef get_potential(x,y,z):\n # since the units are in a_0 we can treat the a_0 in the equation defined above as 1\n # As well we add 1e-10 to the value of r to avoid any infinities at r=0\n return -delta**2/np.sqrt(x**2+y**2+z**2 + 1e-10)\n\nV0 = get_potential(X,Y,Z) # This creates a 3d grid of potentials\nV0.shape # shape should be n*n*n we really want this to be a diagonal matrix in M_{n^3}(R)\n\n(120, 120, 120)\n\n\nWe want to get our proper \\(V\\) matrix which we can do along with our \\(D\\) matrix\n\ndiag = np.ones([N]) # create a vector of ones in R^n\ndiags = np.array([diag, -2*diag, diag]) # create a n*3 matrix representing the diagonals in D\nD = sparse.spdiags(diags, np.array([-1,0,1]), N, N) # Create D from the diags\nT = -1/2 * sparse.kronsum(sparse.kronsum(D,D), D) # Create T from D\nV = sparse.diags(V0.reshape(N**3), (0)) # Create a sparse matrix from V0\nH = T+V # Finally create the hamiltonian matrix\nH.shape # Print out the shape of H which should be (N^3,N^3)\n\n(1728000, 1728000)\n\n\nConvert H so that it is on the gpu. This makes finding the eigenvalues easier\n\nH = H.tocoo()\nH = torch.sparse_coo_tensor(indices=torch.tensor([H.row, H.col]), values=torch.tensor(H.data), size=H.shape).to(device)\n\n/tmp/ipykernel_7383/2973072149.py:2: UserWarning:\n\nCreating a tensor from a list of numpy.ndarrays is extremely slow. Please consider converting the list to a single numpy.ndarray with numpy.array() before converting to a tensor. (Triggered internally at /build/python-pytorch/src/pytorch/torch/csrc/utils/tensor_new.cpp:254.)\n\n\n\nFinally we can compute the eigenvalues/eigenvectors as follows\n\nnum_states = 20 # number of states to calculate\nstart = time.perf_counter()\neigenvalues, eigenvectors = torch.lobpcg(H, k=num_states, largest=False)\nend = time.perf_counter()\nelapsed = timedelta(seconds = end-start)\nprint(\"Time to calculate:\", elapsed)\n\nTime to calculate: 0:49:01.725120\n\n\nHere is a function to get a an eigenvector given an energy level\n\ndef get_e(n):\n return eigenvectors.T[n].reshape((N,N,N)).cpu().numpy()\n\nWe can compute an object given a certain energy level and plot it\n\neigenstate = 6 # Eigenstate to display\nverts, faces, _, _ = measure.marching_cubes(get_e(eigenstate)**2, 1e-6, spacing=(0.1, 0.1, 0.1))\nintensity = np.linalg.norm(verts, axis=1)\n\nfig = go.Figure(data=[go.Mesh3d(x=verts[:, 0], y=verts[:, 1], z=verts[:, 2], \n i=faces[:, 0], j=faces[:, 1], k=faces[:, 2],\n intensity=intensity,\n colorscale='Agsunset',\n opacity=0.5)])\n\nfig = fig.update_layout(scene=dict(xaxis=dict(visible=False),\n yaxis=dict(visible=False),\n zaxis=dict(visible=False),\n bgcolor='rgb(0, 0, 0)'),\n margin=dict(l=0, r=0, b=0, t=0))\n\n\nfig.show()\n\n \n \n \n\n\n \n \n\n\nplot the eigenvalues by first converting the units to joules\n\nhbar = 1.055e-34\na0 = 5.29e-11\nm = 9.11e-31 # Mass of an electron\nJ_to_eV = 6.242e18 # convert from Joules to eV\nconversion = hbar**2 / m / delta**2 / a0**2 * J_to_eV \nconverted_eigenvalues = eigenvalues.cpu() * conversion\n\nplt.figure()\nplt.scatter(list(range(num_states)), converted_eigenvalues, label=\"Enegy Eigenstates\")\nplt.xlim(0,20)\nplt.title(\"Eigenstates of a Hydrogen atom (Orbitals)\")\nplt.xlabel(\"Energy Level\")\nplt.ylabel(\"Energy Eigenvalue (eV)\")\nplt.legend()\nplt.show()"
28+
"text": "Calculations\nWith this we can finally start on the calculations. Start by defining a Potential (Noting this is really potenetial energy and not electric potential). The potential is then the potential energy of an electron in an atom of hydrogen which is \\[\nV(r) = -\\frac{e^2}{4 \\pi \\epsilon_0 r} = -\\frac{1}{ma_0 r},\\, a_0 = \\frac{4\\pi\\epsilon_0\\hbar^2}{e^2m}\\approx 5.29 \\times 10^-11m\n\\] This allows us to define the radius in terms of the bohr radius \\(a_0\\). We can then rearange the equation to solve for \\(m\\delta^2V(x)\\) and write our function as \\[\nm\\delta^2V(x)= -\\frac{\\delta^2}{a_0 r} = -\\frac{(\\delta/a_0)^2}{(r/a_0)}\n\\] Changing the units to a_0 by dividing by \\(a_0/a_0\\)\nStart by defining values for our grid and delta\n\nN = 120\n# Note that both the coordinates and delta are measured in units of a_0\nX,Y,Z = np.mgrid[-25:25:N*1j,-25:25:N*1j,-25:25:N*1j] # create a grid from -25 to 25 a_0\ndelta = np.diff(X[:,0,0])[0] # get the step size\n\nNow we write a function to get the potential as follows\n\ndef get_potential(x,y,z):\n # since the units are in a_0 we can treat the a_0 in the equation defined above as 1\n # As well we add 1e-10 to the value of r to avoid any infinities at r=0\n return -delta**2/np.sqrt(x**2+y**2+z**2 + 1e-10)\n\nV0 = get_potential(X,Y,Z) # This creates a 3d grid of potentials\nV0.shape # shape should be n*n*n we really want this to be a diagonal matrix in M_{n^3}(R)\n\n(120, 120, 120)\n\n\nWe want to get our proper \\(V\\) matrix which we can do along with our \\(D\\) matrix\n\ndiag = np.ones([N]) # create a vector of ones in R^n\ndiags = np.array([diag, -2*diag, diag]) # create a n*3 matrix representing the diagonals in D\nD = sparse.spdiags(diags, np.array([-1,0,1]), N, N) # Create D from the diags\nT = -1/2 * sparse.kronsum(sparse.kronsum(D,D), D) # Create T from D\nV = sparse.diags(V0.reshape(N**3), (0)) # Create a sparse matrix from V0\nH = T+V # Finally create the hamiltonian matrix\nH.shape # Print out the shape of H which should be (N^3,N^3)\n\n(1728000, 1728000)\n\n\nConvert H so that it is on the gpu. This makes finding the eigenvalues easier\n\nH = H.tocoo()\nH = torch.sparse_coo_tensor(indices=torch.tensor([H.row, H.col]), values=torch.tensor(H.data), size=H.shape).to(device)\n\n/tmp/ipykernel_248606/2973072149.py:2: UserWarning:\n\nCreating a tensor from a list of numpy.ndarrays is extremely slow. Please consider converting the list to a single numpy.ndarray with numpy.array() before converting to a tensor. (Triggered internally at /build/python-pytorch/src/pytorch/torch/csrc/utils/tensor_new.cpp:254.)\n\n\n\nFinally we can compute the eigenvalues/eigenvectors as follows\n\nnum_states = 20 # number of states to calculate\nstart = time.perf_counter()\neigenvalues, eigenvectors = torch.lobpcg(H, k=num_states, largest=False)\nend = time.perf_counter()\nelapsed = timedelta(seconds = end-start)\nprint(\"Time to calculate:\", elapsed)\n\nTime to calculate: 0:43:18.962407\n\n\nHere is a function to get a an eigenvector given an energy level\n\ndef get_e(n):\n return eigenvectors.T[n].reshape((N,N,N)).cpu().numpy()\n\nWe can compute an object given a certain energy level and plot it\n\neigenstate = 6 # Eigenstate to display\nverts, faces, _, _ = measure.marching_cubes(get_e(eigenstate)**2, 1e-6, spacing=(0.1, 0.1, 0.1))\nintensity = np.linalg.norm(verts, axis=1)\n\nfig = go.Figure(data=[go.Mesh3d(x=verts[:, 0], y=verts[:, 1], z=verts[:, 2], \n i=faces[:, 0], j=faces[:, 1], k=faces[:, 2],\n intensity=intensity,\n colorscale='Agsunset',\n opacity=0.5)])\n\nfig = fig.update_layout(scene=dict(xaxis=dict(visible=False),\n yaxis=dict(visible=False),\n zaxis=dict(visible=False),\n bgcolor='rgb(0, 0, 0)'),\n margin=dict(l=0, r=0, b=0, t=0))\n\nfig.show()\n\n \n \n \n\n\n \n \n\n\nplot the eigenvalues by first converting the units to joules\n\nhbar = 1.055e-34\na0 = 5.29e-11\nm = 9.11e-31 # Mass of an electron\nJ_to_eV = 6.242e18 # convert from Joules to eV\nconversion = hbar**2 / m / delta**2 / a0**2 * J_to_eV \nconverted_eigenvalues = eigenvalues.cpu() * conversion\n\nplt.figure()\nplt.scatter(list(range(num_states)), converted_eigenvalues, label=\"Enegy Eigenstates\")\nplt.xlim(0,20)\nplt.title(\"Eigenstates of a Hydrogen atom (Orbitals)\")\nplt.xlabel(\"Energy Level\")\nplt.ylabel(\"Energy Eigenvalue (eV)\")\nplt.legend()\nplt.show()"
2929
},
3030
{
3131
"objectID": "experiments/wave_equation/index.html",

0 commit comments

Comments
 (0)