Skip to content

Commit

Permalink
fix failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
phoebe-p committed Nov 10, 2023
1 parent a7fdc05 commit 2900bce
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 32 deletions.
40 changes: 16 additions & 24 deletions examples/Si_cell.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
from solcore.solar_cell import SolarCell, Junction, Layer
from solcore.state import State
from solcore.solar_cell_solver import solar_cell_solver
from solcore.sesame_drift_diffusion.solve_pdd import process_structure
import numpy as np
import os
from solcore.light_source import LightSource
from solcore.absorption_calculator import search_db
from scipy.special import erfc
import matplotlib.pyplot as plt
from matplotlib.patches import Rectangle
from cycler import cycler
from solcore.constants import q
from scipy.interpolate import interp1d, RectBivariateSpline

from solcore import material, si

Expand All @@ -29,7 +24,6 @@

TCO = material('ITO2')()


front_materials = [Layer(80e-9, MgF2), Layer(55e-9, TCO)]

back_materials = [Layer(55e-9, TCO),
Expand All @@ -44,11 +38,11 @@
options.light_source = LightSource(source_type="standard",
version="AM1.5g", x=options.wavelength, output_units="photon_flux_per_m")


options.voltages = np.linspace(0, 0.8, 30)
options.internal_voltages = options.voltages
options.mpp = True
options.recalculate_absorption = True
options.no_back_reflection = False

nD = si("1e20cm-3")
nA = si("1e19cm-3")
Expand Down Expand Up @@ -83,36 +77,34 @@ def doping_profile_func(x):
Si_junction +
back_materials,
shading=0.02,
substrate=Air,
substrate=Ag,
)


solar_cell_solver(Si_cell, 'iv', options)

solar_cell_solver(Si_cell, 'qe', options)

shading = 0.02
result_stack = np.vstack([Si_cell.reflected, [layer.layer_absorption for layer in Si_cell]])

fig, (ax, ax2) = plt.subplots(1, 2, figsize=(10, 3.5))
# ax.stackplot(wavelengths * 1e9, 100 * (1 - shading) * np.array(result_stack), linewidth=0.5)
# ax.fill_between(wavelengths * 1e9, 100 * (1 - shading), 100, color='white')
ax.plot(wavelengths * 1e9, 100 * Si_cell(0).eqe(wavelengths), '-r', linewidth=2)
ax.legend(['Si absorption', 'Front stack absorption', 'Rear stack aborption',
'Front reflection', 'Front escape', 'Electrode shading', 'Simulated EQE'],
loc='lower center')
ax.stackplot(wavelengths * 1e9, 100 * result_stack[::-1], linewidth=0.5, alpha=0.5,
labels=['MgF2 (rear)', 'TCO (rear)', 'Si bulk', 'TCO (front)', 'MgF2 (front)',
'Reflection'])
ax.plot(wavelengths * 1e9, 100 * Si_cell(0).eqe(wavelengths), '-r', linewidth=2,
label='EQE')

ax.set_xlim(280, 1200)
ax.set_ylim(0, 100)
ax.set_xlabel("Wavelength (nm)")
ax.set_ylabel("R / A / EQE (%)")
ax.set_title('a) EQE and cell optics', loc='left')
ax.legend()
# plt.show()

jsc = Si_cell.iv.Isc / 10

ax2.plot(options.voltages, -(1 - shading) * Si_cell(0).iv(options.voltages) / 10, '-', label='IV',
ax2.plot(Si_cell.iv['IV'][0], Si_cell.iv['IV'][1] / 10, '-', label='IV',
linewidth=2, color='k')
# plt.plot(options.voltages, solar_cell_old[1].iv(options.voltages), 'o-', label='IV')
# plt.xlim(-2, 1.8)

ax2.set_ylim(0, 1.03 * jsc)
ax2.set_xlim(np.min(options.voltages), np.max(options.voltages))
Expand All @@ -126,9 +118,9 @@ def doping_profile_func(x):
ax3.set_ylabel('Power density (W m$^{-2}$)')
ax3.set_ylim(0, 1.03 * jsc * 10)

# ax3.spines['right'].set_color(pal[2])
# ax3.yaxis.label.set_color(pal[2])
# ax3.tick_params(axis='y', colors=pal[2])
ax3.spines['right'].set_color('r')
ax3.yaxis.label.set_color('r')
ax3.tick_params(axis='y', colors='r')

ax2.set_axisbelow(True)
ax3.set_axisbelow(True)
Expand All @@ -143,8 +135,8 @@ def doping_profile_func(x):
ax2.text(0.1, 0.9 * jsc, r'= {:.2f} mA/cm$^2$'.format(jsc))
ax2.text(0.1, 0.8 * jsc, r'= {:.3f} V'.format(Si_cell.iv.Voc))
ax2.text(0.1, 0.7 * jsc, '= {:.2f} %'.format(Si_cell.iv.FF * 100))
ax2.text(0.1, 0.6 * jsc, r'= {:.2f} %'.format((1 - shading) * Si_cell.iv.Pmpp / 10))
ax2.text(0.1, 0.5 * jsc, r'= {:.2f} mA/cm$^2$'.format((1 - shading) * Si_cell.iv.Impp / 10))
ax2.text(0.1, 0.6 * jsc, r'= {:.2f} %'.format(Si_cell.iv.Pmpp / 10))
ax2.text(0.1, 0.5 * jsc, r'= {:.2f} mA/cm$^2$'.format( Si_cell.iv.Impp / 10))
ax2.text(0.1, 0.4 * jsc, r'= {:.3f} V'.format(Si_cell.iv.Vmpp))
ax2.grid(which='major', alpha=0.35)

Expand Down
17 changes: 9 additions & 8 deletions solcore/solar_cell_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,16 +351,17 @@ def prepare_solar_cell(solar_cell, options):
process_position(solar_cell, options, layer_widths)

# check that the voltages are in the expected format (monotonically increasing):
if hasattr(options, "voltages"):

if np.any(np.diff(options.voltages) < 0):
raise ValueError(
"ERROR in 'solar_cell_solver' - The voltages must be monotonically increasing."
)
if np.any(np.diff(options.voltages) < 0):
raise ValueError(
"ERROR in 'solar_cell_solver' - The voltages must be monotonically increasing."
)

if np.any(np.diff(options.internal_voltages) < 0):
raise ValueError(
"ERROR in 'solar_cell_solver' - The internal_voltages must be monotonically increasing."
)
if np.any(np.diff(options.internal_voltages) < 0):
raise ValueError(
"ERROR in 'solar_cell_solver' - The internal_voltages must be monotonically increasing."
)


def process_position(solar_cell, options, layer_widths):
Expand Down

0 comments on commit 2900bce

Please sign in to comment.