Fitting experimental data

Related YouTube videos:

c l

image

& Advanced topics in fitting of JV curves to experimental data using OghmaNano. 
image

& Fitting transient photocurrent (TPC) and light JV curves using OghmaNano
image

& Fitting the light JV curve of an ultra large area (2.5meter x 1cm) OPV device using OghmaNano

[sec:fitting] In the same way you can fit the diode equation to a dark curve of a solar cell to extract the ideality factor, OghmaNano can be fit to experimental data using the fitting function. Fitting is a good way to extract physical parameters from a device such as mobility, destiny of trap states etc. The advantage of fitting a complex model such as OghmaNano to data rather than simplistic analytical equations is that far more detailed information can be extracted and a better physical picture of the underlying physics obtained. This section gives an overview of the fitting tools in OghamNano.

Key tips and tricks

The main fitting window

An example of how to fit the model to experimental data is included in the demo simulations provided with OghmaNano. In this example a simple drift diffusion model is fit to some experimental data. If you click on the New simulation icon in the File ribbon, this will bring the new simulation window as seen in Figure 16.2a. Double click on the Scripting and fitting icon, this will display the menu that can be seen in Figure 16.2b. From this menu double click on the Fitting and parameter extraction example.(see 16.2a). If you open this simulation you will be presented with the window shown in Figure (see 16.3), this is a simple solar cell simulation. It should be noted that the fitting engine can be used to fit any simulation to any data set.

a) The example fitting simulation can be found in the Scripting and fitting folder b) The fitting example is called Fitting and parameter extraction example. a) The example fitting simulation can be found in the Scripting and fitting folder b) The fitting example is called Fitting and parameter extraction example.
The main fitting window.
The fitting window can be accessed through the Automation ribbon, using the Fit to experiment icon.

From the Automation ribbon in the simulation (Figure 16.4), click on the Fit to experiment icon. This will bring up the fitting window (see figure 16.5). The icons in the ribbon of the fitting window perform the following tasks:

The main fitting window.

If you click the one fit button, the fit window will update and will look like 16.7a. You can now see the difference between the experimental and simulated curves. The green line represents the difference between the two curves, it is called the error function. It represents the mathematical difference between the simulated and experimental data. If you now click Run fit to start the fitting process, you should see the curves gradually start to get closer and the error function decrease in value. Now click on the Fit progress tab, this plots the error function as a function of fit iterations. Watch as the error drops off. It should start looking like figure 16.7b. This process should take about 30 seconds, if it takes longer read section 16.1 above.

a) The result of clicking the one fit button. b) The error function dropping during a simulation. a) The result of clicking the one fit button. b) The error function dropping during a simulation.

Setting the variables to fit

In figure 16.5, there is a Configure icon. If you click on this it will open the Fit variable window. This window is used to configure the fitting variables. The tab entitled Fit variables defines the variables we will fit. The more variables you fit at the same time the longer the fit will take. Try to minimize the number of variables you are fitting. A good tip is to start of fitting with symmetric parameters then only move to asymmetric parameters, once the fit becomes good. (see figure 16.8). You can see from Figure 16.8, that there are 7 columns to the fit window, they have the following functions:

Defining the variables to fit and their ranges.

Duplicating variables

The Fit Variable Window includes a tab called Duplicate Variables, which allows one parameter to be copied onto another. In this example, we assume the device is symmetric, meaning we only fit the electron parameter as a variable. However, we use the Duplicate Variables tool to copy the newly fitted electron parameters onto the hole parameters. This approach enables us to vary electron mobility during the fitting process while ensuring that hole mobility maintains the same value at each step. (See Figure 16.9.)

If you examine the window closely, you will notice a column labeled "Function y=f(x)", where the default value is set to "x". This function defines how the source variable is transformed into the destination variable yy. For example, setting it to "2*x" would double the source variable each time it is copied. The available mathematical operations are detailed in Table [sec:calculator].

Defining which variables are duplicated to other variables.

Fit rules

Also in the Fit variable window is a tab called Fit rules. This is used to enforce rules onto the fit, using mathematical expressions. For example one can force one parameter to always be bigger than another.

Minimizer configuration

Also in the Fit configure window is a tab called Configure minimizer. This configures the fitting algorithm that is used for the fit. Fitting algorithms are an entire research field in themselves. OghmaNano implements a few key algorithms to do the fitting. These are listed below. The algorithm used can be selected from the Fitting method drop down box.

a) Configuring the simplex downhill minimizer b) Configuring the thermal annealing minimizer. a) Configuring the simplex downhill minimizer b) Configuring the thermal annealing minimizer.

There are in general two types of fitting algorithms. The first class of algorithms are gradient decent type, these attempt to effectively roll a ball down a hill to find the best fit. This class of algorithm can be divided into two sub types, ones which require the gradient to be calculated and those that do not. Calculating the gradient is computationally expensive and prone to errors with complex models. Therefore, generally more reliable fitting with methods that do not require the gradient to be explicitly calculate is usually more robust (in my exprience). The second class of algorithm are statistical methods, these methods have the advantage that the user does not only get a fit of the model to the data but a statistical distribution telling him/her how probable (and unique) the fit is. These methods therefore often require longer run times than down hill methods.

Method Downhill Gradient Statistical Comment
Nelder-Mead x Robust, slow, reliable
Newton x x Fragile, sometimes fast
Thermal Annealing x Surprisingly good
MCMC x ?
HMC x ?

Nelder-Mead (Simplex Downhill)

The simplex downhill algorithm is the most often used fitting method in OghmaNano, all papers published until 2024 used this method. More can be read about how the algroytham works here: https://en.wikipedia.org/wiki/Nelder%E2%80%93Mead_method. This minimizer has the following options:

The advantage of this method is that it effectively looks for an answer by rolling a ball down hill. It also does not need to take gradients of the problem, which can be beneficial in complex problem spaces.

Newton

Newton’s method is included for completeness. In my experience it is quite unstable when used with fitting. This is a gradient method, thus requires derivatives to be calculated. This can make the fitting process unstable, but the advantage is that it can be faster than Nelder-Mead in some circumstances for some classes of problem.

Thermal Annealing

This is a classical thermal annealing algorithm. The algorithm will only explore the parameter space defined by the allowed limits of the fit variables, thus to use this efficiently it is key to set these limits correctly. I have found this method to be surprisingly good and often faster than Nelder-Mead, however the final results are often not as polished as those for Nelder-Mead.

Markov chain Monte Carlo (MCMC)

This method is under development.

Hamiltonian Monte Carlo (HMC)

This method is under development.

No-U-Turn Sampler (NUTS)

This method is under development.

How the fitting process works

When you click the "Run fit" button, OghmaNano makes a new directory inside the simulation directory called "sim" this is the directory in which the fitting process takes place. Inside this directory OghmaNano will make one new directory for each data set you are trying to fit, it will populate each directory with the sim.json (and sim.oghma) files from your main simulation directory. At this point the sim.json files in all the directories are identical. Then using the contents of the fit "fit patch" (see figure 16.12) the content of each sim.json file will be updated, this process is called patching the simulation files. This process enables you to adjust parameters in each simulation directory to match the data set you are trying to fit. For example you might want one data set to have optical/light/Psun set 1.0 and another to be set to 0.0 to enable fitting of a 1 sun JV curve and a dark JV curve. After patching each directory, the fitting process then commences. During this process fitting variables in the sim.json files in the "sim" directory are updated. During the fit the algorithm will often produce fits which are worse than the current best effort, and only sometimes produce fits which are better than the current best effort. Only when a better fit is obtained will the sim.json file be updated in the main simulation directory and the curves in the GUI also updated.

The fit patch applied to each data set.

Fitting without the GUI

The GUI is a very easy and efficient way to setup a fit. However, it takes considerable CPU time to update the user interface as the fit runs and this therefore slows the fitting process. Therefore if you are doing lots of fitting or fitting difficult problems, fitting without the GUI can be faster. This section covers how to fit from the Windows command line:

  1. First set up your simulation you want to fit in the usual way using the GUI. Run a single iteration of the fit to make sure it looks right. Then close the GUI.

  2. Next we need to tell Windows where it can find OghmaNano, usually it has been installed in C:\Program files x86 \OghmaNano . If you open this directory you will see lots of files. But the two key ones are oghma.exe and oghma_core.exe. The file oghma.exe is the GUI, oghma_core.exe is the core solver, these are completely independent programs. The core solver can be run without the GUI. To tell windows where these files are we need to add C:\Program files x86 \OghmaNano to the windows path. This can be done by following these https://docs.microsoft.com/en-us/previous-versions/office/developer/sharepoint-2010/ee537574(v=office.14) instructions. These instructions are for a modern version of Windows, but on your system things may be in slightly different places. On most versions of windows the process is more or less the same, if you get stuck google "adding a path to window".

  3. Click on the start menu and type "cmd" and enter to bring up a Windows terminal. Type:

    oghma_core.exe --help

    Note it is a double dash before help not a single dash.

    This should bring up some help for OghmaNano. If it does them we have successfully told windows where oghma_core.exe lives. If you get an error, try step 2 again (and/or restart your computer).

  4. Now that windows knows where oghma_core.exe lives, we can navigate to our simulation directory. Use cd to navigate to the directory where your simulation you want to fit is saved.

  5. First run the command oghma_core.exe to see if your simulation runs OK. If it does not then recheck your simulation file.

  6. Now run a single fit by typing:

    oghma_core.exe --1fit

    Inspect the results in the "sim" directory, use your favourite plotting program to compare the results to the experimental data. Note the experimental data is stored in fit_data(0-1).inp.

  7. If everything went well with the above step, you can run a real fit by typing:

    oghma_core.exe --fit

    Again those are double dashes before the fit command. Ctrl+C will terminate the fit. You can check the progress of convergence by plotting fitlog.csv.