TITLE: Bacterial growth model
AUTHORS: Wolfram Moebius

[DESCRIPTION]
Bacterial growth model

[STEPS]
1. RELEVANT TUTORIALS
https://www.comsol.com/model/microchannel-h-cell-19
https://www.comsol.com/model/hydrocarbon-dehalogenation-in-a-tortuous-microreactor-2182

To create the spatial aspect of our model, we use the Geometry 1 menu to add blocks which represent individual channels or sheets of agar, and set the dimensions and coordinates to arrange the blocks according to the real life geometry.

Create a new project in COMSOL using the Model Wizard: Select 3D for the dimension, add the Transport of Diluted Species, Surface Reactions and Laminar Flow modules (under Chemical Species Transport and Fluid Flow>Single-Phase Flow), and select Empty Study.
Select the Geometry 1 menu in Model Builder (left hand side of the screen).
In the Settings, change the Length unit to mm.
Right click Geometry 1 in Model Builder and add a Block to represent the agar sheet. Add further Blocks for channels. This will be a Solid type whether it is a channel or agar.
In the Block Settings, alter the Size and Shape and Position of each to correspond to the real life geometry.  
Select Build All Objects to show the geometry in the Graphics window (on the right of the screen). If the whole structure isn't visible, you can zoom using the buttons above the Graphics window.

 
  
N.B. 

Values used in example: 
Three channels w, d, h = 1/1/0.5, 1, 1 mm, x = 0/6/12 mm.
Agar w, d, h = 27.5, 1, 1.7 mm, x, z = -15, 1 mm.
The model is symmetrised through the middle of the third channel to improve efficiency, with the agar and channel therefore cut-off at this point.  

The size of the area of agar with no channels above (simulating the empty channel side of an experiment) was set as 15 mm, as past this value there was minimal difference in surface concentration over time.

Any value can be set globally by defining a variable in Parameters 1 in the Model Builder, and typing the name of the variable in an input box. Values can also be functions of parameters: for example, setting the channel height as a parameter of hchannel = 1 mm and the agar z value as hchannel ensures that changing the channel height automatically moves the agar by the same amount.

To change the units, suffix values with [unit_of_choice], e.g. [mm].

 
2. To model bulk transport of nutrients and byproducts in the device, we use the Transport of Diluted Species 1 menu to set convection and diffusion patterns within the channels and agar separately.

In the Model Builder, select Transport of Dilute Species 1, and in the Settings add two Dependent Variables: cGlu and cBy for glucose and byproduct concentrations respectively.
Right click the Transport Properties 1 submenu and Duplicate - we need separate properties for the agar and channel. 
Repeat for the Initial Values 1 submenu.
Whilst Transport Properties 2 is highlighted, click on the agar sheet in the Graphics window to deselect it - this menu now only applies to the channels and supersedes the original Transport Properties 1, which will now only affect the agar. 
Repeat for the Initial Values 2 submenu.
Select Transport Properties 1 and in Settings, set the diffusion coefficients for the glucose and byproducts (6E-10 and 1E-9 m2/s are a good estimate for glucose and byproducts in 1.5% agar and channels, but with harder agar, the agar values may be lower). 
Repeat for the Transport Properties 2 submenu.
Select Transport Properties 1 and change the Velocity field from Velocity field to User defined, and leave the values at 0 to disallow convection in the agar sheet. 
Select Initial Values 2 and set the initial concentration of glucose in the channels as that in the media flow (we assumed 3 mM glucose in LB media). There should be no byproducts in the device initially.
If there are nutrients in the agar sheet, set this initial concentration in Initial Values 1.

 
3. To enable flow of nutrients and byproducts through channels, we use the Transport of Diluted Species 1 menu to set inflow and outflow at each end of the channel.

Right click Transport of Diluted Species 1 and add an Inflow. Select the end of the channel visible in the Graphics window to set this as the inlet. 
In the Inlet settings, change the Boundary condition type to Flux (Danckwerts). Set the glucose and byproduct concentration of the inflow of media to the same as the initial value above.
Right click Transport of Diluted Species 1 and add an Outflow, selecting the opposite end of the channel in the Graphics window. You can rotate the view by clicking and dragging. 
If symmetrising the spatial model, add a Symmetry constraint to Transport of Diluted Species 1 , selecting the side of the channel and agar sheet that have been bisected.

 
5. To model consumption and production of glucose and byproducts as they interact with bacteria at the agar surface, we use the Transport of Dilute Species 1 menu to set reaction rates for each species.

Right click Transport of Dilute Species 1 and add a Surface Reactions submenu. Click on the agar surface in the Graphics window to select it and isolate reactions to this surface.
As glucose consumption and byproduct production are proportional to the rate of local biomass production, we link these reaction rates to the local rate of increase of bacteria, which in COMSOL syntax is denoted sr.Rs_cBac. 
We treat moles of bacteria as equivalent to grams of bacteria, so ensure rates are in mol_glucose/g_bacteria and mol_byproducts/g_bacteria
Standard operators are used in COMSOL (^*/+-).

N.B. 

The glucose rate is negative as the glucose is removed from the system.

Values used were dependent on the bacterial density, where a local density higher than 5 g/m2 was assumed to grow anaerobically. Byproducts were not assumed to be produced aerobically as the concentration is low.

This can be performed in COMSOL with an if statement, for example: sr.Rs_cBac * if(cBac<5[mM], aerobicyield, anaerobicyield).
4. To model the initial distribution of bacteria streaked over the agar surface, we use the Surface Reactions 1 menu to set an initial 2D rectangular density function for bacterial concentration. To model growth of bacteria upwards and across the surface in response to nutrient availability and byproduct concentration, we set up a reaction-diffusion system, with the reaction rate of the bacterial concentration according to Monod kinetics (equation below), and a diffusion coefficient fit to the wave speed found experimentally.

Right click on Definitions in Model Builder and select Rectangle in Functions. This will allow use of the rect1 function, creating a 1D rectangular pulse. The syntax rect1((x-x0[mm])/xlength[mm]) creates a structure of length xlength centred on x0. 
Select the Surface Reactions 1 menu. In Settings, rename the Dependent Variable>surface species as cBac for the bacterial colony. Deselect all surfaces in Boundary Selection, and select the agar surface in the Graphics window as we only want reactions to occur on this surface. 
Expand the Surface Reactions 1 menu if collapsed. In the Initial Values 1 submenu, input the desired initial bacterial density multiplied by a rectangular function representing a bacterial streak in the y direction, and a separate rectangular function in the x direction to form a 2D surface.
In the Surface Properties submenu, set the diffusion coefficient of the bacteria across the surface. 
Select the Reactions 1 submenu and input the Monod equation multiplied by the bacterial concentration as the bacterial reaction rate, with cGlu and cBy as glucose and byproduct concentrations. Exponential powers are represented as exp(arg). 

 
 
Mu is rate of bacterial growth, mumax is the maximum growth rate, S is glucose concentration, kS is the half-monod constant, I is byproduct concentration and I* is the inhibition constant.

N.B. 

We assumed the initial population was a fully populated monolayer, so used 0.1 g/m2 as the bacterial density (from literature). As above, moles of bacteria are considered equivalent to grams of bacteria.

We assumed this was 1.5 mm wide and stretched the length of the channel, so set the density as 0.1 * rect1((x-0.5[mm])/1.5[mm])*rect1(y/3[mm])

The coverage area can be tested by selecting Analytics in the same Functions menu and inputting the desired function into the Expression box.

Growth values used were dependent on the bacterial density, where a local density higher than 5 g/m2 was assumed to grow anaerobically, with a different growth rate. Growth parameters are noted in Table 3.1.

A maximum of 1 g/m2 was assumed to be actively growing (from literature) with any excess bacteria being quiescent. 

 
 

 
6. To model the laminar flow of media through channels, we set inlets and outlets (corresponding to the inflow and outflow of materials as defined previously) with defined flow conditions using the Laminar Flow 1 menu. As the flow is not time-dependent, we can model this once at the beginning of a simulation to reduce computation load.

Select the Laminar Flow 1 menu and deselect the agar sheet in the Graphics window to ensure only the channels are affected. In settings, change Compressibility to Incompressible flow as the media flow is a liquid. 
Add an Inlet condition and set the same end of the channel as the Inflow 1 previously. Change the Boundary Condition to Fully developed flow, and select the Flow rate option. If symmetrising the channel, input half the desired flow rate here as only half the channel is modelled (1 ml/h). 
Add an Outlet condition and set the same end of the channel as the Outflow 1 previously. Ensure the Boundary Condition here is set to Pressure. If symmetrising the channel, add a Symmetry condition and select the bisected edge of the channel.

 
N.B. 

If symmetrising the channel flow, ensure you halve the flow rate or use velocity instead to prevent confusion.
7. To simulate our device, COMSOL discretises the model spatially and temporally. The spatial discretisation is defined by a mesh of points, created in the Mesh 1 menu. COMSOL will automatically design a mesh, but this should be optimised for different parts of the design manually.

Select the Mesh 1 menu in Model Builder. In the Settings, change the Sequence type to User controlled mesh, which will open new submenus. 
Selecting the Size submenu, you can set the overall mesh size, either with predefined or custom settings.
Selecting the Size 1 submenu, you can set the channel mesh size. Delete Size 2 as this is unnecessary.
To Mesh 1 add a Mapped condition (found under More Operations), and within this select the agar surface in the Graphics window. 
Right click on the new Mapped 1 submenu and add a Size condition. This can set the mesh size at the agar surface. 
Click and drag the Mapped 1 submenu up above the Free Tetrahedral 1 submenu or the latter will take precedence.

 

N.B.

The overall mesh size was set to Custom with a maximum size of 0.9, maximum growth of 1.25 and minimum size of 0.04 mm to ensure a small mesh near channels and the surface, but not elsewhere. 

The channel mesh size was set to Finer as convective flow requires a small mesh. The agar surface mesh size was set with a grid of 0.045 mm to ensure the bacterial profile, our primary output, is highly reliable.
8. To set up the study parameters, we set steps in the Study 1 menu. We then set up visualisations of bacteria, glucose and byproducts in the Results menu to be viewed whilst the study is running. We can then run a simulation.

Right click the Study 1 menu and add a Stationary step (found under Study steps and Stationary). and then a Time Dependent step. 
Deselect all but Laminar Flow 1 in the settings for the Stationary step - this will pre-solve the flow regime, improving efficiency. 
Deselect Laminar Flow 1 in the Time Dependent step to ensure it is not solved twice. 
Right click on Study 1, selecting Get initial value. This sets up a solution folder the study will be contained in. 
Right click the Results menu and add 3D Plot Group - this will visualise the solution. 
In Results in the Model Builder, select Surface Species Concentration - this visualises the bacterial concentration on the agar surface. Right click and add a Slice condition. In Settings, type cGlu into the Expression box, change the Plane to xz and the number of planes to 1. Selecting Interactive, you can shift this slice across the geometry with the scroll bar - move it to the leftmost point. 
Duplicate this slice and repeat for the byproduct concentration, but move this to the rightmost point.
Back in Study 1, select the Time Dependent step. In Results While Solving, select Plot and find the 3D plot in the Plot group drop menu. Update at Timesteps taken by solver for a live view of the simulation.
The output timesteps and overall timescale of a study can be altered in this submenu with the syntax range(start, step, stop). 
To start a study, select Compute and allow the program to run. COMSOL will give relevant information about the running study in the Log, Messages and Progress menus under the Graphics window, and in Convergence Plots found in the tab above the Graphics window. 
When complete, navigate back to the Results menu where drop boxes in the settings will allow you to look at different times in the simulation.

N.B. 

You can change and invert the colour schemes with the Color table drop menu.

 
 
9. Convergence Plot 1 will give you information on the stationary solver. 

Convergence Plot 2 will give you information on the time dependent solver - this should always be decreasing in error over each step, otherwise a solver failure will occur. The failure type is shown in the Log: T failures mean the timestep has needed to increase dramatically to find a solution. NL failures mean the solver has not been able to find a solution, which can cause artefacts in the model. These can typically can be solved with a smaller mesh or adjusting the model to avoid instabilities. The plot should highlight whether the surface or bulk concentrations are causing the failure, and therefore which part of the mesh should be refined.

Convergence Plot 3 will tell you the reciprocal of the timesteps being taken. The timestep should ideally increase exponentially, or flatline at a high value. A solver failure will cause the timestep to decrease - if this is caused by a sudden change in the system, this should increase again rapidly. If it remains low, the simulation is unlikely to work due to issues with the model.

To run multiple simulations sequentially, add an Parametric Sweep under Study 1. Any parameters you have defined in Parameters 1 under Global Definitions can be added with the plus icon. Separate values with a space. This will now automatically run until you disable or delete the Sweep.