diff --git a/examples/additive_coag_comparison.ipynb b/examples/additive_coag_comparison.ipynb
index b29d201e..481db287 100644
--- a/examples/additive_coag_comparison.ipynb
+++ b/examples/additive_coag_comparison.ipynb
@@ -52,13 +52,7 @@
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"from open_atmos_jupyter_utils import show_plot\n",
- "from open_atmos_jupyter_utils.show_anim import show_anim \n",
- "import PySDM as pysdm\n",
- "from PySDM import environments\n",
- "from PySDM.initialisation import spectra\n",
- "from PySDM.dynamics.collisions import collision_kernels\n",
- "from PySDM import products\n",
- "import PyPartMC as ppmc"
+ "from open_atmos_jupyter_utils.show_anim import show_anim \n"
]
},
{
@@ -68,4190 +62,471 @@
"metadata": {},
"outputs": [],
"source": [
- "N_PART = 2**16\n",
- "VOLUME_M3 = 1e6\n",
- "DT_SEC = 1.\n",
- "T_MAX_SEC = 3600\n",
- "NUM_CONC_PER_M3 = 2**23\n",
- "DIAM_AT_MEAN_VOL_M = 2*30.531e-6\n",
- "ADDITIVE_KERNEL_COEFF = 1000\n",
- "AMBIENT_T_K = 288\n",
- "AMBIENT_P_Pa = 1e5\n",
- "AMBIENT_RH = 0.999\n",
+ "from collections import namedtuple\n",
"\n",
- "# Plotting parameters\n",
- "N_BINS = 128\n",
- "N_BIN_EDGES = N_BINS + 1\n",
- "R_BINS_MIN = 1e-5\n",
- "R_BINS_MAX = 5e-3\n",
- "PLOT_TIME_STEP = 120 # seconds\n",
- "BINNING_METHOD = 'Mass Density (g/m^3 dlnr)' # 'Number Concentration (m^-3)' or 'Mass Density (g/m^3 dlnr)'\n"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 5,
- "id": "7f986747",
- "metadata": {},
- "outputs": [
- {
- "name": "stderr",
- "output_type": "stream",
- "text": [
- "/Users/emmaware/Library/Python/3.9/lib/python/site-packages/PySDM/backends/numba.py:46: UserWarning: Disabling Numba threading due to ARM64 CPU (atomics do not work yet)\n",
- " warnings.warn(\n"
- ]
- }
- ],
- "source": [
- "radius_bins_edges=np.logspace(np.log10(R_BINS_MIN), np.log10(R_BINS_MAX), num=N_BIN_EDGES, endpoint=True)\n",
- "\n",
- "\n",
- "builder = pysdm.Builder(\n",
- " N_PART,\n",
- " backend=pysdm.backends.CPU(),\n",
- " environment=environments.Box(dt=DT_SEC * pysdm.physics.si.s, \n",
- " dv=VOLUME_M3 * pysdm.physics.si.m**3)\n",
- ")\n",
- "trivia = builder.formulae.trivia\n",
- "spectrum = spectra.Exponential(\n",
- " norm_factor=NUM_CONC_PER_M3 *VOLUME_M3 / pysdm.physics.si.m**3, #TODO: check\n",
- " scale=trivia.volume(radius=DIAM_AT_MEAN_VOL_M / 2 * pysdm.physics.si.m)\n",
- ")\n",
- "builder.add_dynamic(pysdm.dynamics.Coalescence(\n",
- " collision_kernel=collision_kernels.Golovin(b=ADDITIVE_KERNEL_COEFF)\n",
- "))\n",
- "if BINNING_METHOD == 'Number Concentration (m^-3)':\n",
- " binning = (products.ParticleSizeSpectrumPerVolume(\n",
- " radius_bins_edges=radius_bins_edges,\n",
- " name='spectrum',),)\n",
- "elif BINNING_METHOD == 'Mass Density (g/m^3 dlnr)':\n",
- " binning = (products.ParticleVolumeVersusRadiusLogarithmSpectrum(\n",
- " radius_bins_edges=radius_bins_edges,\n",
- " name='spectrum',),)\n",
- "\n",
- "particulator = builder.build(\n",
- " attributes=builder.particulator.environment.init_attributes(\n",
- " spectral_discretisation=pysdm.initialisation.sampling.spectral_sampling.Logarithmic(\n",
- " spectrum,\n",
- " )\n",
- " ),\n",
- " products=binning\n",
- ")\n",
- "# print(np.amax(particulator.attributes[\"multiplicity\"].to_ndarray()))\n",
- "particulator.environment[\"rhod\"] = 1. # TODO!\n",
- "pysdm_output = {}\n",
- "for step in range(int(T_MAX_SEC // PLOT_TIME_STEP)+1):\n",
- " if step != 0:\n",
- " particulator.run(int(PLOT_TIME_STEP // DT_SEC))\n",
- " if BINNING_METHOD == 'Number Concentration (m^-3)':\n",
- " pysdm_output[step] = particulator.products['spectrum'].get()\n",
- " #next two lines convert from dr to dlnr\n",
- " pysdm_output[step] *= (radius_bins_edges[1:]-radius_bins_edges[:-1])\n",
- " pysdm_output[step] /= (np.log(radius_bins_edges[1:]) - np.log(radius_bins_edges[:-1]))\n",
- " elif BINNING_METHOD == 'Mass Density (g/m^3 dlnr)': \n",
- " pysdm_output[step] = particulator.products['spectrum'].get()[0]\n",
- " pysdm_output[step][:] *= pysdm.physics.constants_defaults.rho_w * pysdm.physics.si.kilogram / pysdm.physics.si.metre**3 \n",
- " pysdm_output[step][:] /= pysdm.physics.si.g"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 6,
- "id": "6c9e2cbd",
- "metadata": {},
- "outputs": [],
- "source": [
- "collision_kernel=collision_kernels.Golovin(b=ADDITIVE_KERNEL_COEFF)\n",
- "\n",
- "def analytical_solution_golovin(t):\n",
- " X0 = trivia.volume(DIAM_AT_MEAN_VOL_M / 2)\n",
- " volume_bins_edges = trivia.volume(radius_bins_edges)\n",
- " dm = np.diff(volume_bins_edges)\n",
- " dr = np.diff(radius_bins_edges)\n",
- " pdf_m_x = volume_bins_edges[:-1] + dm / 2\n",
- " pdf_r_x = radius_bins_edges[:-1] + dr / 2\n",
- " pdf_m_y = NUM_CONC_PER_M3*VOLUME_M3*collision_kernel.analytic_solution(x = pdf_m_x,t = t,x_0=X0,N_0=NUM_CONC_PER_M3)\n",
- " pdf_r_y = pdf_m_y * dm / dr * pdf_r_x\n",
- " y_true = (\n",
- " pdf_r_y\n",
- " * trivia.volume(radius=pdf_r_x)\n",
- " * pysdm.physics.constants_defaults.rho_w\n",
- " / VOLUME_M3*pysdm.physics.si.metres**3\n",
- " * pysdm.physics.si.kilograms\n",
- " / pysdm.physics.si.grams\n",
- " )\n",
- "\n",
- " return y_true\n"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 7,
- "id": "6c8b3b0c",
- "metadata": {},
- "outputs": [
- {
- "data": {
- "image/svg+xml": [
- "\n",
- "\n",
- "\n"
- ],
- "text/plain": [
- "