Skip to content

Instantly share code, notes, and snippets.

View marl0ny's full-sized avatar

Mark Lamorena marl0ny

  • 06:02 (UTC -04:00)
View GitHub Profile
"""
My attempt at implementing a math parser, using the Shunting-yard algorithm
as described by its Wikipedia page:
https://en.wikipedia.org/wiki/Shunting-yard_algorithm
Currently it's a mess, and there are definitely things that I could simplify.
"""
import math
class Token:
"""Plots and animations of single particle quantum mechanics phenomena in 1D
by discretizing the Hamiltonian. This method is described here:
https://wiki.physics.udel.edu/phys824/Discretization_of_1D_continuous_Hamiltonian
"""
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from numpy.linalg import eigh, eig
n = 512
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
/*
2D fluid simulation using the Lattice-Boltzmann algorithm,
based on the Fluid Dynamics Simulation by Daniel Schroeder:
- https://physics.weber.edu/schroeder/fluids/
- http://physics.weber.edu/schroeder/javacourse/LatticeBoltzmann.pdf
Still need to check if the implementation is correct.
SDL is a prerequisite. Compile with the following commands:
g++ -c -I<include path> fluid2d.cpp;
"""
Lorentz transform of 4-vector field. Reference:
- Introduction to Electrodynamics by Griffiths, chapter 10-12
"""
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import sympy as sp
from sympy.parsing.sympy_parser import parse_expr
import numpy as np
from numpy.linalg import eigh
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d.art3d import Poly3DCollection
from skimage import measure
n: int = 256
length: float = 64
x: np.ndarray = np.linspace(-length/2, length/2-length/(n), n,
#!/usr/bin/python3
"""
Cranck-Nicolson method for the Schrödinger equation in 2D.
Jacobi iteration can be used to solve for the system of equations that occurs
when using the Cranck-Nicolson method. This is following an
article found here https://arxiv.org/pdf/1409.8340 by Sadovskyy et al.,
where the Cranck-Nicolson method with Jacobi iteration is
used to solve the Ginzburg-Landau equations, which is similar to
the Schrödinger equation but contains nonlinear terms and
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
N = 256 # Controls the grid size.
L = 8
X, Y = np.meshgrid(np.linspace(-L/2, L/2, N, dtype=float),
np.linspace(-L/2, L/2, N, dtype=float))
DX = X[0, 1] - X[0, 0]
"""
Single particle quantum mechanics in 1D using the split-operator method.
References:
https://www.algorithm-archive.org/contents/
split-operator_method/split-operator_method.html
https://en.wikipedia.org/wiki/Split-step_method
"""
from splitstep import SplitStepMethod
import numpy as np
# Constants (Metric Units)
N = 64 # Number of points to use
L = 1e-8 # Extent of simulation (in meters)
X, Y, Z = np.meshgrid(L*np.linspace(-0.5, 0.5 - 1.0/N, N),
L*np.linspace(-0.5, 0.5 - 1.0/N, N),
L*np.linspace(-0.5, 0.5 - 1.0/N, N))
DX = X[1] - X[0] # Spatial step size