### Install TorchGDM via pip Source: https://homepages.laas.fr/pwiecha/torchgdm_doc Install the TorchGDM package using pip. This is the primary method for obtaining the library. ```bash $ pip install torchgdm ``` -------------------------------- ### Basic TorchGDM Simulation Setup and Execution Source: https://homepages.laas.fr/pwiecha/torchgdm_doc This snippet demonstrates setting up a simulation with a homogeneous environment, plane wave illumination, and a discretized structure. It includes running the simulation and plotting cross-section results. ```python import torch import matplotlib.pyplot as plt import torchgdm as tg # --- simulation setup # - vacuum environment mat_env = tg.materials.MatConstant(eps=1.0) env = tg.env.EnvHomogeneous3D(env_material=mat_env) # - illumination field(s) and wavelength wavelengths = torch.linspace(550.0, 950.0, 25) plane_wave = tg.env.freespace_3d.PlaneWave(e0p=1.0, e0s=0.0) # - discretized structure structure = tg.struct3d.StructDiscretizedCubic3D( discretization_config=tg.struct3d.cube(l=8), step=30.0, # in nm materials=tg.materials.MatDatabase("GaN"), ) # - define and run simulation. sim = tg.Simulation( structures=[structure], illumination_fields=[plane_wave], environment=env, wavelengths=wavelengths, ) sim.plot_structure() # visualize structure sim.run() # run the main simulation # - post-processing: cross sections cs_results = sim.get_spectra_crosssections() # plot plt.figure(figsize=(5, 4)) plt.plot(tg.to_np(wavelengths), tg.to_np(cs_results["scs"])) plt.xlabel("wavelength (nm)") plt.ylabel("scs (nm^2)") plt.show() ``` -------------------------------- ### Enable GPU Usage in TorchGDM Source: https://homepages.laas.fr/pwiecha/torchgdm_doc This snippet shows how to enable GPU acceleration for TorchGDM simulations. It can be done globally or by setting the device for a specific simulation instance. ```python import torchgdm as tg tg.use_cuda(True) ``` ```python sim = tg.Simulation(...) sim.set_device("cuda") ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.