### Temporary directory setup Source: https://github.com/loganbvh/py-tdgl/blob/main/docs/notebooks/quickstart.ipynb Sets up a temporary directory for saving simulation data. ```python tempdir = tempfile.TemporaryDirectory() ``` -------------------------------- ### Conda Environment Setup Source: https://github.com/loganbvh/py-tdgl/blob/main/README.md Example of creating and activating a conda environment for pyTDGL. ```bash conda create --name tdgl python="3.12" conda activate tdgl ``` -------------------------------- ### Install PARDISO Source: https://github.com/loganbvh/py-tdgl/blob/main/docs/installation.rst Commands to install the MKL PARDISO sparse solver using pip or conda. ```bash # After activating your conda environment for tdgl pip install pypardiso # or conda install -c conda-forge pypardiso # or pip install tdgl[pardiso] ``` -------------------------------- ### Draw the device Source: https://github.com/loganbvh/py-tdgl/blob/main/docs/notebooks/quickstart.ipynb Draws the device geometry. ```python fig, ax = device.draw() ``` -------------------------------- ### Install UMFPACK Source: https://github.com/loganbvh/py-tdgl/blob/main/docs/installation.rst Commands to install the UMFPACK sparse solver using conda and pip. ```bash # After activating your conda environment for tdgl conda install -c conda-forge suitesparse pip install swig scikit-umfpack # or pip install tdgl[umfpack] ``` -------------------------------- ### Define device geometry Source: https://github.com/loganbvh/py-tdgl/blob/main/docs/notebooks/quickstart.ipynb Sets up the material parameters and initial geometry for the superconducting device. ```python length_units = "um" # Material parameters xi = 0.5 london_lambda = 2 d = 0.1 layer = tdgl.Layer(coherence_length=xi, london_lambda=london_lambda, thickness=d, gamma=1) # Device geometry total_width = 5 total_length = 3.5 * total_width link_width = total_width / 3 ``` -------------------------------- ### Plot the mesh Source: https://github.com/loganbvh/py-tdgl/blob/main/docs/notebooks/quickstart.ipynb Plots the device with the generated mesh. ```python fig, ax = device.plot(mesh=True, legend=False) _ = ax.set_ylim(-5, 5) ``` -------------------------------- ### Creating animation Source: https://github.com/loganbvh/py-tdgl/blob/main/docs/notebooks/quickstart.ipynb Generates an animation of the device dynamics, including order parameter, phase, and scalar potential, if MAKE_ANIMATIONS is true. ```python if MAKE_ANIMATIONS: field_current_video = make_video_from_solution( field_current_solution, quantities=["order_parameter", "phase", "scalar_potential"], figsize=(6.5, 4), ) display(field_current_video) ``` -------------------------------- ### Helper function for creating videos Source: https://github.com/loganbvh/py-tdgl/blob/main/docs/notebooks/quickstart.ipynb A helper function that animates a tdgl.Solution object for embedding in a notebook. ```python def make_video_from_solution( solution, quantities=("order_parameter", "phase"), fps=20, figsize=(5, 4), ): """Generates an HTML5 video from a tdgl.Solution.""" with tdgl.non_gui_backend(): with h5py.File(solution.path, "r") as h5file: anim = create_animation( h5file, quantities=quantities, fps=fps, figure_kwargs=dict(figsize=figsize), ) video = anim.to_html5_video() return HTML(video) ``` -------------------------------- ### Check CUDA Toolkit installation Source: https://github.com/loganbvh/py-tdgl/blob/main/docs/installation.rst Command to verify if the NVIDIA CUDA Toolkit is installed and accessible. ```bash nvcc --version ``` -------------------------------- ### Simulating dynamics with applied field and current Source: https://github.com/loganbvh/py-tdgl/blob/main/docs/notebooks/quickstart.ipynb Sets up solver options and solves the device dynamics with applied vector potential and terminal currents, using a seed solution from a previous simulation. ```python options = tdgl.SolverOptions( solve_time=200, output_file=os.path.join(tempdir.name, "weak-link.h5"), field_units="mT", current_units="uA", ) field_current_solution = tdgl.solve( device, options, applied_vector_potential=0.4, terminal_currents=dict(source=12, drain=-12), # The seed solution will be used as the initial state of the film. seed_solution=zero_current_solution, ) ``` -------------------------------- ### Verify tdgl installation using the test suite Source: https://github.com/loganbvh/py-tdgl/blob/main/docs/installation.rst Runs the tdgl test suite from the command line. ```bash python -m tdgl.testing ``` -------------------------------- ### Install CUDA Toolkit using Conda Source: https://github.com/loganbvh/py-tdgl/blob/main/docs/installation.rst Installs the CUDA Toolkit from the NVIDIA conda channel. ```bash conda install cuda -c nvidia ``` -------------------------------- ### Create an animation of the simulated dynamics Source: https://github.com/loganbvh/py-tdgl/blob/main/docs/notebooks/quickstart.ipynb Generates an animation of the simulated dynamics, showing order parameter, phase, and scalar potential. It includes a note about adaptive time steps. ```python if MAKE_ANIMATIONS: zero_field_video = make_video_from_solution( zero_field_solution, quantities=["order_parameter", "phase", "scalar_potential"], figsize=(6.5, 4), ) display(zero_field_video) ``` -------------------------------- ### Update PATH and LD_LIBRARY_PATH for CUDA Source: https://github.com/loganbvh/py-tdgl/blob/main/docs/installation.rst Sets environment variables to point to the CUDA installation. The first block is for direct installation from NVIDIA, and the second is for conda installations. ```bash # If you installed CUDA Toolkit directly from the NVIDIA website, # resulting in CUDA being installed in /usr/local/cuda: export PATH=/usr/local/cuda/bin${PATH:+:${PATH}} export LD_LIBRARY_PATH=/usr/local/cuda/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}} # If you installed CUDA using conda, activate the appropriate conda environment and run: export PATH=${CONDA_PREFIX}/bin${PATH:+:${PATH}} export LD_LIBRARY_PATH=${CONDA_PREFIX}/lib${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}} ``` -------------------------------- ### Editable Installation Source: https://github.com/loganbvh/py-tdgl/blob/main/README.md Instructions for an editable installation of pyTDGL from its GitHub repository, including development and documentation dependencies. ```bash git clone https://github.com/loganbvh/py-tdgl.git cd py-tdgl pip install -e ".[dev,docs]" ``` -------------------------------- ### Cleanup temporary directory Source: https://github.com/loganbvh/py-tdgl/blob/main/docs/notebooks/quickstart.ipynb Cleans up the temporary directory used for storing simulation output. ```python tempdir.cleanup() ``` -------------------------------- ### Creating animation from solution Source: https://github.com/loganbvh/py-tdgl/blob/main/docs/notebooks/quickstart.ipynb This code snippet conditionally creates and displays a video animation from the simulation solution if the `MAKE_ANIMATIONS` flag is set to true. ```python if MAKE_ANIMATIONS: zero_current_video = make_video_from_solution(zero_current_solution) display(zero_current_video) ``` -------------------------------- ### Imports and Setup Source: https://github.com/loganbvh/py-tdgl/blob/main/docs/notebooks/screening.ipynb Imports necessary libraries and sets up plotting configurations. ```python %config InlineBackend.figure_formats = {"retina", "png"} import os os.environ["OPENBLAS_NUM_THREADS"] = "1" import matplotlib.pyplot as plt import numpy as np plt.rcParams["figure.figsize"] = (7.5, 2.5) import tdgl from tdgl.geometry import box, circle ``` -------------------------------- ### Install pyTDGL and ffmpeg Source: https://github.com/loganbvh/py-tdgl/blob/main/docs/notebooks/logo.ipynb Automatically installs the pyTDGL library from GitHub if running in Google Colab and installs ffmpeg. ```python # Automatically install tdgl from GitHub only if running in Google Colab if "google.colab" in str(get_ipython()): %pip install --quiet git+https://github.com/loganbvh/py-tdgl.git !apt install ffmpeg ``` -------------------------------- ### Plotting dynamics Source: https://github.com/loganbvh/py-tdgl/blob/main/docs/notebooks/quickstart.ipynb Plots the dynamics of the voltage across the device, excluding the mean voltage. ```python fig, axes = field_current_solution.dynamics.plot(tmin=10, mean_voltage=False) ``` -------------------------------- ### Visualize voltage spikes and phase slips Source: https://github.com/loganbvh/py-tdgl/blob/main/docs/notebooks/quickstart.ipynb Zooms in on a time slice to show the relationship between voltage spikes and $2\pi$ phase slips. ```python dynamics = zero_field_solution.dynamics indices = dynamics.time_slice(tmax=75) fig, ax = plt.subplots() # Plot the voltage on the left y axis ax.plot(dynamics.time[indices], dynamics.voltage()[indices], "C0-") ax.tick_params(axis="y", color="C0", labelcolor="C0") ax.set_ylabel("Voltage, $\Delta\mu$ [$V_0$]", color="C0") ax.set_xlabel("Time, $t$ [$\tau_0$]") # Plot the phase difference on the right y axis bx = ax.twinx() unwrapped_phase = np.unwrap(dynamics.phase_difference()[indices]) bx.plot(dynamics.time[indices], unwrapped_phase / np.pi, "C1") bx.grid(axis="both") bx.spines["right"].set_color("C1") bx.spines["left"].set_color("C0") bx.tick_params(axis="y", color="C1", labelcolor="C1") _ = bx.set_ylabel("Phase difference, $\Delta\theta/\pi$", color="C1") ``` -------------------------------- ### Import necessary libraries Source: https://github.com/loganbvh/py-tdgl/blob/main/docs/notebooks/quickstart.ipynb Imports common libraries for plotting, data handling, and the tdgl library. ```python %config InlineBackend.figure_formats = {"retina", "png"} import os import tempfile os.environ["OPENBLAS_NUM_THREADS"] = "1" from IPython.display import HTML, display import h5py import matplotlib.pyplot as plt import numpy as np plt.rcParams["figure.figsize"] = (5, 4) import tdgl from tdgl.geometry import box, circle from tdgl.visualization.animate import create_animation ``` -------------------------------- ### Plot the dynamics of voltage and phase difference Source: https://github.com/loganbvh/py-tdgl/blob/main/docs/notebooks/quickstart.ipynb Plots the dynamics of the voltage and phase difference between the top and bottom halves of the device, highlighting a specific time point. ```python fig, axes = zero_field_solution.dynamics.plot() for ax in axes: ax.axvline(t0, color="k", alpha=0.5) ``` -------------------------------- ### Install via pip from PyPI Source: https://github.com/loganbvh/py-tdgl/blob/main/README.md Installation command for pyTDGL using pip from the Python Package Index. ```bash pip install tdgl ``` -------------------------------- ### Install via pip from GitHub repository Source: https://github.com/loganbvh/py-tdgl/blob/main/README.md Installation command for pyTDGL using pip directly from its GitHub repository. ```bash pip install git+https://github.com/loganbvh/py-tdgl.git ``` -------------------------------- ### Plot a snapshot of the order parameter in the middle of a phase slip Source: https://github.com/loganbvh/py-tdgl/blob/main/docs/notebooks/quickstart.ipynb Plots a snapshot of the order parameter at a specific time step (t0). ```python # Plot a snapshot of the order parameter in the middle of a phase slip t0 = 112 zero_field_solution.solve_step = zero_field_solution.closest_solve_step(t0) fig, axes = zero_field_solution.plot_order_parameter(figsize=(5.5, 4)) ``` -------------------------------- ### Install py-tdgl Source: https://github.com/loganbvh/py-tdgl/blob/main/docs/notebooks/screening.ipynb Automatically install tdgl from GitHub only if running in Google Colab. ```python # Automatically install tdgl from GitHub only if running in Google Colab if "google.colab" in str(get_ipython()): %pip install --quiet git+https://github.com/loganbvh/py-tdgl.git ``` -------------------------------- ### Plotting supercurrent density Source: https://github.com/loganbvh/py-tdgl/blob/main/docs/notebooks/quickstart.ipynb This code snippet generates a plot visualizing the supercurrent density flowing within the device. ```python fig, ax = zero_current_solution.plot_currents(min_stream_amp=0.075, vmin=0, vmax=10) ``` -------------------------------- ### Simulating vortex dynamics with zero bias current Source: https://github.com/loganbvh/py-tdgl/blob/main/docs/notebooks/quickstart.ipynb This code snippet sets up and runs a simulation of vortex dynamics with zero bias current. It defines solver options, including output file and units, and then applies a time-dependent magnetic field. The simulation is executed using `tdgl.solve`. ```python options = tdgl.SolverOptions( solve_time=200, output_file=os.path.join(tempdir.name, "weak-link-zero-current.h5"), field_units = "mT", current_units="uA", ) RAMP_FIELD = True if RAMP_FIELD: from tdgl.sources import LinearRamp, ConstantField # Ramp the applied field from 0 to 0.4 mT between t=0 and t=100, then hold it at 0.4 mT. applied_vector_potential = ( LinearRamp(tmin=0, tmax=100) * ConstantField(0.4, field_units=options.field_units, length_units=device.length_units) ) else: # If applied_vector_potential is given as a single number, # it is interpreted to mean the vector potential associated with a # uniform out-of-plane magnetic field with the specified strength. # This is simply shorthand for # ConstantField(0.4, field_units=options.field_units, length_units=device.length_units). applied_vector_potential = 0.4 zero_current_solution = tdgl.solve( device, options, applied_vector_potential=applied_vector_potential, ) ``` -------------------------------- ### Verify tdgl installation using Python session Source: https://github.com/loganbvh/py-tdgl/blob/main/docs/installation.rst Runs the tdgl test suite within a Python session. ```python >>> import tdgl.testing >>> tdgl.testing.run() ``` -------------------------------- ### Animation flag Source: https://github.com/loganbvh/py-tdgl/blob/main/docs/notebooks/quickstart.ipynb A flag to control whether animations are generated. ```python MAKE_ANIMATIONS = True ``` -------------------------------- ### Define the device geometry Source: https://github.com/loganbvh/py-tdgl/blob/main/docs/notebooks/quickstart.ipynb This code defines the geometry of the superconducting weak link device, including the film, notches, holes, and terminals. ```python right_notch = ( tdgl.Polygon(points=box(total_width)) .rotate(45) .translate(dx=(np.sqrt(2) * total_width + link_width) / 2) ) left_notch = right_notch.scale(xfact=-1) film = ( tdgl.Polygon("film", points=box(total_width, total_length)) .difference(right_notch, left_notch) .resample(401) .buffer(0) ) # Holes in the film round_hole = ( tdgl.Polygon("round_hole", points=circle(link_width / 2)) .translate(dy=total_length / 5) ) square_hole = ( tdgl.Polygon("square_hole", points=box(link_width)) .rotate(45) .translate(dy=-total_length / 5) ) # Current terminals source = ( tdgl.Polygon("source", points=box(1.1 * total_width, total_length / 100)) .translate(dy=total_length / 2) ) drain = source.scale(yfact=-1).set_name("drain") # Voltage measurement points probe_points = [(0, total_length / 2.5), (0, -total_length / 2.5)] ``` ```python device = tdgl.Device( "weak_link", layer=layer, film=film, holes=[round_hole, square_hole], terminals=[source, drain], probe_points=probe_points, length_units=length_units, ) ``` -------------------------------- ### Calculating fluxoid from boundary phases Source: https://github.com/loganbvh/py-tdgl/blob/main/docs/notebooks/quickstart.ipynb This code calculates the fluxoid for each hole by measuring the number of $2\pi$ phase windings around the hole using the `boundary_phases` method. ```python boundary_phases = zero_current_solution.boundary_phases() for hole in device.holes: phases = boundary_phases[hole.name].phases fluxoid_from_phase = (phases[-1] - phases[0]) / (2 * np.pi) print(f"Total fluxoid for {hole.name!r}: {fluxoid_from_phase:.2f} Phi_0") ``` -------------------------------- ### Calculate and print the current through the cross-section Source: https://github.com/loganbvh/py-tdgl/blob/main/docs/notebooks/quickstart.ipynb Calculates the current through the defined cross-section and prints the measured current. ```python current = zero_field_solution.current_through_path(cross_section) print(f"Measured current: {current:.3f~P}") ``` -------------------------------- ### Define the coordinates at which to evaluate the sheet current density Source: https://github.com/loganbvh/py-tdgl/blob/main/docs/notebooks/quickstart.ipynb Defines the x and y coordinates for a cross-section and plots it. ```python x = np.linspace(-total_width / 2, total_width / 2, 401) y = 2 * np.ones_like(x) cross_section = np.array([x, y]).T for ax in axes: _ = ax.plot(x, y, "C1--") ``` -------------------------------- ### Plotting the order parameter Source: https://github.com/loganbvh/py-tdgl/blob/main/docs/notebooks/quickstart.ipynb This code snippet generates a plot of the order parameter, which helps visualize the distribution of vortices within the device. It also overlays polygons representing fluxoids around specific locations. ```python fig, axes = zero_current_solution.plot_order_parameter(figsize=(5.5, 4)) fluxoid_polygons = { # name: (circle radius, circle center) "Top vortex": (1, (0, 6)), "Round hole": (1.5, (0, 3.5)), "Square hole": (1.5, (0, -3.5)), "Bottom vortex": (1, (0, -6)), } for name, (radius, center) in fluxoid_polygons.items(): polygon = circle(radius, center=center, points=201) for ax in axes: ax.plot(*polygon.T) ``` -------------------------------- ### Simulate with zero applied field Source: https://github.com/loganbvh/py-tdgl/blob/main/docs/notebooks/quickstart.ipynb Simulates the device with zero applied magnetic field and a constant bias current. The `tdgl.SolverOptions` are configured to control the simulation time, output file, and saving frequency. The `tdgl.solve()` function executes the simulation. ```python options = tdgl.SolverOptions( # Allow some time to equilibrate before saving data. skip_time=100, solve_time=150, output_file=os.path.join(tempdir.name, "weak-link-zero-field.h5"), field_units = "mT", current_units="uA", save_every=100, ) # If you do not provide an applied_vector_potential, tdgl defaults to zero applied field. zero_field_solution = tdgl.solve( device, options, # terminal_currents must satisfy current conservation, i.e., # sum(terminal_currents.values()) == 0. terminal_currents=dict(source=12, drain=-12), ) ``` -------------------------------- ### Calculating fluxoid for specific regions Source: https://github.com/loganbvh/py-tdgl/blob/main/docs/notebooks/quickstart.ipynb This code calculates and prints the fluxoid for predefined regions (vortices and holes) within the device. It iterates through the defined fluxoid polygons and computes the fluxoid for each. ```python for name, (radius, center) in fluxoid_polygons.items(): polygon = circle(radius, center=center, points=201) fluxoid = zero_current_solution.polygon_fluxoid(polygon, with_units=False) print( f"{name}:\n\t{fluxoid} Phi_0\n\tTotal fluxoid: {sum(fluxoid):.2f} Phi_0\n" ) ``` -------------------------------- ### Disabling adaptive time step Source: https://github.com/loganbvh/py-tdgl/blob/main/docs/background.rst Example of how to disable the adaptive time step algorithm by setting 'adaptive=False' in the SolverOptions. ```python tdgl.SolverOptions(..., adaptive=False, ...) ``` -------------------------------- ### Plot current density Source: https://github.com/loganbvh/py-tdgl/blob/main/docs/notebooks/quickstart.ipynb Plots the sheet current density $\mathbf{K}(\mathbf{r})$ at the final time step and measures the total current flowing from top to bottom. The dashed orange line indicates the curve through which the total current is calculated. ```python fig, axes = plt.subplots(1, 2, figsize=(6, 4)) _ = zero_field_solution.plot_currents(ax=axes[0], streamplot=False) _ = zero_field_solution.plot_currents(ax=axes[1]) ``` -------------------------------- ### Solver Options (With Screening) Source: https://github.com/loganbvh/py-tdgl/blob/main/docs/notebooks/screening.ipynb Sets up solver options for a simulation including screening. ```python options = tdgl.SolverOptions( solve_time=5, field_units="mT", current_units="uA", include_screening=True, screening_tolerance=1e-6, dt_max=1e-3, ) screening_solution = tdgl.solve(device, options, applied_vector_potential=0.1) ``` -------------------------------- ### Set up temporary directory for output Source: https://github.com/loganbvh/py-tdgl/blob/main/docs/notebooks/logo.ipynb Configures the output path for simulation results, using a temporary directory if USE_TEMPDIR is True. ```python if USE_TEMPDIR: tempdir = tempfile.TemporaryDirectory() output_path = tempdir.name else: output_path = "." ``` -------------------------------- ### Import necessary libraries and set up environment variables Source: https://github.com/loganbvh/py-tdgl/blob/main/docs/notebooks/py-mesh.ipynb Imports libraries like os, tempfile, numpy, matplotlib, and tdgl. Sets up environment variables for OpenBLAS and configures matplotlib for inline plotting and figure size. ```python %config InlineBackend.figure_formats = {"retina", "png"} %matplotlib inline import os import tempfile from typing import List, Tuple os.environ["OPENBLAS_NUM_THREADS"] = "1" import numpy as np import matplotlib as mpl from matplotlib.path import Path from matplotlib.textpath import TextPath from matplotlib.font_manager import FontProperties import matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = (5, 4) plt.rcParams["font.size"] = 11 import tdgl from tdgl.geometry import box, ensure_unique, close_curve SAVE_FIGURES = False image_path = os.path.join(os.pardir, "images") ``` -------------------------------- ### Solver Options (No Screening) Source: https://github.com/loganbvh/py-tdgl/blob/main/docs/notebooks/screening.ipynb Sets up solver options for a simulation without screening. ```python options = tdgl.SolverOptions( solve_time=5, field_units="mT", current_units="uA", include_screening=False, ) no_screening_solution = tdgl.solve(device, options, applied_vector_potential=0.1) ``` -------------------------------- ### Set up solver options and applied field Source: https://github.com/loganbvh/py-tdgl/blob/main/docs/notebooks/logo.ipynb Configures the TDGL solver options, including simulation time, field units, and output file. Defines the applied vector potential as a linear ramp followed by a constant field. ```python options = tdgl.SolverOptions( solve_time=800, field_units="mT", output_file=os.path.join(output_path, "py.h5"), ) # Ramp the applied field from 0 to 1.8 mT between t=0 and t=100, then hold it at 1.8 mT. applied_vector_potential = ( LinearRamp(tmin=0, tmax=100) * ConstantField(1.8, field_units=options.field_units, length_units=device.length_units) ) ``` -------------------------------- ### Define Layer properties Source: https://github.com/loganbvh/py-tdgl/blob/main/docs/notebooks/py-mesh.ipynb Sets up the layer properties for the device, including London lambda, coherence length, and thickness. ```python fontsize = 10 fontprops = FontProperties(weight="bold") xi = 0.4 layer = tdgl.Layer(london_lambda=4, coherence_length=xi, thickness=0.1) ``` -------------------------------- ### Mesh the device and plot Source: https://github.com/loganbvh/py-tdgl/blob/main/docs/notebooks/py-mesh.ipynb Generates a mesh for the device with a specified maximum edge length and smooth parameter, then plots the meshed device. ```python fig, ax = plt.subplots() device.make_mesh(max_edge_length=xi / 2, smooth=100) _ = device.plot(ax=ax, mesh=True, legend=False) ``` -------------------------------- ### Import necessary libraries and set up plotting Source: https://github.com/loganbvh/py-tdgl/blob/main/docs/notebooks/logo.ipynb Imports libraries for numerical operations, plotting, and the tdgl library. Sets up matplotlib configurations for inline plotting and figure size. ```python %config InlineBackend.figure_formats = {"retina", "png"} %matplotlib inline import os import tempfile from typing import List, Tuple os.environ["OPENBLAS_NUM_THREADS"] = "1" import numpy as np import matplotlib as mpl from matplotlib.path import Path from matplotlib.textpath import TextPath from matplotlib.font_manager import FontProperties import matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = (5, 4) plt.rcParams["font.size"] = 11 import tdgl from tdgl.geometry import box, ensure_unique, close_curve from tdgl.sources import LinearRamp, ConstantField USE_TEMPDIR = True SAVE = False MAKE_ANIMATIONS = True image_path = os.path.join(os.pardir, "images") ``` -------------------------------- ### Create Device geometry Source: https://github.com/loganbvh/py-tdgl/blob/main/docs/notebooks/py-mesh.ipynb Creates the 'py' device by combining the outer polygons of 'p' and 'y', and including the inner polygon of 'p' as a hole. ```python p_outer, p_inner = make_polygons("p", fontsize, fontprops) y_outer, = make_polygons("y", fontsize, fontprops) film = p_outer.union(y_outer.translate(dx=5.75)) device = tdgl.Device("py", layer=layer, film=film, holes=[p_inner]) ``` -------------------------------- ### Function to create video from solution Source: https://github.com/loganbvh/py-tdgl/blob/main/docs/notebooks/logo.ipynb Defines a function that generates an HTML5 video from a tdgl.Solution object using the create_animation utility. ```python def make_video_from_solution(solution, **kwargs): """Generates an HTML5 video from a tdgl.Solution.""" with tdgl.non_gui_backend(): with h5py.File(solution.path, "r") as h5file: anim = create_animation(h5file, **kwargs) video = anim.to_html5_video() return HTML(video) ``` -------------------------------- ### Analyze Screening Solution Source: https://github.com/loganbvh/py-tdgl/blob/main/docs/notebooks/screening.ipynb Calculates and prints maximum current density and fluxoid values for the screening case. ```python K = screening_solution.current_density K_max = np.sqrt(K[:, 0]**2 + K[:, 1]**2).max() print(f"Maximum sheet current density: {K_max:.1f~P}") fig, ax = screening_solution.plot_currents() _ = ax.set_title("With screening", fontsize=18) for i, curve in enumerate(fluxoid_curves): ax.plot(*curve.T, "--", lw=2, label=f"Curve {i}") fluxoid = screening_solution.polygon_fluxoid(curve) total_fluxoid = sum(fluxoid).magnitude error = abs(total_fluxoid / fluxoid.flux_part.magnitude) print(f"Curve {i}: total fluxoid {sum(fluxoid):.3e}, (error {100 * error:.1f}%)") _ = ax.legend(bbox_to_anchor=(1.3, 1), loc="upper left") ``` -------------------------------- ### Draw the device Source: https://github.com/loganbvh/py-tdgl/blob/main/docs/notebooks/py-mesh.ipynb Draws the device geometry without a legend. ```python fig, ax = device.draw(legend=False) ``` -------------------------------- ### CLI Tool: tdgl.visualize Source: https://github.com/loganbvh/py-tdgl/blob/main/docs/api/visualization.rst The command line interface for animating and interactively viewing TDGL simulation results. ```bash python -m tdgl.visualize ``` -------------------------------- ### Import necessary libraries for animation Source: https://github.com/loganbvh/py-tdgl/blob/main/docs/notebooks/logo.ipynb Imports libraries required for creating animations and handling HDF5 files. ```python from IPython.display import display, HTML import h5py from tdgl.visualization.animate import create_animation ``` -------------------------------- ### Version Table Source: https://github.com/loganbvh/py-tdgl/blob/main/docs/notebooks/screening.ipynb Displays the version table for tdgl. ```python tdgl.version_table() ``` -------------------------------- ### Analyze No Screening Solution Source: https://github.com/loganbvh/py-tdgl/blob/main/docs/notebooks/screening.ipynb Calculates and prints maximum current density and fluxoid values for the no-screening case. ```python K = no_screening_solution.current_density K_max = np.sqrt(K[:, 0]**2 + K[:, 1]**2).max() print(f"Maximum sheet current density: {K_max:.1f~P}") fig, ax = no_screening_solution.plot_currents() _ = ax.set_title("No screening", fontsize=18) for i, curve in enumerate(fluxoid_curves): fluxoid = no_screening_solution.polygon_fluxoid(curve) total_fluxoid = sum(fluxoid).magnitude error = abs(total_fluxoid / fluxoid.flux_part.magnitude) print(f"Curve {i}: total fluxoid {sum(fluxoid):.3e}, (error {100* error:.1f}%)") ax.plot(*curve.T, "--", lw=2, label=f"Curve {i}") _ = ax.legend(bbox_to_anchor=(1.3, 1), loc="upper left") ``` -------------------------------- ### Plot mesh details Source: https://github.com/loganbvh/py-tdgl/blob/main/docs/notebooks/py-mesh.ipynb Plots the mesh of the device on three subplots, highlighting sites, edges, and dual edges with different styles. ```python fig, axes = plt.subplots(1, 3, figsize=(9, 3), gridspec_kw=dict(width_ratios=[1.45, 1, 1])) ax, bx, cx = axes mesh = device.mesh for a in (ax, bx, cx): a.set_xticks([]) a.set_yticks([]) a.set_aspect("equal") # Draw the "py" film on the left axes. scale = 1 / device.coherence_length.magnitude patch = device.scale(xfact=scale, yfact=scale).patches()["p"] patch.set_facecolor("C4") patch.set_edgecolor("C4") patch.set_alpha(0.5) ax.add_artist(patch) ax.set_xlim(mesh.x.min() - 1, mesh.x.max() + 1) ax.set_ylim(mesh.y.min() - 0.5, mesh.y.max() + 0.5) # Plot the mesh on the center and right axes. for a, lw, marker in [(bx, 0.75, "."), (cx, 2, "o")]: _ = mesh.plot( ax=a, show_sites=False, site_color="k", show_edges=True, edge_color="C1", show_dual_edges=True, dual_edge_color="C0", linewidth=lw, marker=marker, ) # Zoom in on the relevant parts of the mesh bx.set_xlim(5, 10) bx.set_ylim(0, 5) ``` -------------------------------- ### Import necessary libraries and set up plotting. Source: https://github.com/loganbvh/py-tdgl/blob/main/docs/notebooks/mesh.ipynb Imports matplotlib, numpy, and tdgl. Sets up inline plotting for matplotlib and defines a SAVE flag. ```python %config InlineBackend.figure_formats = {"retina", "png"} import matplotlib.pyplot as plt import numpy as np import matplotlib as mpl import tdgl from tdgl.geometry import box, circle, close_curve SAVE = False ``` -------------------------------- ### Generate and display animation Source: https://github.com/loganbvh/py-tdgl/blob/main/docs/notebooks/logo.ipynb Conditionally generates and displays an animation as an HTML5 video if MAKE_ANIMATIONS is true. ```python if MAKE_ANIMATIONS: video = make_video_from_solution( solution, quantities=["order_parameter", "phase"], dpi=100, fps=50, title_off=True, axes_off=True, max_frame=600, max_cols=1, figure_kwargs=dict(figsize=(4.5, 6)), ) display(video) ``` -------------------------------- ### MIT License Source: https://github.com/loganbvh/py-tdgl/blob/main/docs/about/license.rst The MIT License text for the py-tdgl project. ```text MIT License Copyright (c) 2022-2026 Logan Bishop-Van Horn Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ```