diff --git a/Example_Mesh_Creation.ipynb b/Example_Mesh_Creation.ipynb new file mode 100644 index 0000000..565d446 --- /dev/null +++ b/Example_Mesh_Creation.ipynb @@ -0,0 +1,269 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Notes on Spatial Information for StochSS\n", + "\n", + "When setting up a spatial problem in StochSS information about the geometry needs to be provided through two files: a\n", + "file containing the mesh information in DOLFIN XML format and a text file containing information about subdomains. The\n", + "file with subdomain information is optional in general (if it is not provided the entire mesh will belong to one subdomain).\n", + "Below is a tutorial on how to provide that information in a variety of cases.\n", + "\n", + "## Mesh Library \n", + "\n", + "The first and simpilest scenario is using one of the default builtĀin meshes provided by StochSS in the Mesh Library.\n", + "These include simple example mesh and subdomain combinations that are common in biological modeling. For example\n", + "there is a unit sphere with a membrane (i.e. the volume is one subdomain and the surface is another), a unit cube witha\n", + "membrane, a cylinder with the two ends being different subdomains among others. If for a given problem these are not\n", + "sufficient then mesh and subdomain information can be provided by attaching files. One simple case where creating and\n", + "attaching a file may be necessary could involve using the DOLFIN built in meshes but with different subdomains than\n", + "provided in the Mesh Library. This can be done as follows.\n", + "## Using DOLFIN Built-In Geometry with Subdomains Outside of Mesh\n", + "Library\n", + "For example consider a sphere with three different subdomains: the top half of the membrane, the bottom half of the\n", + "membrane and the volume. This can be done using pyurdme as follows (pyurdme and FEniCS are software packages\n", + "that are automatically installed during the StochSS installation and DOLFIN is a library within FEniCS).\n", + "First the appropriate libraries need to be imported:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "FILENAME = \"sphere_top_bot_mesh.xml\"\n", + "SD_FILENAME = \"sphere_top_botsubdomains.txt\"" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "import dolfin\n", + "import mshr\n", + "import os\n", + "import pyurdme" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "class top_half_membrane(dolfin.SubDomain):\n", + " def inside(self,x,on_boundary):\n", + " return on_boundary and x[2]>=0\n", + "class bottom_half_membrane(dolfin.SubDomain):\n", + " def inside(self,x,on_boundary):\n", + " return on_boundary and x[2]<=0" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "class sphere_top_bot(pyurdme.URDMEModel):\n", + " def __init__(self,model_name=\"polarization\"):\n", + " pyurdme.URDMEModel.__init__(self,model_name)\n", + " #DefineGeometry\n", + " sphere=mshr.Sphere(dolfin.Point(0.0,0.0,0.0),1.0)\n", + " self.mesh=pyurdme.URDMEMesh(mesh=mshr.generate_mesh(sphere,10))\n", + " cell_function=dolfin.CellFunction(\"size_t\",self.mesh)\n", + "\n", + " self.add_subdomain(top_half_membrane(),2)\n", + " self.add_subdomain(bottom_half_membrane(),3)\n", + " #Defineinitialpopulations\n", + " self.set_initial_condition_scatter({},[1])" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "model=sphere_top_bot()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "sd=model.get_subdomain_vector()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "#This is a dolfin xml file with mesh information\n", + "dolfin.File(FILENAME) << model.mesh" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "import base64\n", + "import IPython.display\n", + "with open(FILENAME) as fd:\n", + " b64 = base64.b64encode(fd.read())\n", + " payload = b64.decode()\n", + " html = '