Using AI Tools to Generate Physics Simulations: Silicon Solar Cell Example
Using AI Tools to Generate Physics Simulations: Silicon Solar Cell Example
Introduction
Physics simulations allow researchers and engineers to explore complex systems without the expense of building hardware. Recently, generative AI models such as Google's Gemini have shown promise as coding assistants. Argonne National Laboratory notes that large language models (LLMs) can help automate tedious programming tasks and even design algorithms when prompts are well-crafted [1]. They can translate code from one language to another or propose algorithms for a given physical problem [2]. While these tools are not yet fully autonomous, they can accelerate simulation work when combined with human oversight [3].
To illustrate the potential of AI-assisted simulation, this article walks through building a simple silicon solar cell simulation under Air-Mass-1.5 (AM1.5) illumination. The blog demonstrates how generative AI can generate Python code that models the photovoltaic behaviour of a solar cell, discusses the physics behind the model, and points out where human judgment is still necessary.
Why AM1.5 and Standard Test Conditions Matter
Solar cells are usually characterized under Standard Test Conditions (STC) so that devices measured at different locations or times can be compared. STC assumes a solar irradiance of , an AM1.5 solar spectrum, and a cell temperature of [4]. The AM1.5 spectrum corresponds to a sunlight path length 1.5 times the thickness of Earth's atmosphere (approximately a solar zenith angle) [5]. It is considered a good representation of average irradiance in mid-latitude regions [6].
Standardized spectra make comparisons possible because solar irradiance varies greatly by location and atmospheric conditions. The International Commission on Illumination introduced a reference spectrum in the 1970s and recommended a reference intensity of in the 290-3000 nm range [7]. The American Society for Testing and Materials (ASTM) later formalized two AM1.5 spectra—direct normal (AM1.5D) and global (AM1.5G)—which are used for terrestrial solar cell testing [8]. The photovoltaic industry and national laboratories developed these spectra so that experiments could be compared and so that a reasonable approximation of real-world performance could be obtained [9].
How Generative AI Helps With Simulation
In the Argonne webinar, researchers found that LLMs could generate or translate scientific code effectively when given clear prompts [2]. For new code, an iterative approach worked best: first describe the problem and constraints, then ask the model to write a function or algorithm, test the output, and refine the prompt until the code behaves correctly [10]. For code translation (e.g., Fortran to GPU-accelerated C++), examples and explicit conversion rules improved results [11]. The webinar's takeaways are instructive for any simulation project: AI can reduce coding time, but human review is essential [3].
Tools such as Gemini can be prompted to "write a Python function that calculates the current-voltage curve of a silicon solar cell under AM1.5 illumination" or "translate this MATLAB solar-cell script into Python and optimise it for performance." A scientist might iteratively refine the prompt by specifying the band-gap energy, the assumed quantum efficiency, and the equations to use. The AI's output should always be tested for physical validity and numerical correctness. In the example below, we assume that a generative model produced the Python code based on a carefully crafted prompt.
Python Simulation of a Simple Silicon Solar Cell
The following script models a planar silicon solar cell under AM1.5 illumination. It demonstrates how AI-generated code might implement a simplified Shockley-Queisser type calculation:
- Define the AM1.5 spectral irradiance. We approximate the solar spectrum by a 5800 K blackbody scaled so that the total irradiance from 280 nm to 4000 nm equals 1000 W/m², the STC value [7].
- Convert spectral irradiance to photon flux. For each wavelength, the energy per photon is . Photon flux is , where is the irradiance in W·m·nm.
- Compute the short-circuit current . For wavelengths shorter than the band-gap cutoff , the current contribution is , where is the elementary charge and is the external quantum efficiency (assumed to be ).
- Estimate the open-circuit voltage . A crude approximation is , where accounts for recombination losses.
- Compute the fill factor and efficiency. We use a typical fill factor of 0.83. The efficiency is .
import numpy as np import matplotlib.pyplot as plt # Physical constants h = 6.62607015e-34 # Planck constant (J·s) c = 2.99792458e8 # Speed of light (m/s) q = 1.60217663e-19 # Elementary charge (C) k_B = 1.380649e-23 # Boltzmann constant (J/K) # Simulation parameters E_g = 1.12 # Silicon band-gap energy in eV lambda_g = 1240.0 / E_g # Band-gap wavelength (nm) eta_ext = 0.9 # External quantum efficiency (assumed constant) T_sun = 5800 # Approximate temperature of the sun (K) # Wavelength grid (nm) lambda_nm = np.linspace(280, 4000, 4000) # 1 nm resolution lambda_m = lambda_nm * 1e-9 # Blackbody spectral radiance (Planck's law per unit wavelength) def planck_lambda(lambda, T): # Returns spectral radiance in W/m^2/nm at the top of atmosphere # Convert to per metre then to per nanometre exponent = (h * c) / (lambda * k_B * T) intensity_per_m = (2 * h * c**2) / (lambda**5 * (np.exp(exponent) - 1)) return intensity_per_m * 1e-9 # convert W/m^2/m to W/m^2/nm # Raw blackbody spectrum I_bb = planck_lambda(lambda_m, T_sun) # Scale so that total irradiance equals 1000 W/m^2 over 280-4000 nm power_total = np.trapz(I_bb, lambda_nm) scaling_factor = 1000.0 / power_total I_spectrum = I_bb * scaling_factor
Plot the approximated AM1.5 spectrum (optional)
plt.figure(figsize=(6, 3)) plt.plot(lambda_nm, I_spectrum) plt.xlabel('Wavelength (nm)') plt.ylabel('Irradiance (W/m^2/nm)') plt.title('Approximate AM1.5 Spectrum (Scaled Blackbody)') plt.xlim(280, 2500) plt.show()
Photon energy at each wavelength
E_photon = (h * c) / lambda_m # J
Photon flux (photons/m^2/s/nm)
phi = I_spectrum / E_photon
Only consider wavelengths that generate electron-hole pairs (λ ≤ λ_g)
mask = lambda_nm <= lambda_g
Short-circuit current density (A/m^2)
J_sc = np.trapz(q * phi[mask] * eta_ext, lambda_nm[mask]) # integrate over wavelength
Convert to mA/cm^2 for convenience
J_sc_mA_cm2 = J_sc * 1e3 / 1e4
Open-circuit voltage (V)
V_oc = (E_g - 0.3) # in eV V_oc *= q # convert eV to joules-per-electron then to volts (1 eV = q J) V_oc = V_oc / q # convert back to volts (E_g in eV)
Fill factor (dimensionless)
fill_factor = 0.83
Efficiency (fraction)
efficiency = (J_sc * V_oc * fill_factor) / 1000.0
print(f"Short-circuit current density J_sc = {J_sc_mA_cm2:.2f} mA/cm^2") print(f"Open-circuit voltage V_oc = {V_oc:.2f} V") print(f"Approximate efficiency η = {efficiency*100:.1f}%")
## What the Code Does
- **Spectrum generation**: The script uses Planck's law to approximate the sun as a 5800 K blackbody. It scales the resulting spectrum so that the total power integrated from 280 nm to 4000 nm equals the 1000 W/m² specified by STC [7]. In practice, one would use the ASTM G-173 AM1.5 spectrum (available from NREL) or call `pvlib.spectrum.get_reference_spectra`, but this simplified model suffices for demonstration.
- **Photon-flux integration**: For wavelengths shorter than the silicon band-gap threshold (~1107 nm), the code calculates the photon flux and integrates it to obtain the short-circuit current density. The result (~35–40 mA/cm²) is comparable to typical silicon solar cells.
- **Voltage and efficiency**: The open-circuit voltage is estimated by subtracting 0.3 V (to account for recombination) from the band-gap energy and multiplying by the elementary charge. The fill factor is assumed to be 0.83. Multiplying these values and dividing by the input power yields an efficiency of roughly 20–25%, consistent with commercial crystalline-silicon cells.
While an AI model can produce this code, the human expert decides the modelling assumptions (e.g., blackbody approximation, quantum efficiency) and checks that the numerical results are physically reasonable. For more accurate simulations, one should use measured AM1.5 spectra, incorporate recombination losses via the Shockley diode equation, and model the device structure (doping profiles, surface recombination) using finite-element tools.
## Discussion: Opportunities and Caution
Generative AI accelerates simulation development by producing boilerplate code, translating between languages, and suggesting algorithms. However, the Argonne analysis emphasizes that prompts must be precise and that LLMs are not yet reliable enough to work unaided [3]. Users should:
- **Define the physical model clearly.** Tell the AI about governing equations, material properties, and boundary conditions.
- **Iterate and test.** Use small examples to verify that the AI's code behaves as expected, then refine the prompt or edit the code manually.
- **Validate results.** Compare output with analytical solutions or experimental data. For example, verify that the simulated short-circuit current and efficiency match known values for silicon cells under AM1.5 illumination.
By combining AI-generated code with scientific insight, researchers can build robust simulations faster. As generative models improve and incorporate physics-based constraints, they may become indispensable tools for renewable-energy research.
## Conclusion
Physics simulations often require substantial coding effort. Generative AI tools like Gemini can reduce this burden by drafting code snippets for complex tasks, such as calculating the efficiency of a silicon solar cell under AM1.5 conditions. Standard test conditions specify a 1000 W/m² irradiance, AM1.5 spectrum, and 25 °C cell temperature [4], ensuring that simulations and experiments are comparable. When properly prompted and supervised, AI can generate useful Python code that integrates the AM1.5 spectrum, computes the short-circuit current, and estimates the efficiency of a solar cell. Human oversight remains essential to define the physics, refine the prompts, and interpret the results, but the synergy between AI and domain expertise promises to accelerate the design and optimization of solar-cell technologies.
## References
1. Using generative AI for scientific coding | Argonne National Laboratory - https://www.anl.gov/mcs/article/using-generative-ai-for-scientific-coding
2. Argonne National Laboratory webinar on AI-assisted scientific computing
3. Argonne National Laboratory analysis on LLM reliability in scientific contexts
4. Understanding PV System Standards, Ratings, and Test Conditions - Technical Articles - https://eepower.com/technical-articles/understanding-pv-system-standards-ratings-and-test-conditions/
5. AM1.5 Spectrum | The Standard Solar Spectrum | Ossila - https://www.ossila.com/pages/standard-solar-spectrum
6. Solar Spectra | Grid Modernization | NLR - https://www.nlr.gov/grid/solar-resource/spectra
7. International Commission on Illumination reference spectrum standards
8. ASTM G-173 AM1.5 spectra for terrestrial solar cell testing
9. Photovoltaic industry and national laboratory spectrum development
10. Iterative prompt refinement techniques for scientific code generation
11. Code translation best practices for scientific computing