Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update documentation #210

Merged
merged 12 commits into from
Mar 23, 2022
Merged
Show file tree
Hide file tree
Changes from 7 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
Binary file removed .DS_Store
Binary file not shown.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,7 @@ dmypy.json
.idea/

# VS Code
.vscode/
.vscode/

# macOS
.DS_Store
23 changes: 8 additions & 15 deletions docs/source/Examples/custom_materials_example.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,10 @@ Setting up the options for and defining custom materials
import numpy as np
import os

# first we need to tell Solcore some things about where to put custom materials. for this,
# we use the add_source function from config_tools, although we could also manually edit
# the solcore configuration file (which should be in your home directory).
# You need to add two things to the config file: where to put the n and k data for new
# materials added to the database, and where to put the other parameters (these can all
# go in the same file).

home_folder = os.path.expanduser('~')
custom_nk_path = os.path.join(home_folder, 'Solcore/custommats')
nk_db_path = os.path.join(home_folder, 'Solcore/NK.db')
param_path = os.path.join(home_folder, 'Solcore/custom_params.txt')

add_source('Others', 'custom_mats', custom_nk_path)
add_source('Others', 'nk', nk_db_path)
add_source('Parameters', 'custom', param_path)
# When adding custom materials - or getting the refractive index database - the
# information will be stored in the Solcore's users folder. These can be setup by setting
# the SOLCORE_USER_DATA environmental variable to your prefered location or, by default,
# it will be in your home directory, in a directory called .solcore.

# EXAMPLE 1

Expand All @@ -43,6 +32,10 @@ Setting up the options for and defining custom materials
# the parameters in SiGeSn_params.txt have been copied directly from Ge.
create_new_material('SiGeSn', 'SiGeSn_n.txt', 'SiGeSn_k.txt', 'SiGeSn_params.txt')

# Note that the final argument, the parameter file, is optional - if you do not
# provide it, a material will be added with optical constants only, so it can be
# used for optical calculations.

# can now create an instance of it like any Solcore material
SiGeSn = material('SiGeSn')()

Expand Down
3 changes: 1 addition & 2 deletions docs/source/Examples/example_3J_with_DA_solver.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ Example of a 3J solar cell calculated with the DA solver

.. code-block:: Python

import os
import numpy as np
import matplotlib.pyplot as plt

Expand All @@ -28,7 +27,7 @@ Example of a 3J solar cell calculated with the DA solver


def this_dir_file(f):
return os.path.join(os.path.split(__file__)[0], f)
return "data/" + f
phoebe-p marked this conversation as resolved.
Show resolved Hide resolved


# We need to build the solar cell layer by layer.
Expand Down
2 changes: 1 addition & 1 deletion docs/source/Examples/example_RAT_of_ARC.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Using the TMM solver to calculate the reflextion of a multilayered ARC
Using the TMM solver to calculate the reflection of a multilayered ARC
======================================================================

.. image:: RAT_of_ARC.png
Expand Down
2 changes: 1 addition & 1 deletion docs/source/Examples/example_optics_comparison.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ due to diffraction effects.
from solcore.solar_cell_solver import solar_cell_solver, default_options
from solcore.light_source import LightSource
from solcore.constants import vacuum_permittivity
from solcore.optics import RCWASolverError
from solcore.absorption_calculator import RCWASolverError

# user options
T = 298
Expand Down
2 changes: 1 addition & 1 deletion docs/source/Examples/example_substrate.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Looking at the effect of substrate and the no_back_reflection option in the TMM

# Thin solar cell, no substrate - will get significant absorption enhancement from reflection at the GaAs/air interface at the back
# MUST specify no_back_reflection = False, so that Solcore does not automatically suppress reflections from the back
# (currently, the default setting in solcore is to suppress reflections from the back, so no_back_reflection = True
# (currently, the default setting in solcore is to suppress reflections from the back, so no_back_reflection = True)
solar_cell_solver(thin_GaAs, 'optics', user_options={'wavelength': wl, 'optics_method': 'TMM', 'no_back_reflection': False})
z_pos = np.linspace(0, thin_GaAs.width, 201)
profiles_thin = thin_GaAs[0].absorbed(z_pos)
Expand Down
20 changes: 1 addition & 19 deletions docs/source/Examples/tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -169,14 +169,6 @@ of the window and BSF layers, and (2) the missing layers are added
outside the Junction object when creating the full solar cell in order
to consider their optical properties (see below).

**TRICK:** The TMM solver work best with "thin" layers therefore, if the
results of optical calculations look strange, try dividing thick layers
(> 2-3 µm) into thinner ones (~500 nm). The reason is that the waves
propagating forwards and backwards, leading to interference are
ultimately complex exponentials that increase (or decrease) quite fast
away from the interfaces, resulting in a loss of numerical accuracy when
they trying to interact far from the interfaces.

The only tunnel junction of this solar cell will be defined according to
the parametric model and we will assume it is made of GaInP layers, 40
nm-thick in total, that will block part of the light reaching the bottom
Expand Down Expand Up @@ -246,6 +238,7 @@ code that defines the spectrum to use and lunch the calculation will be:
solar_cell_solver(my_solar_cell, 'qe',
user_options={'light_source': light_source, 'wavelength': wl, 'optics_method': 'TMM'})


The calculation will proceed in several stages: (1) The structure is
processed and discretized, (2) the problem is solved under equilibrium,
(2) the problem is solved under short circuit conditions increasing in
Expand All @@ -256,17 +249,6 @@ densities at equilibrium (dashed line) and at short circuit (continuous
line), as well as the EQE of the two junctions and the total absorption
in the layers.

.. code:: python

from solcore.solar_cell_solver import solar_cell_solver
from solcore.light_source import LightSource

light_source = LightSource(source_type='standard', version='AM1.5g', x=wl,
output_units='photon_flux_per_m', concentration=1)

solar_cell_solver(my_solar_cell, 'qe',
user_options={'light_source': light_source, 'wavelength': wl, 'optics_method': 'TMM'})

.. figure:: qe.jpg
:alt: Quantum efficiency

Expand Down
104 changes: 57 additions & 47 deletions docs/source/Installation/Solcore_on_Windows.md
Original file line number Diff line number Diff line change
@@ -1,83 +1,93 @@
Solcore on Windows 10
=====================
The Python part of Solcore, which is the majority, should work under Windows with no problems. However, we have found a lot trouble trying to make the parts and complements that require compilation to work properly (the PDD solver, S4, SMARTS and SPICE). For those who need to use those tools, please follow the instructions below.
The Python part of Solcore, which is the majority, should work under Windows with no problems. However, we have had some
trouble trying to make the parts and complements that require compilation to work properly (the PDD solver, S4, SMARTS
and SPICE). For those who need to use those tools and encounter issues on Windows, please follow the instructions below.

Note that in principle, out of the packages listed above (the PDD solver, S4, SMARTS and SPICE), all can be
installed on Windows **except S4**, which to date we have not been able to produce Windows installation instructions for.
To compile the PDD, you need to do [a few extra steps](compilation.md) to get a suitable compiler working.
S4 is only required to use the rigorous coupled-wave analysis (RCWA) functionality in Solcore, used to calculate diffraction
from periodic structures (e.g. diffraction gratings, photonic crystals). Thus, if you do not need this functionality, you
can stick with Windows.

Installing Solcore
------------------
(thanks Phoebe!)

After a lot of effort, we have Solcore fully up and running in Windows 10... more or less, using the Ubuntu shell that comes with Windows 10. To install Solcore there, follow this steps:
It is possible to run all the parts of Solcore from a Windows 10 environment without using a virtual machine or dual-booting a UNIX operating
system (e.g. Ubuntu). This can be done by using the Ubuntu shell that comes with Windows 10. **It should be noted that this Windows
Subsystem on Linux (WSL) does not support graphical applications, so it is purely a command line environment.** This can be
phoebe-p marked this conversation as resolved.
Show resolved Hide resolved
inconvenient for actually writing code and viewing results, so please bear this in mind before continuing with the instructions below.
If you are having problems on Windows (or want to use the RCWA functionality/S4) and do not want to be limited to a command-line only
environment, we recommend installing Ubuntu either as a virtual machine, or as a dual boot alongside Windows 10. If you do want to
install Solcore on WSL, follow these steps:

All steps on fresh install of Ubuntu (using the Ubuntu terminal on
Windows 10 distributed by Canonical Group, Ubuntu 16.04.3 LTS, Codename:
xenial)

- Install git if not done already
- Install python 3.x if not already done
- Install pip3 (for installing Python3 packages; you may need to update the package list first: sudo apt-get update)::

```bash
sudo apt install python3-pip
```
- You need LAPACK and BLAS libraries linked to the -llapack and -lblas library flags – these are used for scipy and S4. The developers of S4 recommend OpenBLAS (you can find installation instructions by Googling), but this also works and is simpler:
- Install git if not done already
- Install python 3.x if not already done
- Install pip3 (for installing Python3 packages; you may need to update the package list first: `sudo apt-get update`):

```bash
sudo apt-get install libblas-dev liblapack-dev
```
```bash
sudo apt install python3-pip
```

- Install matplotlib (and tk, otherwise get an error later):
- Install matplotlib (and tk, otherwise get an error later):

```bash
pip3 install matplotlib
sudo apt-get install python3-tk
```

- Other dependencies install automatically & successfully when
installing Solcore5... hopefully.
```bash
pip3 install matplotlib
sudo apt-get install python3-tk
```

- Now, we actually Install Solcore::
- Install Solcore5, which can be done according to the [standard instructions](installation.rst).

```bash
git clone https://github.com/dalonsoa/solcore5.git
cd solcore5
sudo python3 setup.py install
```

Installing S4
-------------

- The “make” command must be available:
- The “make” command must be available:

```bash
sudo apt install make
```
```bash
sudo apt install make
```

- You need LAPACK, BOOST, FFT and BLAS libraries to compile S4. The developers of S4 recommend OpenBLAS (you can find installation
instructions by Googling), but this also works and is simpler:

```bash
sudo apt install libopenblas-dev libfftw3-dev libsuitesparse-dev libboost-all-dev
```

- You must use the fork of S4 at https://github.com/phoebe-p/S4; the
main branch is not compatible with Python 3.x:
(if you have any issues, more detailed installation instructions can be found [here](https://github.com/phoebe-p/S4).
- You must use the fork of S4 at [https://github.com/phoebe-p/S4](https://github.com/phoebe-p/S4), as the
main branch is not compatible with Python 3:

```bash
git clone https://github.com/phoebe-p/S4.git
cd S4
make S4_pyext
```
```bash
git clone https://github.com/phoebe-p/S4.git
cd S4
make S4_pyext
```

Checking if everything works
--------------------------

- To see if the PDD is working:

```bash
python3
>>> import solcore.solar_cell_solver
```
```bash
python3
>>> import solcore.solar_cell_solver
```

- Run tests:

```bash
sudo python3 setup.py test
```
```bash
sudo python3 setup.py test
```

This might result in an error saying that quantum mechanics failed because 5\ :sup:`th` decimal place of result doesn’t match. Simply, ignore it.
This might result in an error saying that quantum mechanics failed because 5\ :sup:`th` decimal place of result doesn’t match.
You can simply ignore this error.

- Other information:
- gcc/g++/gfortran versions used here: gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.6)
Expand Down
4 changes: 4 additions & 0 deletions docs/source/Installation/compilation.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ For Mac OS X we have used the *gfortran* compiler installed together with GCC us

Other package managers like [MacPorts](https://www.macports.org) or [Fink](http://www.finkproject.org) might also work, but we have not tried.

There is currently a known issue involving the compilation of the PDD solver on new Macs with M1/ARM/Apple silicon chips.
phoebe-p marked this conversation as resolved.
Show resolved Hide resolved
The homebrew version of gfortran (installed above alongside gcc as indicated above) does not work. For a workaround please
see [here](https://github.com/qpv-research-group/solcore5/issues/209).

## Windows

To get a Fortran compiler properly working under Windows with F2Py, we have followed the [detailed instructions written by Michael Hirsch](https://www.scivision.co/f2py-running-fortran-code-in-python-on-windows/). Read Michael Hirsch's instructions in full for a complete picture, but the important bits are:
Expand Down
21 changes: 15 additions & 6 deletions docs/source/Installation/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,16 @@ Once you are ready to install it in your own machine, go to the next section.
Installing Solcore
^^^^^^^^^^^^^^^^^^

Solcore is written mostly in Python, but the Poisson-Drift-diffusion (PDD) solver is written in Fortran to make it more efficient. The following instructions are expected to work in most systems, but check the sections below for OS specific instructions and caveats. In order to install Solcore in your computer, you will need the following:
Solcore is written mostly in Python, but the Poisson-Drift-diffusion (PDD) solver is written in Fortran to make it more efficient,
and the RCWA (rigorous coupled-wave analysis) solver uses the package S4 which is written in C++.
The following instructions are expected to work in most systems, but check the sections below for OS specific instructions and caveats.
In order to install Solcore in your computer, you will need the following:

- Python >3.7
- pip
- setuptools
- :doc:`a suitable Fortran compiler (only needed for the PDD solver) <compilation>`
- :doc:`the S4 package <s4_installation>` (only needed for RCWA functionality)
phoebe-p marked this conversation as resolved.
Show resolved Hide resolved

*Pip* is normally part of the standard Python installation, but you might need to install *setuptools* manually with::
phoebe-p marked this conversation as resolved.
Show resolved Hide resolved

Expand Down Expand Up @@ -70,11 +74,11 @@ Install in development mode

If you are planning to develop Solcore further, you would want to have all the files in an accessible place but still being able to use the package from other places and examples, behaving as if it were truly installed. For this, install Solcore in development mode. `Download the source from the Solcore GitHub repository <https://github.com/dalonsoa/solcore5>`_ as above and then::

pip install -e .[dev]
pip install -e ".[dev]"

or::

pip install -e .[dev] --install-option="--with_pdd"
pip install -e ".[dev]" --install-option="--with_pdd"

Solcore uses *pre-commit* to do a few things before commiting the changes (for example, clearing the output of Jupyter Notebooks). The *pre-commit* package is installed automatically with the above commands, but each user needs to be initialise it before it can work. This can be done with::

Expand All @@ -97,7 +101,7 @@ After installing Solcore (or even without installing it), there are a few things
from solcore import config
print(config)

You can find all the functionality of the :code:`config` object in `The config_tools`_
You can find all the functionality of the :code:`config` object in `The config_tools`_.

2. **Check Solcore examples:** This is the fastest way of getting started. These examples include all the scripts used in the main Solcore paper in the `Journal of Computational Electronics (2018) <https://doi.org/10.1007/s10825-018-1171-3>`_ and a few others to explore other functionality. We hope to increase the number and usefulness of these examples over time. You can try directly the examples using `MyBinder.org <https://mybinder.org/v2/gh/qpv-research-group/solcore5/deployment>`_.

Expand All @@ -111,7 +115,7 @@ You can find all the functionality of the :code:`config` object in `The config_t
config.smarts('/path/to/the/SMARTS/folder')


4. **Installing S4:** The rigorous-coupled wave analysis (RCWA) solver S4, created by the Stanford University, needs to be installed separately using `the fork by Phoebe Pearce <http://github.com/phoebe-p/S4>`_. The original version **do not work** with Python 3.x, only with Python 2. You can find more information about the solver in the `project webpage <http://web.stanford.edu/group/fan/S4/>`_. An example of its use with Solcore is included in the examples folder, *Figure9.py*.
4. **Installing S4:** The rigorous-coupled wave analysis (RCWA) solver S4, created by the Stanford University, needs to be installed separately using `the fork by Phoebe Pearce <http://github.com/phoebe-p/S4>`_. The original version **does not work** with Python 3.x, only with Python 2. You can find more information about the solver in the `project webpage <http://web.stanford.edu/group/fan/S4/>`_. An example of its use with Solcore is included in the examples folder :doc:`here </Examples/example_optics_comparison>`.

5. **Getting specific information about Solcore:** Even though the documentation "should" be more complete, you can get information about any object in python (including any Solcore function, module and package) using the :code:`help` built-in function, for example::

Expand All @@ -126,10 +130,15 @@ Problems with the installation

There are several things that can go wrong in the above description, specially in Windows.

1. **The tests associated with the Poisson-Drift-Diffusion solver fail**: This is usually the result of not having a Fortran compiler installed in your system, not being correctly configured or having a temperamental F2PY version, the tool - included in numpy - that makes Fotran code accesible from Python. Please, make sure you follow all the steps indicated in the :doc:`Fortran compiler section <compilation>` and above to have the PDD solver up and running.
1. **The tests associated with the Poisson-Drift-Diffusion solver fail**: This is usually the result of not having a Fortran compiler installed in your system, not being correctly configured or having a temperamental F2PY version, the tool - included in numpy - that makes Fortran code accesible from Python. Please, make sure you follow all the steps indicated in the :doc:`Fortran compiler section <compilation>` and above to have the PDD solver up and running.

2. **Some of the dependencies fail to install**: That is rarely the case, as all dependencies are in the main Python repositories. However, there might be issues with Numpy, Matplotlib and Scipy. Depending on your Python distribution, some of these packages might need to be compiled and it is often easy to get them as a scientific bundle. You can check `Anaconda <https://www.continuum.io/downloads>`_ which provides all these packages together already configured for the correct OS.

3. **The PDD solver throws an error, even though I installed it and the installation appeared to be successful**:
This can happen if you are trying to call PDD functions when the solcore5 directory (downloaded from GitHub) is
the current working directory. Try calling the functions from a different working directory (by e.g. copying the file you
are trying to run to a different directory) and seeing if the error persists.

The config_tools
^^^^^^^^^^^^^^^^

Expand Down
12 changes: 12 additions & 0 deletions docs/source/Installation/s4_installation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Installing S4
--------------

Installing S4 is only necessary if you would like to use Solcore's rigorous coupled-wave analysis (RCWA) functionality.
This is a wave optical method for solving Maxwell's equations in a periodic structure, and can be used for structures which
contain e.g. a diffraction grating or other photonic structures. S4 is written in C++ and must be compiled on your system
before you are able to import it as a Python package. Up-to-date instructions on how to do this in MacOS
and Ubuntu are maintained [here](https://github.com/phoebe-p/S4) (scroll down to the README section). We do not currently have
installation instructions for other Linux distributions, but it should be possible to compile S4 on any UNIX operating system
as long as the relevant packages are installed first (see the link above for requirements). Unfortunately,
there are currently no instructions available for installing S4 on Windows; if you want to use the RCWA functionality from
a Windows machine there are [a few options](Solcore_on_Windows.md).
Loading