A one-file starter: a solar cell's I–V curve
A silicon n⁺p cell under light, its I–V curve recomputed as you move the slider. Every point is a full
self-consistent drift–diffusion solve, with electrons and holes recombining (a 0.6 µs lifetime in the
base, a 48 µm diffusion length) and an ohmic back contact that takes the carriers that reach it, in the
browser. So the short-circuit current, the open-circuit voltage and the fill factor come out of the
device, not out of the ideal-diode equation: change the lifetime, the base's thickness or its doping in
one line, or let the light be absorbed with depth (photogeneration()), and they follow.
The dashed curve is the dark curve moved up by Jsc. The page loads driftlet from a pinned CDN
URL, with no install and no build step.
Checks before you build on it
At G = 50 mol/(m³·s) the cell gives Jsc = 18.47 mA/cm² and Voc = 0.5613 V. The
superposition principle, that the lit curve is the dark curve shifted by Jsc, puts
Voc where the dark cell passes Jsc: 0.5617 V, 0.3 mV away (the page drives the dark
cell at that current to find it). It holds this well because the base stays in low injection; the
curves part by a few tenths of a percent near the maximum-power point. Jsc is 38% of the
F·G·(101 µm) the light makes, since the base is twice the diffusion length and its back contact
recombines what reaches it. sol.current is along +x, toward the p side on the right, which is
where the photocurrent flows, so it's the current delivered as it stands. The fill factor is read at the
20 mV sweep points.
The whole page
<!doctype html>
<meta charset="utf-8">
<title>solar cell I–V</title>
<label>light: generation G <input id="G" type="range" min="5" max="100" step="5" value="50"></label>
<span id="Gout"></span>
<div id="readout"></div>
<div id="figure"></div>
<script type="module">
import { Device, units } from 'https://cdn.jsdelivr.net/npm/driftlet@1.23.0/src/index.js';
import { build, layer, ohmic, semiconductor } from 'https://cdn.jsdelivr.net/npm/driftlet@1.23.0/src/kit.js';
// A silicon n⁺p cell, its electrons and holes drifting, diffusing and recombining (τ ≈ 0.6 µs in the
// p base) under light that makes pairs uniformly at G mol/(m³·s). Every point is a self-consistent solve.
const cell = (G) => build({
T: 300,
library: [semiconductor('Si')],
stack: [
ohmic(0),
layer('Si', units.um(1), { name: 'n', donors: units.perCm3(1e18) }),
layer('Si', units.um(100), { name: 'p', acceptors: units.perCm3(1e16) }),
ohmic(0),
],
bulkReactions: [
{ equation: 'e- + h+ = 0', kf: { Si: 1e8 } },
{ equation: 'photon = e- + h+', fixed: { photon: units.eV(3) }, kf: { Si: G } },
],
grid: { hmin: units.nm(1), hmax: units.um(1) },
});
const volts = Array.from({ length: 36 }, (_, k) => k * 0.02);
// The current delivered, in mA/cm²: sol.current is along +x, out at the p side, where the photocurrent goes.
const curve = (G) => {
const d = new Device(cell(G));
return volts.map((V) => (d.set({ contacts: { right: { V } } }), d.solve().current / 10));
};
const openCircuit = (G, I = 0) => {
const d = new Device(cell(G));
d.set({ contacts: { right: { I } } });
return d.solve().terminals.right.V;
};
const dark = curve(0);
// The page: the I–V curve in the light, and the dark curve shifted by the short-circuit current.
function plot(light, Jsc, Voc) {
const W = 640, H = 300, X = (V) => 60 + (V / 0.7) * 560, Y = (J) => 20 + ((25 - J) / 30) * 240;
const line = (J, color, dash = '') => `<polyline fill="none" stroke="${color}" stroke-width="2" stroke-dasharray="${dash}" points="${volts.map((V, k) => [V, J[k]]).filter(([, j]) => j > -5 && j < 25).map(([V, j]) => `${X(V).toFixed(1)},${Y(j).toFixed(1)}`).join(' ')}"/>`;
const grid = [-5, 0, 5, 10, 15, 20, 25].map((j) => `<line x1="60" x2="620" y1="${Y(j)}" y2="${Y(j)}" stroke="${j ? '#ddd' : '#888'}"/><text x="54" y="${Y(j) + 4}" text-anchor="end" font-size="12">${j}</text>`).join('');
const xs = [0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7].map((V) => `<text x="${X(V)}" y="${H - 18}" text-anchor="middle" font-size="12">${V}</text>`).join('');
return `<svg viewBox="0 0 ${W} ${H}" width="${W}" height="${H}" font-family="sans-serif">${grid}${xs}<text x="340" y="${H - 2}" text-anchor="middle" font-size="12">voltage (V)</text><text x="14" y="150" font-size="12" transform="rotate(-90 14 150)" text-anchor="middle">current (mA/cm²)</text>${line(light, '#c0392b')}${line(dark.map((j) => j + Jsc), '#333', '5 4')}<circle cx="${X(Voc)}" cy="${Y(0)}" r="4" fill="#c0392b"/><text x="610" y="40" text-anchor="end" font-size="13" fill="#c0392b">in the light</text><text x="610" y="58" text-anchor="end" font-size="13" fill="#333">dark + J_sc (dashed)</text></svg>`;
}
function update() {
const G = +document.getElementById('G').value;
document.getElementById('Gout').textContent = `${G} mol/(m³·s)`;
const light = curve(G), Jsc = light[0], Voc = openCircuit(G);
const mpp = Math.max(...volts.map((V, k) => V * light[k])); // mW/cm²
const superposed = openCircuit(0, Jsc * 10); // the dark cell, driven at J_sc: where superposition puts V_oc
document.getElementById('readout').textContent =
`J_sc = ${Jsc.toFixed(2)} mA/cm², V_oc = ${Voc.toFixed(4)} V (superposition: ${superposed.toFixed(4)} V), fill factor ${(mpp / (Jsc * Voc)).toFixed(3)}, P_max = ${mpp.toFixed(2)} mW/cm²`;
document.getElementById('figure').innerHTML = plot(light, Jsc, Voc);
}
document.getElementById('G').addEventListener('input', update);
update();
</script>
Next: the solar cell demo has light absorbed with depth, band diagrams and the efficiency's limits; the perovskite demo adds moving ions and their hysteresis; the pn junction starter shows the band diagram itself; and the guide for coding agents has templates for the rest.