### Install pyTDGL Source: https://py-tdgl.readthedocs.io/en/latest/notebooks/quickstart.html 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 !apt install ffmpeg ``` -------------------------------- ### Temporary directory setup Source: https://py-tdgl.readthedocs.io/en/latest/notebooks/quickstart.html Sets up a temporary directory for saving data, which will be removed at the end of the notebook. ```python tempdir = tempfile.TemporaryDirectory() ``` -------------------------------- ### Solver Options and Applied Field Setup Source: https://py-tdgl.readthedocs.io/en/latest/notebooks/quickstart.html Configures the TDGL solver options and sets up the applied vector potential, which can be a linear ramp or a constant field. ```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, ) ``` -------------------------------- ### Plotting Order Parameter and Fluxoid Calculation Setup Source: https://py-tdgl.readthedocs.io/en/latest/notebooks/quickstart.html Plots the order parameter and defines fluxoid polygons for later calculation. This helps visualize vortex positions. ```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) ``` -------------------------------- ### Draw the device Source: https://py-tdgl.readthedocs.io/en/latest/notebooks/quickstart.html Draws the device geometry. ```python fig, ax = device.draw() ``` -------------------------------- ### Install UMFPACK Source: https://py-tdgl.readthedocs.io/en/latest/_sources/installation.rst.txt Installs 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] ``` -------------------------------- ### Plot the mesh Source: https://py-tdgl.readthedocs.io/en/latest/notebooks/quickstart.html Plots the generated mesh for the device. ```python fig, ax = device.plot(mesh=True, legend=False) _ = ax.set_ylim(-5, 5) ``` -------------------------------- ### Install PARDISO Source: https://py-tdgl.readthedocs.io/en/latest/_sources/installation.rst.txt Installs 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] ``` -------------------------------- ### Install PARDISO Source: https://py-tdgl.readthedocs.io/en/latest/installation.html Installs PyPardiso using pip or conda, or alternatively installs pyTDGL with PARDISO support. ```bash # After activating your conda environment for tdgl pip install pypardiso # or conda install -c conda-forge pypardiso # or pip install tdgl[pardiso] ``` -------------------------------- ### Polygon Bounding Box Source: https://py-tdgl.readthedocs.io/en/latest/_sources/notebooks/polygons.ipynb.txt Example of getting the bounding box of a polygon. ```python from py_tdgl import Polygon coords = [(0, 0), (2, 0), (2, 1), (0, 1)] polygon = Polygon(coords) bounding_box = polygon.bounds print(f"The bounding box of the polygon is: {bounding_box}") ``` -------------------------------- ### Import necessary libraries Source: https://py-tdgl.readthedocs.io/en/latest/notebooks/quickstart.html Imports for plotting, numerical operations, 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 ``` -------------------------------- ### Install pyTDGL from GitHub Source: https://py-tdgl.readthedocs.io/en/latest/installation.html Installs the pyTDGL package directly from its GitHub repository using pip. ```bash pip install git+https://github.com/loganbvh/py-tdgl.git ``` -------------------------------- ### Install pyTDGL from GitHub Source: https://py-tdgl.readthedocs.io/en/latest/_sources/installation.rst.txt Installs the pyTDGL package directly from its GitHub repository using pip. ```bash pip install git+https://github.com/loganbvh/py-tdgl.git ``` -------------------------------- ### Install pyTDGL from PyPI Source: https://py-tdgl.readthedocs.io/en/latest/installation.html Installs the pyTDGL package from the Python Package Index using pip. ```bash pip install tdgl ``` -------------------------------- ### Mesh statistics Source: https://py-tdgl.readthedocs.io/en/latest/notebooks/quickstart.html Prints statistics about the generated mesh. ```python device.mesh_stats() ``` -------------------------------- ### Plotting dynamics Source: https://py-tdgl.readthedocs.io/en/latest/notebooks/quickstart.html This code snippet plots the dynamics of the voltage across the device. ```python fig, axes = field_current_solution.dynamics.plot(tmin=10, mean_voltage=False) ``` -------------------------------- ### Editable installation for development Source: https://py-tdgl.readthedocs.io/en/latest/_sources/installation.rst.txt Installs an editable version of pyTDGL for development purposes, including development and documentation dependencies. ```bash git clone https://github.com/loganbvh/py-tdgl.git cd py-tdgl pip install -e ".[dev,docs]" ``` -------------------------------- ### Install pyTDGL from PyPI Source: https://py-tdgl.readthedocs.io/en/latest/_sources/installation.rst.txt Installs the pyTDGL package from the Python Package Index (PyPI) using pip. ```bash pip install tdgl ``` -------------------------------- ### Voltage measurement points Source: https://py-tdgl.readthedocs.io/en/latest/notebooks/quickstart.html Defines the points for voltage measurements. ```python probe_points = [(0, total_length / 2.5), (0, -total_length / 2.5)] ``` -------------------------------- ### Editable installation for development Source: https://py-tdgl.readthedocs.io/en/latest/installation.html Installs an editable version of pyTDGL for development purposes, including development and documentation dependencies. ```bash git clone https://github.com/loganbvh/py-tdgl.git cd py-tdgl pip install -e ".[dev,docs]" ``` -------------------------------- ### Helper function for creating animations Source: https://py-tdgl.readthedocs.io/en/latest/notebooks/quickstart.html 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) ``` -------------------------------- ### Run tdgl test suite from terminal Source: https://py-tdgl.readthedocs.io/en/latest/_sources/installation.rst.txt Verifies the installation by running the tdgl test suite using a command-line interface. ```bash python -m tdgl.testing ``` -------------------------------- ### Cleaning up temporary directory Source: https://py-tdgl.readthedocs.io/en/latest/notebooks/quickstart.html This code snippet cleans up the temporary directory used for storing simulation output. ```python tempdir.cleanup() ``` -------------------------------- ### Device definition Source: https://py-tdgl.readthedocs.io/en/latest/notebooks/quickstart.html Creates the tdgl.Device object with the defined geometry, terminals, and probe points. ```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, ) ``` -------------------------------- ### Current terminals Source: https://py-tdgl.readthedocs.io/en/latest/notebooks/quickstart.html Defines the source and drain terminals for current flow. ```python 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") ``` -------------------------------- ### Animation flag Source: https://py-tdgl.readthedocs.io/en/latest/notebooks/quickstart.html Flag to control whether animations are generated. ```python MAKE_ANIMATIONS = True ``` -------------------------------- ### Polygon Example Source: https://py-tdgl.readthedocs.io/en/latest/_sources/notebooks/polygons.ipynb.txt Demonstrates the creation and basic usage of a Polygon object. ```python from py_tdgl import Polygon # Example usage polygon = Polygon() polygon.add_point(0, 0) polygon.add_point(1, 0) polygon.add_point(1, 1) polygon.add_point(0, 1) print(polygon.get_area()) print(polygon.get_perimeter()) ``` -------------------------------- ### Polygon Example Source: https://py-tdgl.readthedocs.io/en/latest/_sources/notebooks/polygons.ipynb.txt An example of an SVG polygon element. ```svg Polygon: """Create a shapely Polygon from a list of points. Args: points: A list of (x, y) tuples representing the polygon vertices. Returns: A shapely Polygon object. """ return Polygon(points) def get_polygon_bounding_box(polygon: Polygon) -> Tuple[float, float, float, float]: """Get the bounding box of a shapely Polygon. Args: polygon: A shapely Polygon object. Returns: A tuple (minx, miny, maxx, maxy) representing the bounding box. """ return polygon.bounds ```