Welcome to diffusionpy ! This python package provides a Stefan-Maxwell diffusion model and a PC-SAFT implementation. Furthermore, the package provides additional functions that consider diffusion with crystallization, the swelling and relaxation behavior of polymers and dissolution.
Step 1: A python installation is required. Please install python from the official website (https://www.python.org/downloads). Python versions 3.9-3.12 were tested and should work.
Step 2: Download the zip from the URL https://github.com/Borrdom/diffusionpy/archive/refs/heads/main.zip or copy it to your Harddrive from the Network W: folder.
Step 3: Install diffusionpy as python package. Open the console, cd in the unziped diffusionpy directory and run the pip install
if you have git just open a console and type
git clone https://github.com/Borrdom/diffusionpy
cd diffusionpy
pip install .
alternatively you can download the zip archive and unzip it. Then open your console, cd in the unziped directory and run the pip install
If you have numba installed, the core functions will be precompiled on your machine and run faster. Please note that the first execution of most function will take longer, due to precompilation.
pip install numba
If no errors occoured during installation, the following lines will model the diffusion kinetics of three substances from a starting mass fraction of wi0 to the mass fraction wi8
import numpy as np
from diffusionpy import Diffusion_MS
import matplotlib.pyplot as plt
t=np.linspace(0,300,30) # time points in seconds
D=np.asarray([1E-12,1E-12,5E-14]) # diffusion coefficients in meters per second
wi0=np.asarray([0.33,0.33,0.33]) # mass fractions at t=0
wi8=np.asarray([0.01,0.01,0.98]) # mass fractions in equilibrium
L=5E-6 # diffusion path in meters
mobile=np.asarray([True,True,False]) # specify mobile components
wt=Diffusion_MS(t,L,D,wi0,wi8,mobile)[0]
fig,ax=plt.subplots()
ax.plot(t,wt)
ax.set_xlabel("time / s")
ax.set_ylabel("mass fractions / -")
ax.set_xticks(np.linspace(0,300,5))
ax.set_yticks(np.linspace(0,1,5))
plt.show()
check out the jupyter notebooks in the examples folder.
can be found here.
BSD-3
Just copy the https://github.com/Borrdom/diffusionpy/tree/main/.matplotlib folder into your %USERPROFILE%. This will alter the matplotlib rc permantly so that the format below will be your new default.
import matplotlib.pyplot as plt
import numpy as np
x=np.linspace(1,10,11)
y1=x+1
y2=x+2
y3=x+3
fig,ax=plt.subplots()
ax.plot(x,x,'ko-')
ax.plot(x,y1,'C6s-')
ax.plot(x,y2,'C3^-')
ax.plot(x,y3,'C0*-')
ax.set_xlabel(r'$m_{Aminoacid}/(gmol^{-1})$')
ax.set_ylabel(r'$\alpha/(Jmol^{-1})$')
ax.set_xticks(np.linspace(0,12,7))
ax.set_yticks(np.linspace(0,14,8))
plt.show()
Moreover, Matplotlib will recognize the following formatstrings as these colors.
Feel free to contribute to the project. If you have questions regarding the implementation or usage do not hesitate to contact me ([email protected])
It is recommended to update the documentation when changes were made. New functions should contain detailed docstrings. Check e.g the docstring of the Diffusion_MS function. This way, the documentation can be autogenerated using sphinx. Just run
sphinx-build -M html . docs
and update commit the changes as usual.