Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions docs/Installation/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ Downloading and installing S4 (start from the directory in which you want to dow
Here we download my fork of S4 (modified to be compatible with Python3), move to the downloaded directory, and then we make the Python extension.
If you activated the virtual environment before running this, S4 should automatically install into that virtual environment.

**Note for users of new Mac devices with Apple M1/ARM chips:** You can install packages using Homebrew as described above,
but instead of :literal:`make S4_pyext`, you should run :literal:`make S4_pyext --file="Makefile.m1"`.

.. _install:

Installing RayFlare
Expand Down Expand Up @@ -128,8 +131,8 @@ things like 'pip install' will point to the right place.

As an alternative to the venv method above, PyCharm also has built-in support for making a new virtualenv environment
based on one of your 'system interpreters' (these are the versions of Python installed -- if you followed the
instructions above and are on Ubuntu 18, these are probably Python2.7, Python3.6 and the newly-installed
Python3.8). You can create one of those environments by going to Project Interpreter in the same way, adding a new
instructions above and are on Ubuntu 20, these are probably Python2.7, Python3.8 and possibly the newly-installed
Python3.10). You can create one of those environments by going to Project Interpreter in the same way, adding a new
environment and selecting 'Virtualenv environment' with the relevant base interpreter.

Installing S4 on Windows
Expand Down Expand Up @@ -166,4 +169,4 @@ Troubleshooting
.. _official website: https://releases.ubuntu.com/18.04/
.. _here: https://itsfoss.com/install-linux-in-virtualbox/
.. _dual boot: https://linuxconfig.org/how-to-install-ubuntu-20-04-alongside-windows-10-dual-boot
.. _homebrew: https://brew.sh/
.. _homebrew: https://brew.sh/
54 changes: 34 additions & 20 deletions docs/Installation/python_install.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
========================================
Python versions and installing Python3.8
========================================
==========================================
Python versions and installing Python3.10
==========================================

Ubuntu
-------

On Ubuntu, Python is an integral part of the operating system, so there will already be a version
(likely more than one version, usually a version of Python2 and a version of Python3) installed
Expand All @@ -10,39 +13,50 @@ working in a virtual environment. This also avoids having to use 'sudo' to insta
There are various packages for creating virtual environments, all with confusingly similar names -- I use
venv (not to be confused with virtualenv or pipenv...).

Currently, Ubuntu18 does not come with Python3.8 (the latest stable Python version), by default, but you can
install it pretty easily. From a terminal window (command line):
On Ubuntu20, Python3.8 is the default Python3. You can install the ability to make venvs with:

.. code-block:: console

sudo apt install software-properties-common
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt install python3.8 python3.8-dev python3.8-venv

This installs Python3.8, and also the ability to make virtual environments with python3.8-venv.
You can now use your new version of Python3.8 by just typing 'python3.8' on the command line.
sudo apt install python3-dev python3-venv

Now make the venv:
And make and activate the venv:

.. code-block:: console

python3.8 -m venv mainenv
python3 -m venv mainenv
source mainenv/bin/activate

This makes a virtual environment called 'mainenv' (first line) and then activates it (second line). If you close the terminal and open it again you would have to reactivate the virtual environment to make
sure you are using the virtual environment version of Python3.8.
This makes a virtual environment called 'mainenv' (first line) and then activates it (second line). If you close the
terminal and open it again you would have to reactivate the virtual environment to make
sure you are using the virtual environment version of Python3.10.

On Ubuntu20, Python3.8 is the default Python3. You can install the ability to make venvs with:
Ubuntu20 comes with Python 3.8 by default. Python 3.8 is sufficient for running RayFlare and necessary supporting packages,
but if you want to update to a more recent Python version (3.10), this is easy:

.. code-block:: console

sudo apt install python3-dev python3-venv
sudo apt install software-properties-common
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt install python3.10 python3.10-dev python3.10-venv

And make and activate the venv:
This installs Python3.10, and also the ability to make virtual environments with python3.10-venv.
You can now use your new version of Python3.10 by just typing 'python3.10' on the command line.

Now make the venv:

.. code-block:: console

python3 -m venv mainenv
python3.10 -m venv mainenv
source mainenv/bin/activate

On MacOS, Homebrew Python (default version Python3.8) also comes with the venv ability.

MacOS
-------


On MacOS, Homebrew Python (current default version Python3.10) also comes with the venv ability. This can be installed
with:

.. code-block:: console

brew install python
84 changes: 84 additions & 0 deletions examples/anisotropic_material.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import numpy as np
from solcore import material
from solcore.structure import Layer

from rayflare.rigorous_coupled_wave_analysis import rcwa_structure
from rayflare.options import default_options

import matplotlib.pyplot as plt

wavelengths = np.linspace(400, 800, 20)*1e-9

options = default_options()

options.wavelengths = wavelengths
options.orders = 1
options.parallel = False
options.A_per_order = True
options.pol = "p"
options.theta_in = 0
options.phi_in = 0

# [width of the layer in nm, wavelengths, n at these wavelengths, k at these wavelengths, geometry]

Air = material('Air')()
GaAs = material("GaAs")()
Si = material("Si")()
Ag = material("Ag")()

GaAs_n = GaAs.n(wavelengths)
GaAs_k = GaAs.k(wavelengths)

Si_n = Si.n(wavelengths)
Si_k = Si.k(wavelengths)
#
# n_tensor = np.array([[[2, 0, 0], [0, 3, 0], [0, 0, 1]], [[1, 0, 0], [0, 2, 0], [0, 0, 2]]])
# k_tensor = np.array([[[0.1, 0, 0], [0, 0.1, 0], [0, 0, 0.1]], [[0.2, 0, 0], [0, 0.2, 0], [0, 0, 0.2]]])

GaAs_n_tensor = np.array([np.diag([x,x,x]) for x in GaAs_n])
GaAs_k_tensor = np.array([np.diag([x,x,x]) for x in GaAs_k])

Si_n_tensor = np.array([np.diag([x,x,x]) for x in Si_n])
Si_k_tensor = np.array([np.diag([x,x,x]) for x in Si_k])

test_mat = [100, wavelengths*1e9, GaAs_n_tensor, GaAs_k_tensor, [{'type': 'rectangle', 'mat': Air,
'center': (0, 0), 'angle': 0, 'halfwidths': (150, 150)}]]
test_mat2 = [1000, wavelengths*1e9, Si_n_tensor, Si_k_tensor, []]

rcwa_setup = rcwa_structure([Layer(100e-9, GaAs, geometry=[{'type': 'rectangle', 'mat': Air,
'center': (0, 0), 'angle': 0, 'halfwidths': (150, 150)}]),
Layer(1e-6, Si)], size=((400, 0), (0, 400)), options=options, incidence=Air, transmission=Ag)

rcwa_setup_AS = rcwa_structure([test_mat, test_mat2], size=((400, 0), (0, 400)), options=options, incidence=Air, transmission=Ag)

options.pol = "s"
RAT_s_AS = rcwa_setup_AS.calculate(options)
RAT_s = rcwa_setup.calculate(options)

options.pol = "p"
RAT_p_AS = rcwa_setup_AS.calculate(options)
RAT_p = rcwa_setup.calculate(options)

plt.figure()
plt.plot(wavelengths*1e9, RAT_s_AS["A_per_layer"], '--')
plt.plot(wavelengths*1e9, RAT_s_AS["R"] + RAT_s_AS["T"] + np.sum(RAT_s_AS["A_per_layer"], 1))

plt.plot(wavelengths*1e9, RAT_p_AS["A_per_layer"])
plt.plot(wavelengths*1e9, RAT_p_AS["R"] + RAT_p_AS["T"] + np.sum(RAT_p_AS["A_per_layer"], 1))
plt.show()

plt.figure()
plt.plot(wavelengths*1e9, RAT_s["A_per_layer"])
plt.plot(wavelengths*1e9, RAT_s["R"] + RAT_s["T"] + np.sum(RAT_s["A_per_layer"], 1))

plt.plot(wavelengths*1e9, RAT_p["A_per_layer"])
plt.plot(wavelengths*1e9, RAT_p["R"] + RAT_p["T"] + np.sum(RAT_p["A_per_layer"], 1))
plt.show()

prof = rcwa_setup.calculate_profile(options)
prof_AS = rcwa_setup_AS.calculate_profile(options)

plt.figure()
plt.plot(prof['profile'][[0,20,50,100,249],:].T)
plt.plot(prof_AS['profile'][[0,5, 10],:].T, '--')
plt.show()
6 changes: 4 additions & 2 deletions examples/full_RT_Sipyramids.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from solcore import material
from solcore import si
from solcore.absorption_calculator.nk_db import search_db

# imports for plotting
import matplotlib.pyplot as plt
Expand All @@ -17,7 +18,8 @@

# setting up Solcore materials
Air = material('Air')()
Si = material('566', nk_db=True)()
pageid = search_db("Si/Green-1995")[0][0]
Si = material(str(pageid), nk_db=True)()

# number of x and y points to scan across
nxy = 25
Expand All @@ -31,7 +33,7 @@
options.ny = nxy
options.n_rays = 2 * nxy ** 2
options.depth_spacing = si('1um')
options.parallel = True
options.parallel = False

PVlighthouse = np.loadtxt('data/RAT_data_300um_2um_55.csv', delimiter=',', skiprows=1)

Expand Down
10 changes: 7 additions & 3 deletions examples/profile_pass_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
from rayflare.angles import make_angle_vector
from rayflare.utilities import make_absorption_function


from solcore import material, si
from solcore.solar_cell import SolarCell, Layer, Junction
from solcore.solar_cell_solver import solar_cell_solver
from solcore.light_source import LightSource
from solcore.constants import q
from solcore.absorption_calculator import search_db

# imports for plotting
import matplotlib.pyplot as plt
Expand Down Expand Up @@ -62,8 +62,12 @@
InAlP = material("AlInP")(Al=0.5)
GaInP = material("GaInP")(In=0.5)
Si = material("Si")()
MgF2 = material("203", nk_db=True)()
Ta2O5 = material("410", nk_db=True)()

Ta2O5_pageid = str(search_db("Ta2O5/Rodriguez-de Marcos")[0][0])
MgF2_pageid = str(search_db("MgF2/Rodriguez-de Marcos")[0][0])

Ta2O5 = material(Ta2O5_pageid, nk_db=True)()
MgF2 = material(MgF2_pageid, nk_db=True)()

GaAs_1_th = 120e-9
GaAs_2_th = 1200e-9
Expand Down
2 changes: 1 addition & 1 deletion examples/rcwa_examples.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
"metadata": {},
"outputs": [],
"source": [
"grating_circles = geometry=[{'type': 'circle', 'mat': Ag, 'center': (0, 0), 'radius': 115}]\n",
"grating_circles = [{'type': 'circle', 'mat': Ag, 'center': (0, 0), 'radius': 115}]\n",
"\n",
"grating_squares = [{'type': 'rectangle', 'mat': Ag, 'center': (0, 0),\n",
" 'halfwidths': [115, 115], 'angle': 20}]\n",
Expand Down
2 changes: 1 addition & 1 deletion examples/tmm_rcwa_structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
options = default_options()

options.wavelengths = wavelengths
options.orders = 2
options.orders = 1

size = ((100, 0), (0, 100))

Expand Down
3 changes: 2 additions & 1 deletion rayflare/matrix_formalism/multiply_matrices.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,6 @@ def matrix_multiplication(bulk_mats, bulk_thick, options, layer_names, calc_prof

len_calcs = np.array([len(x) if x is not None else 0 for x in calc_prof_list])


if np.any(len_calcs > 0) or options.bulk_profile:

a = [[] for _ in range(n_interfaces)]
Expand Down Expand Up @@ -420,6 +419,8 @@ def matrix_multiplication(bulk_mats, bulk_thick, options, layer_names, calc_prof

else:

print("b")

a = [[] for _ in range(n_interfaces)]
vr = [[] for _ in range(n_bulks)]
vt = [[] for _ in range(n_bulks)]
Expand Down
Loading