We have developed an algorithm for the numerical simulation of the electrical and optical properties of a thin-film silicon solar cell. The intrinsic layer in the p-i-n solar cell is nonhomogeneous in the thickness direction. This nonhomogeneity is to be engineered via variations in the composition of the amorphous silicon. A layer of a transparent conducting oxide is welded to the p layer and the n layer is backed by a periodically corrugated metallic back reflector. The nonhomogeneous intrinsic layer may trap the incident light better than a homogeneous layer and increase the generation rate of electron-hole pairs. The periodically corrugated metallic back reflector can excite surface plasmon-polariton waves as well as waveguide modes. The generation rate of electron-hole pairs is computed using the rigorous coupledwave approach and the drift-diffusion model is used for the computation of the current density-voltage characteristics of the solar cell.