Hi. Thanks for sharing the files. The FDTD setup looked fine to me. You may want to use symmetric/anti-symmetric boundary conditions to make the simulation even faster. However this is optional since the simulation is already fast enough.
In the DEVICE file, I noticed a problem with the doping which was responsible for the wrong I-V. In your original setup, the n+ and p+ doping objects were being introduced from the side. Since you are using diffusion doping objects and the doping exponentially falls at a smaller value at the surface of these objects, the doping at the metal-semiconductor interface was very small (see screenshot below).
I have modified the doping objects as shown below to make the doping large at the top surface instead. If you run the simulation now (with and without the optical generation), you will see that the I-V looks like a proper diode I-V. Here is the modified file: lateral_pindiode_MOD.ldev (1.8 MB). Please note that I have modified the bias range as well.
Next I looked at the script file. While calculating the surface area, the length in z direction should come from the “norm length” property of the simulation region given that you are doing a 2D simulation. If you were doing a 3D simulation then Lz would come from the z span. I have corrected this at line 13. Also, on line 14 where current density is calculated, the multiplication factor was wrong. I have corrected this and have included the units of the different variables on the different script lines (4,12,13,14) to make this easily understandable. The script now works fine as well (see plots below). Here is the modified script file: lateral_pindiode_MOD.lsf (1.2 KB).