Simulating the intestine - Rijksuniversiteit Groningenoffringa/Simulating the intestine.pdf · and...

41
Simulating the intestine Andr´ e Offringa October 25, 2007 Abstract This report considers all aspects of in silico experiments of microflora in the intestine, including new ways of optimising the visualisation of results with a three-dimensional ray-casting volume rendering technique, issues concerning solving the involved differential equations, the geometry and its boundary conditions, and the involved processes. The focus of this report is purely on the technical issues concerning such simulations. In previous projects, these simulations were performed on high performance computers in order to reach acceptable speed. With aid of an implementation of a simulator written for this project, it is shown that with the present computational power of ordinary low-end computers, high performance computing is no longer a strict necessity in this scientific area, as low-end computers perform the simulations in the order of ten seconds to a few hours. The ray-casting visualisation technique here presented is able to vi- sualise the results of the intestine, but yet unknown is how useful three- dimensional views of results are. The performance of the technique is in its current implementation just below acceptable for interactive viewing of the intestine, but is performing well enough for visualising results during simulations. With some more optimisations, the use of the GPU or with the help of improved computational power on low-end computers in the near future, interactive viewing might be a possibility. Preface This report is the result of my internship at the University of Groningen; a small research project on simulating the intestine, supervised by Dr Michael H.F. Wilkinson. It will contain all aspects of the research project, being the thesis of my research project, a discussion on the results and a reflection on what went well and what can be improved in future research projects. Most of the document is aimed at anyone who is interested in simulating or visualising the intestine. This document will also describe the design infor- mation on the written application. A short explanation on using the written application is provided as appendix. The report is aimed at the computational issues concerning such a simulation. The details of the modelling, parameter set- tings and the medical interpretation of simulation results will only be discussed superficially. 1

Transcript of Simulating the intestine - Rijksuniversiteit Groningenoffringa/Simulating the intestine.pdf · and...

Page 1: Simulating the intestine - Rijksuniversiteit Groningenoffringa/Simulating the intestine.pdf · and large intestine. The intestine is mod-elled as one straight, long tube, with varying

Simulating the intestine

Andre Offringa

October 25, 2007

Abstract

This report considers all aspects of in silico experiments of microflorain the intestine, including new ways of optimising the visualisation ofresults with a three-dimensional ray-casting volume rendering technique,issues concerning solving the involved differential equations, the geometryand its boundary conditions, and the involved processes.

The focus of this report is purely on the technical issues concerningsuch simulations. In previous projects, these simulations were performedon high performance computers in order to reach acceptable speed. Withaid of an implementation of a simulator written for this project, it isshown that with the present computational power of ordinary low-endcomputers, high performance computing is no longer a strict necessity inthis scientific area, as low-end computers perform the simulations in theorder of ten seconds to a few hours.

The ray-casting visualisation technique here presented is able to vi-sualise the results of the intestine, but yet unknown is how useful three-dimensional views of results are. The performance of the technique is inits current implementation just below acceptable for interactive viewing ofthe intestine, but is performing well enough for visualising results duringsimulations. With some more optimisations, the use of the GPU or withthe help of improved computational power on low-end computers in thenear future, interactive viewing might be a possibility.

Preface

This report is the result of my internship at the University of Groningen; asmall research project on simulating the intestine, supervised by Dr MichaelH.F. Wilkinson. It will contain all aspects of the research project, being thethesis of my research project, a discussion on the results and a reflection onwhat went well and what can be improved in future research projects.

Most of the document is aimed at anyone who is interested in simulatingor visualising the intestine. This document will also describe the design infor-mation on the written application. A short explanation on using the writtenapplication is provided as appendix. The report is aimed at the computationalissues concerning such a simulation. The details of the modelling, parameter set-tings and the medical interpretation of simulation results will only be discussedsuperficially.

1

Page 2: Simulating the intestine - Rijksuniversiteit Groningenoffringa/Simulating the intestine.pdf · and large intestine. The intestine is mod-elled as one straight, long tube, with varying

Contents

1 Introduction 31.1 Intestine simulations . . . . . . . . . . . . . . . . . . . . . . . . . 31.2 Previous work . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31.3 Research questions and goals . . . . . . . . . . . . . . . . . . . . 4

2 The simulation 52.1 Discretization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62.2 Geometry . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72.3 Differential Equation-solver . . . . . . . . . . . . . . . . . . . . . 8

3 The intestinal processes 103.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113.2 Transport . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113.3 Metabolism . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173.4 Discussion on overall results . . . . . . . . . . . . . . . . . . . . . 18

4 The visualisation 204.1 Problem description . . . . . . . . . . . . . . . . . . . . . . . . . 204.2 Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 204.3 Shooting rays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224.4 Optimisation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 244.5 Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 274.6 Conclusions and improvements . . . . . . . . . . . . . . . . . . . 30

5 The implementation 325.1 Architecture and design . . . . . . . . . . . . . . . . . . . . . . . 325.2 Libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 335.3 Evaluation of the implementation . . . . . . . . . . . . . . . . . . 35

6 Conclusions & future work 35

7 Acknowledgements 37

A Bibliography 38

B Mimicspp user manual 38B.1 Configuring the simulation . . . . . . . . . . . . . . . . . . . . . . 39B.2 Running the simulation . . . . . . . . . . . . . . . . . . . . . . . 40B.3 Gathering the results . . . . . . . . . . . . . . . . . . . . . . . . . 40

2

Page 3: Simulating the intestine - Rijksuniversiteit Groningenoffringa/Simulating the intestine.pdf · and large intestine. The intestine is mod-elled as one straight, long tube, with varying

1 Introduction

1.1 Intestine simulations

Many things are known about the digestive system of humans and animals fromexperience, for example; of many bacterium species it is known which symp-toms they are causing. However, the exact mechanisms by which the humanintestines work are not very well understood: it is often unclear why and underwhich circumstances bacterium species cause specific symptoms. Therefore, it isimportant to have a simulation environment in which hypothetical experimentscan take place, without having to perform real testing. This might help theunderstanding of the internals enormously and aid the design of new drugs suchas antibiotics.

My research concerns designing simulations of the growth and decay of bac-teria in the intestine on a computer. This is a complex field, requiring expertknowledge on the disciplines of computing science and microbial ecology. Thecomputing science part concerns discretizing the system appropriately, visual-ising the results and allowing experimenting with the parameters. The partwhere microbial ecology comes in is the actual determining of the parametersand interpreting and verifying the results.

1.2 Previous work

Little research has been done in the field of intestine simulation. The articlescomprising the largest effort of simulating the intestine have been authored byMichael Wilkinson, supervisor of this project. An overview can be found in [10],which provides details of the MIMICS project (“Model Intestinal Microflora InComputer Simulation”) and addresses the design of an intestine simulator. Oneof his conclusions is that modelling the intestine on a supercomputer (back then,in 2002) is possible and useful, and he expresses hope that tight cooperationwith medical research groups might provide in silico experiments in the future,complementing in vivo and in vitro experiments.

Simulations of the distribution and metabolism of substances in humanshave been performed by several research groups, for example by Barbara Juilletet al. [3], where the postprandial distribution and metabolism of nitrogen issuccessfully modelled by dividing the human body in thirteen compartments.Another fairly recent article by Peter de Jong et al. describes a three componentmodel of the entire gastrointestinal tract, that produces reasonable results whencompared with in vivo experiments[2]. Some simulations had a very specificpurpose, and these have been proven useful as well. A very specific applicationof an animal intestine simulation has been performed by J.C. Wood et al. in[11]. The authors describe how they simulate in silico, stochastically underwhich circumstances and for which duration the intestine of cattle can act asa reservoir of E. Coli O157. This is done by modelling the gut with threecompartments plus the environment stochastically.

Overall, some basic models have been created, but lots of research can still beperformed on micro-scale simulation of the intestine. The current results seempromising, and with the help of medical experts, simulations might providemedical experts with better understanding of the intestine.

3

Page 4: Simulating the intestine - Rijksuniversiteit Groningenoffringa/Simulating the intestine.pdf · and large intestine. The intestine is mod-elled as one straight, long tube, with varying

1.3 Research questions and goals

Now that a basic overview on previous work has been assembled, this sectionwill elaborate on what questions will be addressed in this brief research project.

1.3.1 Is high-performance required?

The primary aim of the project will be to answer the question whether high-performance is required to simulate the intestine with enough detail to provideuseful information. Michael Wilkinson has written a program in the computerlanguage Fortran that, when executed on 10 CPU’s on the J932 Cray super-computer (the “old” supercomputer of The University of Groningen, back in2002), simulates 15 days in 2 to 40 minutes [10]. The Cray supercomputer ranon 100 or 200 MHz, and has a maximal of 4 GB main memory. Though it isnot possible to linearly compare ten CPU’s on one speed and another CPU ona different speed, personal desktops have at the time of writing speeds of over 3GHz, and main memory sizes of 2 to 4 GB are not uncommon, and the speed ofnormal desktops still rapidly increase. Therefore; it seems feasible to port thesimulation towards a standard desktop.

It would be quite beneficial when it would not be necessary to have a super-computer in order to perform simulations:

• It is for a medical researcher easier to perform a simulation, as the overheadof having to know details about a supercomputer are no longer necessary.

• The task of designing and mainting such an application becomes less com-plex. A high-level programming language can be selected over Fortran andparallel computation is not a strict requirement anymore.

• You do not need (access to) a supercomputer.

I will try to answer this question by writing an implementation of the sim-ulator in the programming language C++ named Mimicspp, and I will try toreproduce some of the results that Michael Wilkinson has achieved, validatethem to the model (not medically) and measure the performance.

1.3.2 How can we visualise the intestine in three dimensions

A secondary goal of the project is to visualise the intestine in a three dimensionalperspective view. I will see if there are suitable methods to visualise an intestinein an easy and quickly interpretable way. The view should provide the operatorquickly with an impression of the processes in the simulation. Performance ofthe method should therefore also be adequate.

It is not required to draw the intestine in three dimensions to provide theoperator of the simulator with this information, as a two dimensional timevs. bacteria plot and/or a two dimensional axial location vs. bacteria plotas provided in [10] provide a well interpretable visualisation as well. Reasonswhy drawing the simulation three dimensional might be useful nevertheless, isbecause it might additionally help interpreting the results, and because threedimensional pictures and movies are good for several other things, such as PR.

I will try to answer this question by designing a tailored algorithm for draw-ing the intestine and its inhabitants and implementing a draft version.

4

Page 5: Simulating the intestine - Rijksuniversiteit Groningenoffringa/Simulating the intestine.pdf · and large intestine. The intestine is mod-elled as one straight, long tube, with varying

1.3.3 Other goals

The two previous questions form the basis of this project. However, one othergoal we will try to achieve in this project, is to turn the simulator, Mimicspp, intoa valuable tool which can be used by medical experts or biologists themselvesto understand the intestine. One thing that will aid this goal is to lose therequirement of a supercomputer as mentioned, yet there are more design goals:

• The simulator should be configurable by a clear graphical user interface,in which all important parameters can be set. A Mimicspp user shouldneed as few technical details as possible.

• The simulation should be parallelised as much as possible. Although sim-ulations of five minutes are acceptable, simulations performed in one tenthof this time are better, because testing several hypotheses becomes muchmore attractive. As there is a trend towards multiprocessor desktop com-puters, parallelising the simulation is still an issue.

• The simulator should allow incremental development to accommodate fastfeedback and, after my research project has been finished, allow (c.q. en-courage) additional enhancements by further development.

This concludes the introduction to my research project. Now that I haveexplained the basics on intestinal simulations and formed a goal for this project,the upcoming sections will focus on the how, why and what’s of the project: howthe simulator works, why I made certain decisions and what the achievementsare.

2 The simulation

Figure 1: Anatomy of the humanintestine (source: Wikipedia)

The program will simulate a model of the in-testine of the human, consisting of the smalland large intestine. The intestine is mod-elled as one straight, long tube, with varyingradii. Food, bacteria and other inhabitantsof the intestine will enter the intestine at theentrance or through the wall by some algo-rithm. Once inside, they will mix and flowthrough the small and large intestine. Whiledoing so, bacteria may react on each otherand on the availability of food and oxygenby metabolic processes. Eventually they willleave the intestine at the rectum.

In the field of biology it is commonto express formula in concentrations (e.g.mmol/l), instead of in amounts (e.g. in moleor in units). Therefore, the simulation willcalculate everything in concentrations.

Wilkinson has already made many of the important design decisions in con-structing a simulator, and has documented them in [9]. I will further elaborateon them, and focus on possible differences.

5

Page 6: Simulating the intestine - Rijksuniversiteit Groningenoffringa/Simulating the intestine.pdf · and large intestine. The intestine is mod-elled as one straight, long tube, with varying

2.1 Discretization

Since the inhabitants of the intestine are not homogeneously spread troughoutthe intestine, and since the growth and decay of inhabitants are dependent onthe presence of the other inhabitants at a certain location in the intestine, thegrowth rate is dependent on the location. Since the inflow of new substrateor bacteria might be time dependent (e.g. by eating at certain intervals), thegrowth rate is also dependent on the current time. Lastly, the growth rate isalso dependent on other bacteria and substrate in the neighbourhood.

The growth rate δsk/δt of an inhabitant k ∈ 1 . . .K at time t at a certainposition ~x is a function that is depending on time t, position ~x and density ofneighbouring substrate and oxygen ~s = {s1, . . . , sK}:

∂sk(t, ~x)∂t

= f(t, ~x,~s) (1)

Such a complex differential equation cannot be solved analytically, thus thesystem has to be discretized. Wilkinson has chosen to discretize spatially andtemporally, and I will do so as well in Mimicspp. Discretizing space is required,as not doing so would require to remember the position of each bacterium (inthe order of several mmol/litre or 1020 bacteria/litre). Discretizing time is alsorequired, as the differential equation still cannot be expressed otherwise.

2.1.1 Spatial discretization

Still left is the choice of how to spatially discretize the system, since variousoptions are available. Wilkinson discretizes the intestine in axial and radialdirection (left picture of figure 2), which has some benefits:

• Our modelled geometry, the tube with varying radii, is cylindrically sym-metric. Since no effect in the model breaks the cylindrically symmetry(effects such as gravity, bending or asymmetric movement of the modelledtube, differing flow speeds for upper and lower part of the intestine andasymmetric inflow), concentrations will remain cylindrical symmetric. Ifcompartments were to be used that split the intestine to account for asym-metry (as in the second and third image of figure 2), the system will nothold an increased detail in information, yet become more complex.

• The size of the compartments can be chosen in such a way that all com-partments at a specific axial position have the same volume. This is alsoan idea of Wilkinson, and allows to add concentrations in radial directionwithout having to account for the volume, making some of the calculationsless complex. Additionally, near the wall, the most “interesting” thingshappen; flow speed is quadratically decreasing towards the wall and newbacteria and oxygen flow in through the wall. Therefore it makes senseto increase the resolution when we are closer towards the wall, but this isonly intuitively: whether the wall really requires more detail is unsure.

• A simple 2D visualisation can be plotted by just drawing the two dimen-sional array of values. This does not account for varying radii and changingradial resolution, but gives some quick overview on the simulation and iseasy to plot.

6

Page 7: Simulating the intestine - Rijksuniversiteit Groningenoffringa/Simulating the intestine.pdf · and large intestine. The intestine is mod-elled as one straight, long tube, with varying

Figure 2: Three different ways of constructing compartments: in axial andradial direction (left), in axial, radial and rotation direction (middle) or in thedirection of the axes (right).

2.1.2 Temporal discretization

The spatial discretization has now been applied in two directions to the systemas in (1). If we specify the radial compartment index with i ∈ 1 . . . N and theaxial compartment index with j ∈ 1 . . .M , the equation can be written in thefollowing form:

d[si,j,k]dt

= fi,j(t, [~s]) (2)

This is an ordinary differential equation (ODE). To discretize over time, it isrequired to integrate over relatively short timesteps of h = ∆t seconds. AnyODE-solver will do, such as an Euler method solver or a Runge Kutta-4 methodsolver. Wilkinson suggests in [9] that the system is rather stiff, and as such thesystem would require a very small time step to give accurate results, whichmight put some constraints on the differential equation solver. I will elaborateon this in §2.3.

2.2 Geometry

The model of the geometry of the intestine will be a straight tube that variesin radii. The intestine is considered to have a total length of about 8 meters.The large intestine has a larger diameter, yet is shorter compared to the smallintestine; the large intestine is about 1.5 meters, and thus the small intestine isabout 6.5 meters long [4]. I had trouble with finding scientific support for thediameter of the intestine, but encyclopedia and sites on the Internet 1 reportthat the small intestine is about 25 to 35 millimetres in diameter, while thelarge intestine is 60 to 65 millimetre in diameter, so this is assumed. Anotherparameter of the geometry is the steepness of the wall of the large intestine.The diameter of the intestine approximately doubles between small and largeintestine, but it is not exactly known how quickly the radius increases. It istherefore by estimation assumed that the wall increases over one fourth of thelarge intestine (38 cm) towards his maximum diameter, keeps his maximumdiameter for one half of the large intestine, and then decreases towards its finalsize near the rectum in the last fourth part of the intestine. The rectum isassumed to be the same diameter as the small intestine.

1http://www.innvista.com/health/anatomy/intestin.htm

7

Page 8: Simulating the intestine - Rijksuniversiteit Groningenoffringa/Simulating the intestine.pdf · and large intestine. The intestine is mod-elled as one straight, long tube, with varying

Wilkinson also uses a cecal sack-like structure at the beginning of the largeintestine, which is a more realistic model of the intestine. This has been ignoredfor now but can be added to the model in a later stadium.

To get an idea of the geometry (and especially the ratio between length anddiameter), figure 3 shows a scaled version of an intestine with these parameters.

Figure 3: Wrapped around and scaled intestine: the gray part is the smallintestine, the white part is the large intestine

In a later stadium, these settings should be changeable with the user in-terface, however in the current version of Mimicspp it can only be changed byrecompiling the system. For testing purposes, the user interface does alreadyallow changing the geometry in an ordinary straight tube.

Each compartment is cone-shaped. The volume of compartments at the sameaxial position is the same, and the volume and radial area of a compartmentis therefore respectively the volume of a cone the size of the intestine at thisaxial position divided by the number of compartments, and the area of a discwith a diameter of the intestine at the axial position divided by the number ofcompartments.

2.3 Differential Equation-solver

The differential equation-solver is the heart of the simulation system, and manydifferent choices can be made regarding it. A customised ordinary differentialequation solver has been written instead of using one that is ready off the shelf.This has the benefit that the algorithm can be customised, that custom data-structures can be used, and that there is no performance loss in the interface.Performance might not be a proper argument for this choice though, as it mightbe expected that standard libraries have been stronger optimised and use morecomplex algorithms.

Wilkinson has separate solvers for the different processes: one for diffusion,one for laminar flow and one for metabolism, which are executed one after theother. This was done with parallelisation in mind. I have put everything inthe same solver. This does not allow the processes to be optimised for eachprocess individually, but the entire system profits of optimising and improvingthe solver. Moreover, it is less complex and has less chance of generating sideeffects.

The ODE-solver requires the initial values [~s]t0,i,j , which will be discussedin §2.3.3, and it requires the concentration change function f(t, ~s) = d[~si,j,k]/dt.This function will be evaluated at different times for each compartment Ci,j andfor each inhabitant k. The function is the sum of the change functions of theprocesses (laminar flow, diffusion, metabolism) for a particular compartmentand inhabitant. The concentration then can be approximated on the spatialgrid (i,j) and temporal grid t0 . . . tn by one of the default ODE solver methods,such as the first order Euler method:

8

Page 9: Simulating the intestine - Rijksuniversiteit Groningenoffringa/Simulating the intestine.pdf · and large intestine. The intestine is mod-elled as one straight, long tube, with varying

[~s]tn+1,i,j = [~s]tn,i,j + hfi,j (tn, [~s]) +O(h2) (3)

Another used solver method is the fourth order Runge Kutta 4 method:

[~s]tn+1,i,j = [~s]tn,i,j +h

6(k1 + 2k2 + 2k3 + k4)[~s]tn,i,j +O(h5) (4)

wherek1 = fi,j (tn, [~s])

k2 = fi,j

(tn +

h

2, [~s] +

h

2k1

)k3 = fi,j

(tn +

h

2, [~s] +

h

2k2

)k4 = fi,j (tn + h, [~s] + hk3)

Runge Kutta 4 requires four evaluations of f , but will yield a total error of orderO(h4), as the local truncation error in each step is O(h5). The Runge Kutta 4method also has better stability properties. Therefore, it pays to perform theextra evaluations. The results of simulating with the Runge Kutta 4 with awell chosen stepsize h are very precise: for example, when we simulate the flowand diffusion of one inhabitant in an hermetically sealed tube, the first 5 digits(no more digits are visible in the simulator) of the total concentration remainsconstant, even for very long simulation (in the order of weeks).

2.3.1 Adaptive step size

Concentration

1.

2.

Figure 4: Crossingzero

One problem that arises is that a timestep which is toolarge might cause negative concentrations in the system.These negative values are substituted in the next calcula-tion, which results in undesired effects like bacteria grow-ing on negative food values or negatively growing bacteria.These can cause major errors in the simulation. To cir-cumvent this problem, Wilkinson uses an adaptive stepsize. He performs the following test:

[s] +d[s]dt

t < ε[s] (5)

This equation tests whether [s] would decrease with a fac-tor of ε or less in an Euler solver. When this test is posi-tive, as in figure 4, the timestep is chosen smaller. This test can be applied onvarious moments in the Runge Kutta method. At first I only used it to checkthe main result [~s]tn,i,j of the Runge Kutta 4 method ((4)):

[~s]tn,i,j +h

6(k1 + 2k2 + 2k3 + k4)[~s]tn,i,j < ε[~s]tn,i,j (6)

This however resulted still in inaccuracies caused by negative kn values. There-fore, I looked at every k value individually, and if one of them would signify adecrease with a factor of ε, the timestep is changed.

9

Page 10: Simulating the intestine - Rijksuniversiteit Groningenoffringa/Simulating the intestine.pdf · and large intestine. The intestine is mod-elled as one straight, long tube, with varying

The timestep is changed to the largest value that would not decrease morerapidly than ε. If the initial timestep is much too high, the new timestepis taken much too carefully, as an exponentially decreasing function decreasesmuch quicker over large timesteps (and thus decreases more easily with a factorof ε). To avoid this from happening, I allow the timestep to change only slowly.I also allow the timestep to increase when the new calculated timestep wouldallow this, yet only slowly. ε ≈ 1.0−3 seems to give reasonable results.

2.3.2 Solving the boundaries

In the case of transport processes, the change rate also dependends on the neigh-bours of a compartment. Each compartment has a maximum of four neighbours.There are different approaches of handling the boundaries of the system in thesolver. Wilkinson enlarges the entire grid axially and radially with two compart-ments, so that boundaries have ordinary neighbours and all calculations can beperformed in the same way. These special boundary-compartments, which haveno further meaning then helping the calculation, can be set to a suitable valuebefore each iteration to preserve the boundary conditions (see §3.2.3: Boundaryconditions). The method used is different; a special change function fi,j (t, [~s])was used for the boundaries that takes in account the fact that a compartmentmight not have all four neighbours. This seemed to be logical during design,as it would increase the flexibility of the transport, as the boundary transportequations can be defined with an arbitrary function instead of only definingthe boundary compartment with the same transport function that is used fornon-boundary compartments. It also does not require the memory for the extra2(n + m + 1) compartments, though this memory usage is so minor that it isnot an issue. The extra flexibility was indeed required to simulate the differentboundary conditions between laminar flow and diffusion, so in the end it was agood choice.

2.3.3 Initialisation

The initial values are expressed as [~s]t0,i,j and are the concentrations of inhabi-tants in compartment Ci,j at the start of the simulation t0. The simulator allowsseveral settings for the initial values, like homogeneous spread (or empty). Inthe future, it would be useful if the initial values could be read from file. Thiswould allow the simulation to continue where a previous simulation, in whichall inhabitants have been settled, left of. For testing purposes, I also added afeature that sets the initialisation to a block of high concentration and a blockof no concentration at all.

3 The intestinal processes

In this chapter we will describe the intestinal processes. These have been cat-egorised into the transport processes that move the inhabitants through theintestine, and the metabolic processes that make the inhabitants grow, decay,be eaten, etc. The upcoming section will give a short introduction on howprocesses work. After that, each process will be described individually.

10

Page 11: Simulating the intestine - Rijksuniversiteit Groningenoffringa/Simulating the intestine.pdf · and large intestine. The intestine is mod-elled as one straight, long tube, with varying

3.1 Introduction

A process is nothing more than a concentration-change function fi,j(t, ~s), asdescribed in §2.3. However, each process can have simulation specific parameterslike flow speed or decay rate, and can be associated with certain inhabitants.Processes that are influenced by there neighboring compartments (i.e. transportprocesses) need specific functions for the boundaries of the system.

Each process is defined by a class in the implementation with a fixed in-terface. Processes are optimised by allowing them to initialise theirselves justbefore the simulation starts, after all parameters have been set. That way, asmuch precalculation as possible can be done beforehand. One example of this isthe default metabolism process, which searches for an inhabitant named “food”and initialises a pointer towards this inhabitant during initialisation.

3.2 Transport

3.2.1 Laminar flow

0

2e-05

4e-05

6e-05

8e-05

0.0001

0.00012

0 1 2 3 4 5 6

Con

cent

ratio

n (m

mol

)

Position (m)

Start of laminar flow

ABC

0

2e-05

4e-05

6e-05

8e-05

0.0001

0.00012

0 1 2 3 4 5 6

Con

cent

ratio

n (m

mol

)

Position (m)

Mimicspp simulation

ABC

0

1e-06

2e-06

3e-06

4e-06

5e-06

6e-06

7e-06

8e-06

9e-06

1e-05

0 1 2 3 4 5 6

Am

ount

(u)

Position (m)

Mimicspp high resolution simulation

ABC

Figure 5: Results of applying laminar flow to three inhabitants at differentspeeds: the horizontal axis represents the position in the intestine, the verticalaxis the amount of inhabitants. C flows three times faster than A. First image:at the start, second: at low axial resolution, third: at high axial resolution.

The laminar flow process transports the substance from the entrance to theexit of the intestine. An incompressible fluid is simulated, which means thatfor each compartment, the volume of the inflowing fluid is equal to the outflowvolume. Therefore, the volumetric flow rate of successive compartments in axial

11

Page 12: Simulating the intestine - Rijksuniversiteit Groningenoffringa/Simulating the intestine.pdf · and large intestine. The intestine is mod-elled as one straight, long tube, with varying

direction is constant:∀i, j1, j2 : I(i, j1) = I(i, j2) (7)

Which implies that Itotal(i), the sum of flow through all radial compartmentsat a given radial index i, is constant for all i:

Itotal(i) =∑j

I(i, j) = Itotal (8)

This value can be used to parametrise the speed of the laminar flow at any axialposition j. Intuitively Itotal stands for “how much fluid flows into (or out of)the intestine each time unit”. If we would parametrise how much fluid flowsinto each compartment instead, the flow speed dependends on the number ofcompartments in radial direction, and this is not favourable.

If fluid in the centre of the intestine flows equally fast as fluid near the wallof the intestine, the volumetric flow speed through each compartment is givenby the following function:

I(i, j) = Itotalai,jai

(9)

Since we will model the compartments such that the compartments in radialdirection have the same volume, we can simplify this to:

I(i, j) =ItotalN

(10)

(where N is the number of compartments in radial direction)However, the fluid does not flow equally fast through each radial compartment;the fluid flows slower near the wall of the intestine. To accommodate for this,separate values for the volumetric flow rate of inner and outer compartments areset (respectively Iinner and Iouter), and the flow rate in the compartments be-tween the outer and inner is quadratically increasing between Iinner and Iouter.:

I(i, j) =(Iouter − Iinner) iN + Iinner

N(11)

Remember that the quadratic increase between the inner and outer compart-ments is eliminated, since the index i is already quadratically decreasing indirection of the wall, to keep the area constant.

The change in amount can be expressed in the flow rate given in (11) withthe following equation:

dxi,j,flow

dt= [~x]i,j−1

I(i, j − 1)Vi,j−1

− [~x]i,jI(i, j)Vi,j

= I(i, j)(

[~x]i,j−1

Vi,j−1− [~x]i,j

Vi,j

)= I(i, j) ([~s]i,j−1 − [~s]i,j)

d[s]i,j,flow

dt=

I(i, j)Vi,j

([~s]i,j−1 − [~s]i,j) (12)

Finally, (12) is the differential equation that can be used to simulate the laminarflow.

12

Page 13: Simulating the intestine - Rijksuniversiteit Groningenoffringa/Simulating the intestine.pdf · and large intestine. The intestine is mod-elled as one straight, long tube, with varying

Figure 5 shows the result of letting three inhabitants flow at different speeds.As Wilkinson has described in [9], this method of applying laminar flow yieldssome implicit diffusion, as is clearly visible in the second image of figure 5.If this is a problem, it can be solved by increasing the axial resolution, as isdone in the third image of figure 5 – however, at the penalty of greatly reducedperformance. Otherwise, the diffusion process described in the upcoming sectioncan be altered so that axially less diffusion takes place, to compensate for thisimplicit diffusion.

The boundary conditions for laminar flow are equal to the conditions ofdiffusion, and are described in §3.2.3.

As the exact speed of the fluids is often not known, it is for physicians easierto express the speed in the time that it takes to flow through the entire intestine.Equation (13) shows how to calculate the flow-through time tflow-through fromthe volumetric flow speed I.

tflow-through =I

Vtotal(13)

An odd consequence of the axial discretization is that bacteria entering acompartment are considered to be immediately homogeneously spread over thecompartment. In each timestep, some of the bacteria will enter the next com-partment. After N timesteps, where N is the axial resolution, the first bacteriawill reach the end of the intestine, no matter what flow speed is used. How-ever, the amount of bacteria that runs forward like this is incredibly small, andseems not to pose problems, not even when aggressive growth of bacteria is tobe simulated.

3.2.2 Diffusion

The diffusion process is the process that blends each inhabitant through the in-testine. The diffuse flow between two neighbouring compartments is dependendon the surface area of contact. The formula for the contribution of diffusion inthe system can be taken literally from Wilkinson’s technical report [9], equation2.5.4. Separated in axial and radial directions, these formula have the followingform:

fi,j,ax(t, ~s) =δ

lVi,j(Ai,j+1,ax ([~s]i,j+1 − [~s]i,j) +Ai,j,ax ([~s]i,j−1 − [~s]i,j)) (14)

fi,j,ra(t, ~s) =δ

V 2i,j

(A2i+1,j,ra ([~s]i+1,j − [~s]i,j) +A2

i,j,ra ([~s]i−1,j − [~s]i,j))

(15)

where

δ the diffusion coefficient, a number representing the diffusion rate

l the length of a compartment (equal for every compartments)

Vi,j the volume of compartment Ci,j

Ai,j,ax the axial area between compartment Ci,j and Ci,j−1.

Ai,j,ra the radial area between compartment Ci,j and Ci−1,j .

13

Page 14: Simulating the intestine - Rijksuniversiteit Groningenoffringa/Simulating the intestine.pdf · and large intestine. The intestine is mod-elled as one straight, long tube, with varying

It is rather difficult to see that this is correct and the total concentration remainsconstant. It can be easily shown however that the total amount xtotal of eachinhabitant remains constant when the boundaries are sealed. If we consider theaxial diffusion between two compartments, A and B, this can be shown withthe following calculation:

dxtotal ax

dt=

dxAdt

+dxBdt

= VAd[sA]dt

+ VBd[sB ]dt

= VAfA,ax + VBfB,ax

= VAδ

lVA(AB,ax ([~s]B − [~s]A) + 0) +

VBδ

lVB(0 +AB,ax ([~s]A − [~s]B))

= 0

Thus, the total amount of one inhabitant remains constant for any value of the

0

2e-05

4e-05

6e-05

8e-05

0.0001

0.00012

0 1 2 3 4 5 6

foodoxygen

bacterium

0

2e-05

4e-05

6e-05

8e-05

0.0001

0.00012

0 1 2 3 4 5 6

foodoxygen

bacterium

0

1e-05

2e-05

3e-05

4e-05

5e-05

6e-05

7e-05

8e-05

9e-05

0.0001

0 1 2 3 4 5 6

foodoxygen

bacterium

Figure 6: Results of applying diffusion to three inhabitants, which have beeninitialised differently. The horizontal axis is the position in the intestine, thevertical axis the amount of inhabitants. First image: at the start, second:diffusion after a short period, third: diffusion after a very long period.

parameters. This can be shown likewise for laminar flow or radial diffusion. Itis a useful check for determining whether the equations are correct when thetotal concentration does not behave as expected.

In figure 6, a test simulation is shown. The timestep that is required to calcu-late diffusion accurately is primary dependend on the number of compartments

14

Page 15: Simulating the intestine - Rijksuniversiteit Groningenoffringa/Simulating the intestine.pdf · and large intestine. The intestine is mod-elled as one straight, long tube, with varying

and the diffusion coefficient δ. From experience, the diffusion process requires atimestep that is about the same order as laminar flow in normal simulations foraxial transport. However, in contrast to laminar flow, diffusion also transportsthe inhabitants in radial direction, which is on a much higher spatial resolution:the ratio between width and length of the intestine is about a factor hundred.Therefore, to be able to perform a simulation with diffusion within reasonabletime, the radial spatial resolution should not be chosen too high: about five toten compartments seems to be okay. As diffusion occurs rather quickly in radialdirection, and thus the inhabitants are radially rather equally spread, a lowradial spatial resolution should not influence the accuracy too much. However,certain processes that have not been considered yet, might be active in or nearthe intestine wall, and this might result in requiring higher radial resolution.

6e-06

7e-06

8e-06

9e-06

1e-05

1.1e-05

1.2e-05

1.3e-05

1.4e-05

1.5e-05

1.6e-05

1.7e-05

0 1 2 3 4 5 6

Am

ount

Position

Mimicspp simulation

foodoxygen

bacterium

Figure 7: Results of applying diffusion with a timestep that is too large.

Although the simulation can adapt the timestep to prevent negative valuesfrom occurring, the simulation might still introduce instability. In figure 7,the results of a simulation are shown in which diffusion has been simulatedfor a long duration. Although no negative values have occurred, the simulationstarts to oscillate heavily, which clearly is not the right behaviour of the diffusionprocess. To work around this error, one can limit the timestep in Mimicspp oncesuch incorrect behaviour has been observed, or the timestep can be limited onforehand by observing the average estimate for the timestep of Mimicspp in ashort simulation and subsequently setting the limit well below this value.

A misleading property of the diffusion process is that if the concentrations areradially equivalent, as is the case in the test initialisation methods, no diffusionoccurs radially, and the requirement for the timestep is dominated by axialdiffusion. Once laminar flow is added, which breaks the equal concentrationsin radial direction because of differing inner and outer speeds, suddenly a muchsmaller timestep is required. The first time this occurred I miss-interpretedthis: I concluded that combining laminar flow and diffusion made the equationsincreasingly stiff, but this is an incorrect conclusion.

15

Page 16: Simulating the intestine - Rijksuniversiteit Groningenoffringa/Simulating the intestine.pdf · and large intestine. The intestine is mod-elled as one straight, long tube, with varying

3.2.3 Boundary conditions

The boundary conditions are the entrance, exit and wall conditions of the intes-tine. The boundary conditions might be different for each inhabitant, as certaininhabitants might diffuse through the wall and some might not be able to, somemight periodically enter the intestine and others continuously or not at all,etcetera. The boundary conditions have been separated in the axial boundaryconditions and the radial boundary conditions, which are respectively the con-ditions at the entrance and exit and the conditions at the wall of the intestine.The two transport processes use the same boundary conditions. Despite that itis technically possible for one inhabitant to have different boundary conditionsin the two processes, I do not think it makes sense, so I have not allowed it inMimicspp.

The following boundary conditions are useful:

• The easiest boundary condition is to diffuse/flow out the intestine throughthe wall, the entrance and the exit of the intestine. This can be achievedby leaving out the inflow component of the the normal, non-boundarytransport equations. Alternatively, the same transport equations can beused, and the “imaginary” compartments Cim = Ci,j : i ∈ {−1,M} ∨j ∈ {−1, N} can be initialised at a zero for this particular inhabitant.Another constant instead of zero can be used to have a constant amountof inhabitant concentration available at the boundaries at all times.

• A hermetic sealed condition can be achieved by having no inflow as wellas no outflow from boundary compartments towards imaginary compart-ments. To achieve this by initialising imaginary compartments, the imag-inary compartments for the laminar flow process have to be differentlyinitialised as for the diffusion process.

In the case of diffusion, the imaginary compartments have to be initialisedat the same value as their neighbouring boundary compartment, as nodiffusion takes place between compartments that already have the samevalue, see (14) and (15).

In the case of laminar flow, only the entrance and exit are important, asthe flow is only in axial direction. The inflow at the entrance Ci,0 can bemade hermetically sealed by leaving out the inflow term (which is the onlyterm) as in the case of the constant boundary conditions, and thus theimaginary cells have to be initialised at zero. The outflow is more compli-cated though, as the flow rate out of the intestine at Ci,N−1 is independentof the imaginary cells at the exit Ci,N , see (12). Therefore, the functionhas to be changed to allow inflow from Ci,N−2 only. Having a laminarflow with a hermetically sealed rectum is probably nonsense though, as allinhabitants will rapidly pile up in the last axial compartments. It is usefulfor testing the system though, as the total concentration can be checkedfor its constantness in a hermetically sealed system.

• A third boundary condition is a timed inflow: inflow at specific intervalsto simulate the behaviour of eating. This is especially useful to allow forthe axial boundaries at Ci,0 and Ci,N−1. The implementation is simple;it is equivalent to the constant boundary conditions, only the constant isreplaced with a time dependend function. As an interesting side note, this

16

Page 17: Simulating the intestine - Rijksuniversiteit Groningenoffringa/Simulating the intestine.pdf · and large intestine. The intestine is mod-elled as one straight, long tube, with varying

introduces the only process that is dependend on the current time in thesystem.

• Near the wall, food uptake takes place, which behaves unlike the aboveconditions. Wilkinson simulates this with Michaelis-Menten kinetics. Theextra concentration change near the boundary is expressed with the fol-lowing formula (also in [9], mentioned here for completeness)

fM,j,uptake(t, ~s) =2MR

(µmuc − λF

[~s]M,j

Kuptake + [~s]M,j

)(16)

where

µmuc is the rate of mucus production per unit of surface area

Kuptake is the half saturation food uptake concentration

λF is the maximum active food uptake rate

This process has not yet been implemented in Mimicspp. It can be im-plemented with a separate process, or diffusion can be altered so that theboundary at the intestinal wall uses (16). Wilkinson has used the secondmethod to perform the uptake, though the first method fits better intothe structure of Mimicspp, and will result in a more logically structuredimplementation. Therefore, if it were to be implemented, the first methodshould be used.

Currently, the entrance and exit conditions are related to each other andcan not be set up differently. This is a limitation of the implementation; inthe future it should be changed so that the entrance and exit conditions can bepicked separately.

Another yet unimplemented feature is default boundary conditions: theboundary conditions that apply to all inhabitants in the system, unless theboundary conditions of an inhabitant have specifically been changed from thedefault. Currently, all inhabitants have to be set to their boundary conditions,and if a change of the default boundary conditions would be required, all in-habitants with this boundary condition would have to be changed separately.

3.3 Metabolism

Metabolism is the process that causes the grow and decay of bacteria and causesfood and oxygen to be used and produced. Since each inhabitant has a partic-ular function, the concentration change function fi,j,k(t, ~s) is different for eachinhabitant k. The different formula are derived in [9], and are given by:

fi,j,bact(t, [~s]) = µbact[sbact] (17)

µbact =(µO2

[sO2 ]KR,O2 [sO2 ]

+ µan

)[sF ]

KF + [sF ]− κO2

[sO2 ]KT,O2 + [sO2 ]

− µbasal

fi,j,food(t, [~s]) = µfood[sbact] (18)

µfood = ακκO2

[sO2 ]KT,O2 + [sO2 ]

−(µO2

αO2

[sO2 ]KR,O2 + [sO2 ]

+µan

αan

)[sF ]

KF + [sF ]

17

Page 18: Simulating the intestine - Rijksuniversiteit Groningenoffringa/Simulating the intestine.pdf · and large intestine. The intestine is mod-elled as one straight, long tube, with varying

fi,j,oxygen(t, [~s]) = µoxygen[sbact] (19)

µoxygen = βµ,l[sO2 ]

KR,O2 + [sO2 ][sF ]

KF + [sF ]+ βκ

[sO2 ]KT,O2,k + [sO2 ]

0

5e+16

1e+17

1.5e+17

2e+17

2.5e+17

3e+17

3.5e+17

4e+17

4.5e+17

0 20000 40000 60000 80000 100000 120000 140000 160000 180000

Am

ount

(u)

Time (s)

Mimicspp simulation

foodoxygenaerobe

anaerobe

Figure 8: Results of applying metabolism to an aerobe and anaerobe bacteriumfor 50 hours.

The many constants in these formula, including estimates for the constants,can be found in [9]. The constants can be different for each bacterium, andeven for each combination of bacterium and food type. Currently, Mimicsppsupports setting each the constants associated with each bacterium, yet doesnot support differing constants associated with one bacterium for different typesof food.

It is not easy to set the constants to a configuration of a realistic simulation.The results of a simulation with one aerobe and one anaerobe bacterium isshown in figure 8. The configuration used in this simulation seems to approachreality, and with better approximations of the constants and better knowledgeon the micro-ecological result, one might mimic the intestine more closely. Thetime it takes to perform the simulation of figure 8 with resolutions of 100 axialand 10 radial compartments is in the order of one minute.

3.4 Discussion on overall results

Now that the three processes have been defined, they can be combined to sim-ulate the intestine. While the speed of the transport processes is in an isolatedsituation not so important, if we want to mimic the intestine correctly, they willnow have to match the conditions of the intestine. The laminar flow speed canbe determined by the flow-through time, but the diffusion speed can not. Thediffusion process however can be considered as moving the fluid slightly slower

18

Page 19: Simulating the intestine - Rijksuniversiteit Groningenoffringa/Simulating the intestine.pdf · and large intestine. The intestine is mod-elled as one straight, long tube, with varying

then the laminar flow process. With this knowledge, the diffusion speed was ap-proximated by looking at the diffusion of one fluid and subsequently adjustingthe speed until it looked reasonable.

0

1e+17

2e+17

3e+17

4e+17

5e+17

6e+17

7e+17

8e+17

0 20000 40000 60000 80000 100000 120000 140000 160000 180000 200000

Am

ount

(u)

Time (s)

Mimicspp simulation

foodoxygenaerobe

anaerobe

0

5e+15

1e+16

1.5e+16

2e+16

2.5e+16

0 1 2 3 4 5 6 7 8

Am

ount

(u)

Position (m)

Mimicspp simulation

foodoxygenaerobe

anaerobe

Figure 9: Combining all three processes.

The resulting figures of combining all three together to simulate anaerobeand aerobe bacteria are shown in figure 9. Food entered the intestine every threehours, which can be seen by the saw-tooth line in the left of figure 9, showingthe amount of each inhabitant over time.

The two bacteria have in this simulation more chance of growing in the largeintestine, as can be seen in the right figure. Since oxygen was allowed to diffusethrough the wall into the intestine in this simulation, the aerobe bacteriumgrow much faster near the wall (see figure 10). The bacteria find their ’favouritespot’ in the intestine very quickly, and their concentrations seems stable aftera couple of hours. Some estimates of the parameters were used from [10], butthese are still very rough. Therefore, it is at this point hard to make conclusionsin the field of micro-biology, but it has been shown that such simulations mightprovide useful information.

The performance of the simulation when all three process are combined isobviously at least three times slower. However, because of the situation growingmore complex, it happens more often that the concentration in at least onecompartment might cross zero if the time step is kept constant. Therefore,when using adaptive time steps, the system chooses smaller time steps, whichdecreases the performance further. The performance is still acceptable though,with simulations such as in figure 9 with a still rather high resolution of 7× 60compartments taking a few minutes. It is useful to decrease the resolutionbefore running simulations that take a considerable amount of time, to checkthe configuration.

It is useful to have an estimate of the time that a simulation is going to take,so that for example a simulation can exactly be performed during the night. It ishowever hard to make such an estimate, as it is dependend on many things, forexample, doubling one of the resolutions lowers the performance because of theincreased number of compartments that have to be calculated, but also lowersthe performance because the time step has to be smaller. Depending on thesituation, this might on overall decrease the performance with a factor between2 to 8. The reported estimated duration by Mimicspp during simulating seemsto be useful to determine the time it is going to take as well.

19

Page 20: Simulating the intestine - Rijksuniversiteit Groningenoffringa/Simulating the intestine.pdf · and large intestine. The intestine is mod-elled as one straight, long tube, with varying

Figure 10: Aerobe bacteria grow well near the wall, because of oxygen diffusingin.

A still unimplemented feature is the ability to apply a process on a specif-ically chosen set of bacteria and substance. The Metabolism currently stillrequires a substance named “food” and one named “oxygen”. If this would bemade more flexible, more substances could be added. Implementing this shouldnot pose to many problems.

4 The visualisation

To improve the understandability and interpretation of the simulation, the pos-sibilities of visualising the results of the simulator in a three-dimensional viewhave been examined. In this chapter, several possible visualisations of the intes-tine and the considerations will be discussed. After this, the design and resultsof the implemented visualisation method will be discussed.

4.1 Problem description

The goal in the beginning of the project was to add a three-dimensional visu-alisation of the intestine to the simulator, that allows interpreting the resultsand that makes a fancy impression of the simulator; see the research questionin §1.3.2. As there are several ways of creating a three-dimensional view of amodel, many considerations had to be taken in account.

The most notable consideration was the fact that the model of the intestineis a rather unusual geometry to visualise in three dimensions: all compartmentsare round, the visualisation should allow seeing compartments underneath othercompartments in some way and there might be a huge number of compartments.It will be an additional benefit if the drawing could be performed in real time ornear real time, so results can be visualised immediately, and interactive viewingis possible.

4.2 Options

As one of the goals was to draw the intestine in real time, a rather trivial solu-tion would be to draw the intestine by converting the round figures to polygonsand using hardware rendering with for example OpenGL to do the drawing. Ifthe compartments would be drawn as polygons of 16 vertices that are trans-parent, with the typical setup of 10 compartments in radial direction and 100

20

Page 21: Simulating the intestine - Rijksuniversiteit Groningenoffringa/Simulating the intestine.pdf · and large intestine. The intestine is mod-elled as one straight, long tube, with varying

compartments in axial direction, the renderer would have to draw 16.000 prim-itives. While a normal scene with this amount of primitives is not a problemfor modern graphics cards (modern graphics cards report their primitives-per-second rate in tens of millions), having to draw so many transparent primitivesmight be a problem. However, I am not sure what the impact of transparencyis on the performance. The fact that this is not a typical scene, in which partof the scene is hidden by other surfaces, might be problematic.

Another visualisation method that might be appropriate is maximum inten-sity projection volume rendering. This technique is frequently used to visualisemedical data such as computerised tomography (CT) and magnetic resonanceimaging (MRI) scans. In [5], several ways of perform MIP are discussed andoptimisations are presented to make it fast enough on low-end hardware andimprovement are presented to make the results better interpretable. This ref-erenced thesis is written in 2001. The thesis mentions that a performance ofa couple of frames per second is realised on low resolutions, so using todayshardware this might have been improved towards a reasonable framerate witha reasonable resolution. MIP is mostly applied on voxel-models and I have notfound much research in the field of applying MIP to compartmented geometries,as will be the case in the intestine simulation. Whether MIP visualisations areuseful for interpretation of the growth of bacteria in the intestine is not certain;conventional method only use position/concentration-plots, cross-cuts and par-allel side views. The easiest method of implementing MIP is by shooting foreach pixel a ray through the geometry and find the compartment with the high-est value: the pixel will receive the colour that is related to this value accordingto some mapping. A drawback of MIP is the fact that depth and occlusioninformation is lost, though occlusion information is probably not useful anyway.One advantage, comparing to polygon rendering, is that the round structurecan be maintained and will be truly round in the image. Another advantageis that it is very easy to parallelise the rendering of MIP, as each pixel can becalculated independently of the others. Another visualization method that ismuch like MIP, is X-ray rendering. In this method, rays are shot through thevolume, but rather than finding the maximum intensity, the volume intersectedby the ray is integrated.

The following aspects have been considered:

• Complexity of implementation: it should be implementable within reason-able time, as this project is rather short, and the visualisation is only oneaspect of my research.

• Personal interest and challenge: I wanted to try something new which wasnot trivial.

• Usefulness: this implies several other constraints, such as a reasonableperformance and an interpretable result.

The chosen visualisation method in Mimicspp is a kind of combination ofX-ray volume rendering and ray tracing: for each pixel, a ray was shot throughthe camera towards the geometry (see figure 11). Once the ray hits the wall ofthe tube, the illumination of a directional light source at this position on thewall is calculated and added to the colour of this pixel, along with a colour thatis calculated by extending the ray through the tube and integrating along the

21

Page 22: Simulating the intestine - Rijksuniversiteit Groningenoffringa/Simulating the intestine.pdf · and large intestine. The intestine is mod-elled as one straight, long tube, with varying

Figure 11: This image shows a ray that is shot through the projection planetowards the geometry (left), passing compartments axially (middle) and radially(right).

ray, resulting in a value that represents the colour produced by the fluid in theintestine. As the contents of the tube are discretized by compartments, we donot really have to integrate, but rather sum the value in each compartment,weighted by the total length of the cut through the compartments.

4.3 Shooting rays

To calculate the correct compartment that we pass while shooting rays, we needto know where the ray hits the wall of the intestine, which is modelled as severalcones. To calculate this, we need the intersection between a three-dimensionalline and a cone. As a cone is a quadratic surface (also called quadric surface)of the form of (20) [8], suitable methods to do this exist, as the generic solutionof the intersection between any quadratic surface and a line is known.

x21

a2+x2

2

b2− x2

3

c2= 0 (20)

Using the generic solution for all quadratic surfaces might however be not opti-mal, and in the hope to optimise the formula for the specific Mimicspp situation,specifically calculations have been performed. First of all, an intestine cone iscircular and not elliptic, so a2 = b2. The axis of the cones have been put on thex-axis, and so the camera is rotated instead of the scene. This avoids havingto deal with degenerate cones (that have been rotated) and allows to map thethree axes (x1, x2, x3) directly to the zero-axes (y, z, x) of the scene. This doesimply that the camera rays have to be rotated, but this is no problem. Next,(20) is transformed into (21) so the parameters of the cone are expressed withd and e, which respectively represent the width of the cone at x = 0 and thesteepness of the cone. For example, e = 0 would represent a cylinder with di-ameter d, whereas e = −d would represent a cone that intersects at x = 1 andhas a diameter of d at x = 0.

y2 + z2 = (d+ ex)2 (21)

22

Page 23: Simulating the intestine - Rijksuniversiteit Groningenoffringa/Simulating the intestine.pdf · and large intestine. The intestine is mod-elled as one straight, long tube, with varying

The points on a line with startpoint (x0, y0, z0) and direction (al, bl, cl) can begiven by:

x = x0 + alλy = y0 + blλz = z0 + clλ

(22)

We can now solve the intersection by replacing x, y and z in (21) with (22):

(y0 + blλ)2 + (z0 + clλ)2 = (d+ e(x0 + alλ))2 (23)

Solving for λ would yield the points on the line that intersect. This is not soeasy by hand, but computer programs like Maxima2 can solve these equationseasily:

solve ((y0 + b*tl)^2 + (z0 + c*tl)^2 =(d + e*(a*tl + x0))^2, tl));

Which, after manually extracting s and D (which is an error prone task!),returns this result:

s =(a2e2 − b2

)z0

2 +(2bcy0 − 2ace2x0 − 2acde

)z0 + (24)(

a2e2 − c2)y0

2 +(−2abe2x0 − 2abde

)y0 +(

c2 + b2)e2x0

2 +(2c2 + 2b2

)dex0 +

(c2 + b2

)d2

D = a2e2 − c2 − b2 (25)

λ1 =−√s+ cz0 + by0 − ae2x0 − ade

D(26)

λ2 =√s+ cz0 + by0 − ae2x0 − ade

D(27)

Substituting λ1 and λ2 back in (22) yield the two coordinates we are looking for.Equations (26) and (27) will not have a real solution if either D = 0 or s < 0.These two situations correspond with respectively the situation in which theline lies on the surface of the cone, and thus has infinitely many intersections,and the situation in which the line does not intersect the cone at all. λ1 and λ2

are equal if s = 0, which corresponds with the situation in which the line onlytouches the surface of the cone. The easiest way of handling these situations isby returning no intersections at all, in which case we will draw the background.

The geometry of the intestine is the concatenation of several sections, whereeach section is a cone (or cylinder). When we shoot a ray towards the geometry,the intersection with each of the sections of the intestine have to be calculated.Once the intersections have been found with the generic cone surfaces, a checkshould be performed to see if the intersection is really a part of the section, asgeneric cones extend infinitely. After filtering of the incorrect intersections hasbeen performed, the intersections can be sorted on distance to find the actualfirst intersection of the ray with the wall and the last intersection. To be ableto perform some optimisations, the renderer consideres everything between thenearest and farthest intersection as the inside of the intestine. This is actuallynot the case if any of the sections have steep edges that are occluded, as infigure 12. Mimicspp solves this problem by disallowing views in which thishappens.

2Maxima is an open source program with some of the functionality of Mathematica

23

Page 24: Simulating the intestine - Rijksuniversiteit Groningenoffringa/Simulating the intestine.pdf · and large intestine. The intestine is mod-elled as one straight, long tube, with varying

Figure 12: The situation that can occur when steep cones are present or whenlooking from the site or nearby

4.4 Optimisation

4.4.1 Calculating intersections

Figure 13: Example rays that illustrate the difficulty of interpolating the in-ner intersections correctly. Left: complication because of using cones, right:complication because of circular shape

The square root operation is an expensive operation in terms of performance,so this makes finding the intersection of a line and a cone a rather expensive op-eration. The number of times these intersections are calculated should thereforebe kept as low as possible. However, to calculate the effect of any compartment– including the compartments that are enclosed by other compartments – onthe total colour, the distance that the ray travels through the compartment hasto be known. A trivial solution for this is to calculate the intersection of the raywith the radial border of all compartments, not only the outmost wall. Thisis what a standard raytracer would do if the compartments would be definedindividually. This however degrades the performance almost linearly with thenumber of radial compartments, and this is undesirable.

To solve this, only the outmost intersections can be calculated and the innerintersections are interpolated from these two values. This however is not atrivial task. Figure 13 shows two effects that are responsible for the difficultyof interpolating: the interpolation should accommodate for the steepness of thecones (left) and accommodate for the fact that all compartments are round(right) and not all compartments are likely to be intersected. This in parallelwith the fact that different axial sections (differently shaped cones) might beintersected by the ray, as is seen in the rightmost ray of the left example offigure 13), makes it a very complicated task. If done precisely, this might proveto require even more calculation time.

24

Page 25: Simulating the intestine - Rijksuniversiteit Groningenoffringa/Simulating the intestine.pdf · and large intestine. The intestine is mod-elled as one straight, long tube, with varying

Figure 14: Calculation ofdeepest compartment in-tersected

The solution that has been chosen, is to identifythe “deepest” compartment that is intersected, bycalculating τ2, the square of the distance betweenthe ray and the axis of the intestine. This axis isequal to the x-axis. Next, τ2 is compared with thesquare of the radius of the compartments at thatpoint (see figure 14). Note that finding the distancebetween a three-dimensional line and the x axis isequivalent to finding the distance between a two-dimensional line and a point. This altogether canbe performed rather quickly. Now that is knownwhich compartments have been intersected, the in-tersections are subsequently calculated by linear in-terpolation. This introduces a slight error, thatincreases when looking towards the top or bottomwall of the intestine and increases when we are look-ing more sidewards towards the side of a steep cone.To improve the performance once more, τ2 is ap-proximated by the point exactly in the middle ofthe two intersections.

When doing ordinary maximum intensity projection through voxels, precal-culated optimisation techniques that eliminate non-contributing compartmentsare available that reach speeds that allow interactivity[6]. Although similartechniques might be applicable on the cylindric geometry as well, I have notlooked into compartment elimination optimisation techniques, as there was notenough time in this project to do so.

To correctly calculate all intersected compartments, rays should also betested for hitting the axial boundaries of the compartments. In Mimicspp, thisis skipped. Only each time a compartment is (radially) entered by a ray, it testsin which axial compartment it is. This does barely effect views from the front,but does raise artifacts in side views: certain compartments may be missed byrays, especially when the axial compartment resolution is much higher then theradial resolution. The higher the radial resolution, the less the artifacts arevisible.

Note that if we were to perform maximum intensity projection instead of X-ray rendering, we only need to know which compartments we cross. Therefore,the deepest compartment can be calculated as described and the interpolationcan be left out, resulting in a rather tailored and efficient maximum intensityprojection method.

4.4.2 Precalculation of concentrations

The geometry and its discretization have been chosen to suite the simulation,but are not ideal for the visualisation. By calculating several things on forehandwe can speed up the visualisation:

• Make radii equal: during the simulation, the compartment density nearthe wall is higher, because all compartments have the same volume. Thisis useful for the simulation, but rather inconvenient for visualisation. Ifwe copy and interpolate the concentration values in the compartments

25

Page 26: Simulating the intestine - Rijksuniversiteit Groningenoffringa/Simulating the intestine.pdf · and large intestine. The intestine is mod-elled as one straight, long tube, with varying

Figure 15: Example interpolation to show typical errors made (neglecting thecone-shape error)

into a new geometry in which the compartments have equal radii, thedistance the rays passes through the compartments does not have to becalculated, as all compartments are of equal size. This saves multiplyingeach concentration with its weight for each ray, and therefore drasticallyimproves the performance. The time needed to recalculate the geometry isnegligible, and the total performance gain of this method is approximately200%. The method is however not suitable when fine detail near the wallis important.

• Lower the resolution: As in the previous optimisation, we can feed thevisualisation an adapted geometry, this time with a lower resolution. Theperformance of the visualisation is depending on the radial resolution only,because of the way the compartments are summed, so lowering the radialresolution is the only effective method. Values of 5 to 10 compartmentsradially seem to result in nice visualisations. It is not likely that simulatingthe intestine will require more then 10 compartments though, so the useof this optimisation is rather restricted.

• Logarithmic values: if logarithmic scaling or some other scaling is desired,this can also be applied beforehand.

4.4.3 Precalculation of camera dependend values

For certain applications, the camera position will not change. This might in-clude for example while creating a movie of the simulation or for observing thesimulation realtime without (camera) interactivity. In these cases, the visuali-sation can be further optimised by calculating certain camera-dependend valueson forehand:

• For each pixel, the intersections with the outer wall of the intestine canbe precalculated. This avoids having to calculate the large equation, in-cluding the square root, for each pixel. This approximately doubles theperformance without loss in quality, at the expensive of requiring morememory. Though, this performance benefit is only available if the cameraposition does not change, and is therefore not suitable for interactivelyexploring the intestine.

26

Page 27: Simulating the intestine - Rijksuniversiteit Groningenoffringa/Simulating the intestine.pdf · and large intestine. The intestine is mod-elled as one straight, long tube, with varying

If the intersections are stored in 64 bit doubles, and if the normals of thecone at that point are also stored, the total amount of extra required mem-ory for an image of 640×480 would be 4×640×480× 64

8 ≈ 10 megabytes,which is not a problem.

• Instead of precalculating just the two outer intersections, we can alsoprecalculate all intersections, thus including the intersections with innercompartments. This simplifies the final rendering; each pixel contains alist of visible compartments and a factor describing its effect on the colourof the pixel. By doing so, we can actually correct the error that occurredby optimising the intersections as described in §4.4.1. Instead of interpo-lating the intersections linearly, we can find the real intersections for eachcompartment on forehand. This “optimisation” will however make thevisualisation slower, as we need to perform the weight-multiplication foreach ray going through a compartment. Also, the total amount of requiredmemory grows with the amount of radial compartments. The benefit isthat the final visualisation contains no artifacts that are caused by theoptimisations. I have not performed this method in my visualisation.

4.5 Results

In Mimicspp, the simulation can be constantly visualised with the method asdescribed in the previous sections. In figure 16 the visualisation of an axialdiffusion simulation can be found for both a one-segment tube (left) and thefour-segment model of the intestine (right). The camera is placed orthogonallyon the model in this visualisation, which results in a rather boring image. In thecase of a tube, the three-dimensional projection is not really an improvementover a two dimensional projection. In the case of the intestine, the geometry ismore easily recognisable though.

Figure 16: Visualisation of diffusion at low axial resolution (M = 25)

The sharp axial edges of the compartments are rather ugly. In a two-dimensional cut or a three-dimensional polygon-rendered this is easily inter-polated. In the case of the three-dimensional ray-cast method, this can besolved by increasing the axial resolution. The whole simulation can be set toan higher axial resolution, as is done in figure 17, or the compartments can beaxially resampled to a higher resolution on forehand of the visualisation. Theperformance of the visualisation method is independent of the axial resolution,so this will not influence performance.

In figure 18, a laminar flow simulation is visualised at low resolution (left)and high resolution (right). The fluid in the centre flows faster then fluid near

27

Page 28: Simulating the intestine - Rijksuniversiteit Groningenoffringa/Simulating the intestine.pdf · and large intestine. The intestine is mod-elled as one straight, long tube, with varying

Figure 17: Visualisation of diffusion at higher axial resolution (M = 250)

the wall. Here, the camera has been rotated slightly, to improve the three-dimensional impression. No “caps” have been rendered, wherefore we can nowlook inside the intestine at the exit. This can be solved by also calculatingthe intersection between the rays and the entrance and exit caps, which is anordinary disk which surface satisfies x = xcap and can be solved quite quickly. Ihave not implemented this because of the limited available time for the project.

Figure 18: Visualisation of laminar flow, slightly rotated

Different fluids can be rendered in one image by using different colours, asin figure 19.

Figure 19: Visualisation of two fluids

In certain views, some artifacts caused by the optimisations can be found.When two neighbouring compartments have highly differing concentrations, andthe user looks slightly from the side on these compartments, some mixing takesplace near the border. This can be seen in figure 20. When looking non-orthogonally towards steep cones, and two compartments again have highlydiffering concentrations, less subtle artifacts arise. This can be seen in figure 21.These artifacts can be solved by increasing radial resolution. This howeverdecreases performance.

28

Page 29: Simulating the intestine - Rijksuniversiteit Groningenoffringa/Simulating the intestine.pdf · and large intestine. The intestine is mod-elled as one straight, long tube, with varying

Figure 20: Artifacts near entrance caused by high contrast between compart-ments

Figure 21: Artifacts near exit caused by high contrast between compartmentsand the cone optimisation

29

Page 30: Simulating the intestine - Rijksuniversiteit Groningenoffringa/Simulating the intestine.pdf · and large intestine. The intestine is mod-elled as one straight, long tube, with varying

Table 1 lists the performance of the visualisation method under various con-ditions. From this table it is clear that the performance is barely dependend onthe axial resolution: the radial resolution is the dominating parameter. Visualis-ing a more complex geometry such as the intestine is mostly slower then a simplegeometry such as a tube, since the intestine is composed of four cone-shaped seg-ments. The performance of precalculated camera-dependend variables3 seemshigher for the more complex intestine model, but this is only because fewer rayshit the geometry, because the intestine has on average a smaller diameter (seefigure 16). Calculating the intersections on forehand with the outer wall resultsin approximately a 4× performance increase. The effect of the precalculation ishigher with multiple cone sections, as with the intestine model.

Table 1: Performance in various situations. All calculations were performed ona 1 GHz laptop.

Description Time (s) fpsTube with one compartment 0.175 5.7Intestine with one compartment 0.326 3.11 rad × 10 ax tube 0.175 5.71 rad × 1000 ax tube 0.177 5.610 rad × 1 ax tube 0.239 4.21000 rad × 1 ax tube 9.64 0.110 rad × 10 ax tube 0.242 4.11 rad × 1 ax precalced tube 0.081 12.31 rad × 10 ax precalced tube 0.081 12.31 rad × 1000 ax precalced tube 0.081 12.310 rad × 1 ax precalced tube 0.143 7.01000 rad × 1 ax precalced tube 10.7 0.110 rad × 10 ax precalced tube 0.143 7.01 rad × 10 ax intestine 0.321 3.11 rad × 1000 ax intestine 0.320 3.110 rad × 1 ax intestine 0.344 2.91000 rad × 1 ax intestine 3.517 0.210 rad × 10 ax intestine 0.349 2.91 rad × 1 ax precalced intestine 0.068 14.61 rad × 10 ax precalced intestine 0.068 14.61 rad × 1000 ax precalced intestine 0.069 14.610 rad × 1 ax precalced intestine 0.096 10.41000 rad × 1 ax precalced intestine 3.842 0.2610 rad × 10 ax precalced intestine 0.096 10.4

4.6 Conclusions and improvements

An implementation of a visualisation technique was successfully finished in thisproject, but not all aspects are satisfactory. The performance is not yet highenough for interactive viewing, such as rotating the camera around the intestine,

3the phrase precalced in table 1 denotes that camera-dependend values have been precal-culated as described in §4.4.3

30

Page 31: Simulating the intestine - Rijksuniversiteit Groningenoffringa/Simulating the intestine.pdf · and large intestine. The intestine is mod-elled as one straight, long tube, with varying

on low-end computers, with only a couple of frames per second. The visuali-sation does allow for viewing the concentrations of the intestine in an intuitiveway during simulation, for example to create a movie, to interpret the resultsor to evaluate the processes during simulation. The added benefit of a three-dimensional view over a straightforward two dimensional cut of the intestineseems to be not too much – especially when interactive viewing is not possible,but real life simulations would have to be performed in order to decide on this,instead of the rather simple simulations that were performed here.

The added value of performing the ray-cast method to visualise the intestineis also hard to estimate, as no other three-dimensional methods have been used,such as “ordinary” polygon drawing. However, with this technique, the edgesare very sharp and truly round, which results in pictures such as figure 19with very smooth edges and colours, which is a big benefit in a geometry thatconsists only of round shapes. If voxel-shaped compartments were used, thisbenefit would also be lost. Polygon based drawing however might also be aninteresting research to look into, if the current visualisations would show to beuseful.

The dominating factor in the visualisation performance is adding the con-centrations of compartments along the ray for each pixel. Therefore, to allowfurther optimisation, techniques that eliminate compartments or different data-structures would have to be found. However, it will only take a minor amountof time until low-end computer are fast enough for interactively performing thepresented techniques. The presented technique allows for parallel computingthe visualisation, and it seems that it is a trend to equip low-end computerswith multiple CPU’s, and as such, parallelising would be a good way of furtherimproving performance. Also, an interesting option might be to perform part ofthe computations on the GPU. For example, summing the concentrations in thecompartments is perfectly possible on the GPU. In 2005, an entire ray-tracerhas already been implemented on the GPU[1]. Not all proposed optimisationsand artifact-correcting methods have been implemented in Mimicspp.

The optimisations presented provide rather simple yet effective means toincrease the performance. The artifacts caused by the optimisations are innoticeable certain cases, but only at low radial resolutions and highly differingconcentrations in neighbouring compartments.

Some other implementation changes that might improve the overall result ofthe visualisation are:

• Implementing resolution resampling of the geometry on forehand of thevisualisation.

• Antialiasing the corners of the image. This would result in very sharpcorners without much performance loss.

• Use a colour map instead of one colour respresenting the concentration.

• Allow interactivity, such as zooming, panning and cutting.

• Allow the making of animations. This is not much work; it only requiressaving every nth frame.

• Optimise the code.

31

Page 32: Simulating the intestine - Rijksuniversiteit Groningenoffringa/Simulating the intestine.pdf · and large intestine. The intestine is mod-elled as one straight, long tube, with varying

5 The implementation

In this chapter, a quick overview of the implementation of Mimicspp, the sim-ulator and visualiser, is given.

Figure 22: Main screen of Mimicspp

5.1 Architecture and design

Mimicspp contains a graphical user interface (see figure 22) in which users canconfigure a simulation, store and load configurations and perform and watchthe simulation, and it contains the simulation engine and visualisation engine.Mimicspp was meant to be cross-platform, so it could easily be ported to anyplatform on which the user likes.

Mimicspp is written in the C++ programming language and uses severalC++ libraries, which will be described in detail in §5.2. C++ was chosen toensure a good performance while being able to use high-level syntax and anobject-oriented design. Development was performed in KDevelop, the developenvironment of KDE, on a system equipped with Linux.

Figure 23: Mimicspp components

Each of the three modules is subdivided into smaller components, and even-tually into objects. Figure 23 shows the three modules and their most notable

32

Page 33: Simulating the intestine - Rijksuniversiteit Groningenoffringa/Simulating the intestine.pdf · and large intestine. The intestine is mod-elled as one straight, long tube, with varying

components.The simulator is the most complicated module. It implements the different

partial differential equation solvers such as Euler and Runge Kutta 4 integration,the processes, datastructures to store the current configuration of the simulationand it provides means to save and load the configuration and extract informationfrom the simulation. Currently, three different processes have been implementedin this component, being diffusion, laminar flow and default metabolism. Theconfiguration component stores all necessary information about the simulator,such as which processes are enabled, which substances and bacteria are required,the transport parameters for each inhabitant, the method of solving the ODE,etcetera.

The graphical user interface module consists of components for the variouswindows that are available in Mimicspp and some helper classes.

The visualisation module implements the discussed visualisation method andprovides a GUI component that the GUI module can create to show the visual-isation.

5.2 Libraries

Three libraries were used in Mimicspp, being FLTK, Boost and libxml. Each ofthese will be discussed in the following sections.

5.2.1 FLTK

FLTK, which stands for Fast Light Toolkit, is a C++ toolkit that lets youbuild a graphical user interface. It aims on being very fast and lightweight andsupports cross-platform development and is designed to let OpenGL integratein your user interface. It is published under an extended LGPL license. Twoversions are being developed: FLTK 1.1 and FLTK 2.0. The first one is thecurrent stable version while the latter one is a newer version that addressescertain issues found in 1.1, such as C++ usage, better support for theming andvarious other improvements.[7]

Initially I was planning on using “gtkmm”, the C++ version of the gtk+toolkit, instead of FLTK. However, Michael Wilkinson advised me to take a lookat FLTK, as he had good experience with it. While reading FLTK’s manual itwas not clear to me which version should be used in my case, nor how far FLTK2.0 was from being stable. I decided to try FLTK 2.0 nevertheless, as I thoughtthat it would probably be more actively developed and gain longer support. Atfirst glance it looked well suited: FLTK provides a GUI builder named Fluid,which let you build your windows by dragging components and it compiles veryquickly; while files that used the C++ STL take about one second to compile,files that only used FLTK compiled about ten times faster. Later, when I wasdemanding more from the toolkit, I came across some nuisances, such as:

• The designer was not flexible enough to do what I wanted, which wascaused by having designed my own VisualizationBox component. Thedesigner did not understand correctly how the component should be ref-erenced, and consequently I had to manually put some #include’s in thefile each time I had changed the layout with Fluid and regenerated thecode.

33

Page 34: Simulating the intestine - Rijksuniversiteit Groningenoffringa/Simulating the intestine.pdf · and large intestine. The intestine is mod-elled as one straight, long tube, with varying

• FLTK 2.0 contains currently still many bugs, some of which were quiteirritating. Mostly, these bugs were located in the open and save file dialogs.

• I had some problems with synchronising drawing to the FLTK canvas fromdifferent threads; although all drawing from threads running in parallelwas eventually behind one exclusive lock, some drawing synchronisationerrors still occurred.

• Regression occurred several times, because I had updated FLTK 2.0 toa newer version. In the hope that some of the bugs were fixed in laterversions, I updated FLTK as soon as here were new versions. Though, atone point, the update actually made part of the functions of Mimicspp nolonger work. I had to revert to an older version of FLTK on the FLTKsvn to fix the problem, and consequently have not been updating since,as solving the issue and pinpointing the cause of the problem costed mequite some time.

• FLTK 2.0 has quite a dull look and it is hard to create a neatly designedapplication. It also solves many things differently from standard toolkits,as for example how to react to resizing.

That said, FLTK’s advantages (quick compilation speed, good performance)were very beneficial, and it was educational to use bleeding edge software. Iwould have made it myself easier though if I would have used FLTK 1.1 oranother toolkit.

5.2.2 Boost

Boost is a set of libraries that enhances the C++ STL. It has an open license.It contains libraries for all sort of tasks, though I have used only three specificparts of Boost: threading, signalling and date and time functions. I was verysatisfied about each of them. Some functions are solved in rather complicatedways, as all aspects of C++ are used very thoroughly, but it contains very gooddocumentation. I found it also rather hard to compile the library from source,especially to compile only those parts of Boost that I actually required, so Iused precompiled packages.

5.2.3 libxml2

libxml2 is an xml parsing and writing library for the language C, is licensedunder a MIP license and portable to all major platforms. It is developed forthe Gnome project but usable outside of the Gnome platform, as is done in thecase of Mimicspp.

libxml2 is used for reading and writing the configuration to XML-files. It israther low-level, but as such it is light weight and quick, and contains adequatedocumentation, and as so it was a good choice. In previous projects, experiencewith Xerces-C++ was gained – another XML library, but this experience wasless positive; it is heavy and contains its own implementation of strings, whichgenerally results in code that is much harder to read or implement.

34

Page 35: Simulating the intestine - Rijksuniversiteit Groningenoffringa/Simulating the intestine.pdf · and large intestine. The intestine is mod-elled as one straight, long tube, with varying

5.3 Evaluation of the implementation

As always, not every aspect of the implementation went as aspected. Certaindesign decisions, such as the way to handle the boundaries, store amounts in-stead of concentrations and to use FLTK 2.0 instead of FLTK 1.1 were not verywell negotiated with my supervisor, and not all of them were ideal. Neverthe-less, the final implementation is very satisfactory, and many extra features wereimplemented that were initially not part of the goals, such as allowing multiplebacteria types, drawing plots and saving and loading the simulation. Despitethe fact that the final goals were reasonable ambitious, the application can beconsidered as “finished”.

The only goal that was not achieved was to use parallel computing to performthe simulation. This, however, was considered as unnecessary, as the simulationprovided enough performance on a single computer to perform the calculations,and as such, other goals that were more likely to provide an increase in valuereplaced this goal.

One major design decision was to implement one differential equation solverwhich solved the entire equation for all processes. This was unlike the previoussimulators (Mimics and MimicsJ), but proved to result in a clear structure ofthe program with adequate performance.

5.3.1 Language

The choice of using the C++ programming language is considered as “okay”;there were times at which “low level” bugs such as memory leaks or pointererrors caused some time to solve, which would not have occurred in higher levellanguages such as Java or C#, but on overall, implementing in C++ is not muchslower as implementing in Java or C#. Moreover, the additional improvementin performance and finer control over memory is worth this small extra troublein this case. Java and C# have the additional benefit of enhanced developmentenvironments with many beneficial features such as code completion. KDevelop,the environment that was used for Mimicspp, is tailered for C++ and alsocontains many of these features, and the use of KDevelop was certainly a pro.

6 Conclusions & future work

In this project, the basis for in silico microbiologic experiments of the intestinehave been achieved: a user friendly simulator has been implemented, with whichresults can be produced that can be examined in multiple ways. Now that thissimulator is available, it is time to let the microbiology experts experimentwith the simulator and assemble results and feedback on how useful the in silicoexperiments truly are. The performance of the simulation is high enough for thecurrent low-end computers, with simulation times of approximately ten secondstowards one hour for very complex simulations. As such, high performancecomputing facilities are no longer required for these kind of simulations.

Sadly, the resources available for this project were small. It would havebeen a benefit if there had been the availability of and time for contact withmicrobiologists during the project, so feedback could be gathered during the im-plementation in order to find out which features are really important and whichfeatures should be skipped. Fortunately, my supervisor Michael Wilkinson had

35

Page 36: Simulating the intestine - Rijksuniversiteit Groningenoffringa/Simulating the intestine.pdf · and large intestine. The intestine is mod-elled as one straight, long tube, with varying

experience with the subject and could pinpoint many important requirementsfor the implementation. It would have been motivating however if – with thehelp of others – any useful simulations could have been performed: the onlyperformed simulations were fictional situations to test the system.

A major problem during the project was finding reasonable parameter set-tings that would mimic the behaviour inside intestine, such as growth rate anddecay rate of bacteria. The values in [10] provide a first estime, but are still veryrough. This was a major problem, as the parameters influence the performanceof the simulation, and performance was an important aspect of the simulation.It is therefore hard to make conclusions from the simulations. Many aspects ofthis research area are yet unknown, and not much previous work on the sub-ject has been performed. In some comparable research projects, the requiredparameters have been estimated by simulating situations that have been wellknown, until equal results have been reached[3]. This might be an interestingidea to estimate the required parameters for this project as well.

Visualising the results with a ray-cast method is an interesting subject. Oncemore, since the simulator has not yet been used by microbiologists that couldinterpret its results, it is unclear how useful the visualisations are. What canbe concluded, is that the performance of the method will soon be high enoughto allow real-time interactivity. In the mean time, the presented visualisationmethod can already be used to create movies or provide the user with informa-tion about a currently running simulation. The visualisation with the severalpresented optimisations, provides interesting, good looking images. Several pos-sible improvements have been presented.

As is generally the case, an implementation is never finished. Several featuresthat might prove to be useful to implement in Mimicspp might be:

• Better graphs, that can also be drawn during simulations. Currently,graphs can only be drawn if the simulations is finished, with the help ofgnuplot.

• Batch processing, so several simulations with multiple parameters can besimulated sequentially without the need for human interference.

• More processes and more flexible process-configurations. Currently, pro-cesses can be turned “on” or “off”, and not turned on for one bacteriumor other inhabitant. There are probably situations in which this is notflexible enough.

• Geometry user interface: Mimicspp is written in such a way that the entiregeometry can be easily changed. However, the interface of Mimicspp doesnot yet allow changing the parameters of the intestine very easily, whichmight be a future enhancement of the simulator, so that the simulation canbe used for example for simulations of the intestine of children or animalsas well. Nevertheless, the length of the intestine is not that important;it is the time that is required for substrate to pass the entire intestinethat seems to be more important. This conclusion, however, might be theresult of the rather simplistic model. A model with wall attachment ortrue peristaltic movement might make this more important.

36

Page 37: Simulating the intestine - Rijksuniversiteit Groningenoffringa/Simulating the intestine.pdf · and large intestine. The intestine is mod-elled as one straight, long tube, with varying

7 Acknowledgements

This report is the result of an educational internship project at the Rijksuni-versiteit Groningen. I would like to thank Michael Wilkinson as supervisor forassisting me. He has providing me with information and feedback during theproject. I would also like to thank Carolien Doorenbos for her helpful discus-sions on, among other things, flow speed, the report and several medical relatedissues. Last, I would like to thank Rene Offringa for correcting some errors inthe report.

37

Page 38: Simulating the intestine - Rijksuniversiteit Groningenoffringa/Simulating the intestine.pdf · and large intestine. The intestine is mod-elled as one straight, long tube, with varying

A Bibliography

References

[1] Martin Christen. Ray tracing on GPU. January 2005. [http://www.clock-workcoders.com/oglsl/rt/].

[2] Peter de Jong, Marc M. M. Vissers, Roelof van der Meer, and Ingeborg M.J.Bovee-Oudenhoven. In silico model as a tool for interpretation of intestinalinfection studies. Applied and Environmental Microbiology, pages 508–515,January 2007.

[3] Barbara Juillet, Maria Pia Saccomani, Cecile Bos, Claire Gaudichon,Daniel Tome, and Helene Fouillet. Conceptual, methodological and com-putational issues concerning the compartmental modeling of a complexbiological system: Postprandial inter-organ metabolism of dietary nitrogenin humans. Mathematical Biosciences, 204:282–309, 2006.

[4] David Kraus. Concepts of Modern Biology. Globe Fearon, December 1998.

[5] Lukas Mroz. Real-Time Volume Visualization on Low-End Hardware. PhDthesis, February 2001. [http://www.cg.tuwien.ac.at/ mroz/diss/].

[6] Lukas Mroz, Helwig Hauser, and Meister Eduard Groller. Interactive high-quality maximum intensity projection. Technical Report TR-186-2-99-25,Institute of Computer Graphics and Algorithms, Vienna University of Tech-nology, Favoritenstrasse 9-11/186, A-1040 Vienna, Austria, December 1999.human contact: [email protected].

[7] Bill Spitzak et al. Introduction to FLTK, 2007. [http://www.fltk.org/doc-2.0/html/intro.html].

[8] Eric W. Weisstein. Quadratic surface. [Online; accessed 13-August-2007;http://mathworld.wolfram.com/QuadraticSurface.html].

[9] Michael H.F. Wilkinson. Model intestinal microflora in computer simula-tion (MIMICS) technical report: Cellular automaton program design andperformance testing.

[10] Michael H.F. Wilkinson. Model intestinal microflora in computer simula-tion: A simulation and modelling package for host-microflora interactions.IEEE Transactions on Biomedical Engineering, 49(10), October 2002.

[11] J.C. Wood, I.J. McKendrick, and G. Gettinby. A simulation model for thestudy of the within-animal infection dynamics of E. coli O157. PreventiveVeterinary Medicine, 74:180–193, 2006.

B Mimicspp user manual

This is a short introduction on how to set up a simulation with Mimicspp. Theprocess of performing an experiment can be divided in the following three steps:

• Configure the simulation

38

Page 39: Simulating the intestine - Rijksuniversiteit Groningenoffringa/Simulating the intestine.pdf · and large intestine. The intestine is mod-elled as one straight, long tube, with varying

• Running the simulation

• Gathering the results

Each of these will be discussed in more detail below.

B.1 Configuring the simulation

Figure 24: Main screen of Mimicspp

After Mimicspp has been started, a small window is shown (figure 24) thatcontains the parameters for the differential equation solver and some otherrunning-parameters. In the top of the window several tabs are shown. Un-der each tab, more settings can be found. The “visualisation” and “report”tabs are where the results will be shown.

To begin defining a new simulation, start by picking the processes that youwant to simulate in the “Processes” tab. You can enable processes by clicking onits name in the right list, and pressing the button with the arrow. The processwill now be shown in the left list. To remove the process, select the process inthe left list, and click the button with the “X” on it. To perform a simulationthat simulates the intestine most closely, select all processes. You will be ableto define the parameters for each process later, as these can be different for eachinhabitant.

The next step is selecting the geometry that you want to simulate, under the“geometry” tab. You can select a different geometry by clicking on a geometry(currently only three different geometries) and press the “Select” button. Thetext under the button should change accordingly.

Then, the substances that are simulated should be chosen. This is done inthe “Substances” tab. Currently, the only available substances are “food” and“oxygen”. These two substances have a special role in the Metabolism process:all bacteria eat food, while aerobic bacteria also use oxygen. Each inhabi-tant contains initialisation parameters and transport parameters. These can beedited by clicking in the left list on the inhabitant that you would like to edit,and subsequently pressing the “Edit transport parameters” or “Initialisationparameters” button.

39

Page 40: Simulating the intestine - Rijksuniversiteit Groningenoffringa/Simulating the intestine.pdf · and large intestine. The intestine is mod-elled as one straight, long tube, with varying

The next step is setting up the bacteria that you want to simulate. Thistab works exactly like the “Substances” tab, except that it contains an extraparameter edit button, “Bacterium parameters”. The parameters in this screenedit the metabolistic properties of the selected bacterium. Bacteria can be givena name, and you can add as many bacteria as is necessary.

Now that you have set up the ecological properties of the simulation, youmight want to save the simulation. This can be done by returning to the “Op-tions” property, pressing the “Save simulation” button and entering an adequatename. Later on, you will be able to load this same simulation by pressing the“Load simulation” button.

You can alter the run options of the simulation on the “Options” tab. Themost important parameters are the “end time” (how many time will be simu-lated) and the compartment resolution parameter “Number of axial compart-ments” and “Number of radial parameters”. Be sure not to set these values toohigh, as this might require a long time to simulate. You can always increasethese values later on.

You can browse the “Tabs” until you are satisfied with all the settings.

B.2 Running the simulation

Once you are satisfied with all settings, you can press the “Run” button onthe “Options” tab. Mimicspp will now switch to a different tab, either the“Visualisation” or the “Report” tab, depending on whether the visualisationwas turned on.

While simulating, you can still switch tabs. You should not make anychanges to the configuration during simulation, except for the parameters onthe “Visualisation” tab.

Normally, the visualisation is periodically refreshed to the current situationin the simulation. You can select which inhabitant should be visualised or choseto simulate all inhabitants in the same visualisation, but this is often confusing.The “logarithmic” button turns all concentrations into logarithmic concentra-tions before they are visualised. The “stretch to fit” checkbox stretches thegeometry so that it is magnified maximally, but might change the width/heightratio of the geometry. In case of visualising an intestine, stretching is necessary,as the intestine is so small that nothing would be seen otherwise. On this win-dow, you can also stop the simulation with the “Stop” button. You will not beable to continue the simulation however, and will have to start all over.

The “Report” tab contains textual information about the currently runningsimulation. It gives for example an estimate on how long the simulation willtake and measurements on the performance. It will also contain the output ofthe optional benchmark.

B.3 Gathering the results

After the simulation, one way of determining the results is looking at the visu-alisation. This is however not very accurate, so a second method that is buildin Mimicspp, is to generate graphs. This can be done by clicking on the “Saveresults” button in the “options” tab. You will be asked for a name-prefix. Sev-eral GNU plot-graph files will be created. To see these graphs, you will needthe “GNU plot” software package. It is free to use, but not available under

40

Page 41: Simulating the intestine - Rijksuniversiteit Groningenoffringa/Simulating the intestine.pdf · and large intestine. The intestine is mod-elled as one straight, long tube, with varying

Windows. To show a graph file, enter the directory in which the .plt-file issaved and type: gnuplot -persist filename.plt

41