From 39589fc8daa87435a216afb7b50c638a7860d934 Mon Sep 17 00:00:00 2001 From: Bryan Rumsey Date: Tue, 9 Nov 2021 16:43:17 -0500 Subject: [PATCH] Started the implementation of the Microfluidics Flow past a Yeast Cell example. --- .../Microfluidics Flow.ipynb | 227 ++++++++++++++++++ 1 file changed, 227 insertions(+) create mode 100644 examples/Microfluidics Flow/Microfluidics Flow.ipynb diff --git a/examples/Microfluidics Flow/Microfluidics Flow.ipynb b/examples/Microfluidics Flow/Microfluidics Flow.ipynb new file mode 100644 index 00000000..0a8e6848 --- /dev/null +++ b/examples/Microfluidics Flow/Microfluidics Flow.ipynb @@ -0,0 +1,227 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "cd233b01", + "metadata": {}, + "source": [ + "# Microfluidics flow past Yeast Cell with SpatialPy" + ] + }, + { + "cell_type": "markdown", + "id": "ed346aba", + "metadata": {}, + "source": [ + "## Definition of the model" + ] + }, + { + "cell_type": "markdown", + "id": "110aa888", + "metadata": {}, + "source": [ + "### Imports and definitions" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "3724e038", + "metadata": {}, + "outputs": [], + "source": [ + "import os\n", + "import sys\n", + "import math\n", + "sys.path.insert(1, \"../../\")\n", + "import numpy as np\n", + "import matplotlib.pyplot as plt\n", + "\n", + "import spatialpy" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "21e18b70", + "metadata": {}, + "outputs": [], + "source": [ + "class Fluid(spatialpy.Geometry):\n", + " def __init__(self, external_radius):\n", + " self.ers = external_radius**2\n", + " \n", + " def create_particles(self, domain, xmin, xmax, ymin, ymax, zmin, zmax, delta):\n", + " Np = 0\n", + " for x in np.arange(xmin, xmax+delta, delta):\n", + " for y in np.arange(ymin, ymax+delta, delta):\n", + " for z in np.arange(zmin, zmax+delta, delta):\n", + " if self.inside((x, y, z), False):\n", + " domain.add_point([x, y, z], type=0, vol=1, mass=1, nu=0, fixed=False)\n", + " Np += 1\n", + " return Np\n", + " \n", + " def inside(self, x, on_boundary):\n", + " return x[0]**2 + x[1]**2 + x[2]**2 > self.ers" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "90b0634a", + "metadata": {}, + "outputs": [], + "source": [ + "class CellWall(spatialpy.Geometry):\n", + " def __init__(self, external_radius, internal_radius):\n", + " self.ers = external_radius**2\n", + " self.irs = internal_radius**2\n", + " \n", + " def create_particles(self, domain, external_radius, delta):\n", + " Np = 0\n", + " for x in np.arange(-external_radius, external_radius+delta, delta):\n", + " for y in np.arange(-external_radius, external_radius+delta, delta):\n", + " for z in np.arange(-external_radius, external_radius+delta, delta):\n", + " if self.inside((x, y, z), False):\n", + " domain.add_point([x, y, z], type=0, vol=1, mass=1, nu=0, fixed=False)\n", + " Np += 1\n", + " return Np\n", + " \n", + " def inside(self, x, on_boundary):\n", + " radius = x[0]**2 + x[1]**2 + x[2]**2\n", + " return radius < self.ers and radius > self.irs" + ] + }, + { + "cell_type": "markdown", + "id": "6f7417b4", + "metadata": {}, + "source": [ + "### Model" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "2b454eb2", + "metadata": {}, + "outputs": [], + "source": [ + "class MicrofluidicsFlow(spatialpy.Model):\n", + " FLUID = 1\n", + " \n", + " def __init__(self, model_name=\"Microfluidics Flow past Yeast Cell\"):\n", + " spatialpy.Model.__init__(self, model_name)\n", + " \n", + " # System Constants\n", + " Lxint = 80e-6\n", + " Lyint = 40e-6\n", + " Lzint = 20e-6\n", + " radius_external = 2.5e-6\n", + " radius_internal = 2.4e-6\n", + " rhof = rhoc = 1000\n", + " \n", + " # Species\n", + " \n", + " # Discretization\n", + " Npx = 40\n", + " \n", + " # Compute domain bounds (including the boundary)\n", + " deltaf = Lxint/Npx\n", + " deltac = deltaf/3\n", + " xmin = -Lxint/2\n", + " xmax = Lxint/2\n", + " ymin = -Lyint/2\n", + " ymax = Lyint/2\n", + " zmin = -Lzint/2\n", + " zmax = Lzint/2\n", + " \n", + " # Domain\n", + " domain = spatialpy.Domain(\n", + " 0, xlim=(xmin, xmax), ylim=(ymin, ymax), zlim=(zmin, zmax), gravity=[0, -1, 0]\n", + " )\n", + " # Fluid Region\n", + " fluid_region = Fluid(radius_external)\n", + " Nfp = fluid_region.create_particles(domain, xmin, xmax, ymin, ymax, zmin, zmax, deltaf)\n", + " # Cell Wall Region\n", + " cell_region = CellWall(radius_external, radius_internal)\n", + " Ncp = cell_region.create_particles(domain, radius_external, deltac)\n", + " \n", + " self.add_domain(domain)\n", + " \n", + " # Compute volume and mass per particle\n", + " vol = Lxint*Lyint*Lzint\n", + " vol_cell_int = 4/3*math.pi*math.pow(radius_internal, 3)\n", + " vol_cell_ext = 4/3*math.pi*math.pow(radius_external, 3)\n", + " vol_cell_wall = vol_cell_ext-vol_cell_int\n", + " vol_fluid = vol-vol_cell_ext\n", + " mfluid = vol_fluid*rhof/Nfp\n", + " mcell = vol_cell_wall*rhoc/Ncp\n", + " \n", + " # Types\n", + " \n", + " # Static Domain\n", + " \n", + " # Initial Conditions\n", + " \n", + " # Boundary Conditions\n", + " \n", + " # Timespan\n", + " dt = 1e-6\n", + " nt = 10000000\n", + " freq_results = 100\n", + " self.timespan(np.arange(0, (nt + 1) * dt, freq_results * dt), timestep_size=dt)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "5fd22cfc", + "metadata": {}, + "outputs": [], + "source": [ + "model = MicrofluidicsFlow()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "cb8b3513", + "metadata": {}, + "outputs": [], + "source": [ + "model.domain" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ff946d58", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.9.7" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +}