Team:BCCS-Bristol/Modeling/Antos/ODE intefaces

From 2009.igem.org

(Difference between revisions)
(An Example ODE)
(Removing all content from page)
 
(2 intermediate revisions not shown)
Line 1: Line 1:
-
=Notes on ODE Interfaces=
 
-
Currently we can specify custom ODEs by creating a class that implements BSimOdeSingle or BSimOdeSystem.
 
-
The custom classes can be passed directly to any solver, ''however the solvers are only single-step to make them more adaptable (and easier to integrate into BSim :) ) therefore implementing actual iteration along a time series is left up to the programmer''.
 
-
 
-
==BSimOdeSingle==
 
-
 
-
This interface allows you to specify a single ODE. The interface requires two methods, one to define the derivatives and one to return the initial conditions for the initial value problem.
 
-
 
-
===An Example ODE===
 
-
 
-
To define the problem
 
-
 
-
(mathsy bits - eqn, ICs)
 
-
 
-
<math>\diff{y}{t} = t</math>
 
-
AAARGH why doesn't this work :(
 
-
 
-
One would create a new class defining the ODE with the following code:
 
-
 
-
<pre>
 
-
//Package, Imports etc here
 
-
 
-
// An example ODE
 
-
public class Linear implements BSimOdeSingle {
 
-
public double derivative(double x, double y){
 
-
dy = x;
 
-
return dy;
 
-
}
 
-
 
-
public double getIC(){ return 0.0; }
 
-
}
 
-
</pre>
 
-
 
-
The class ''Linear'' would then be passed to a solver along with current ''x'' (in this case ''x'' is in fact ''t'') and ''y'' values.
 
-
 
-
==BSimOdeSystem==
 
-
 
-
With this interface it is possible to define a system of multiple (possibly coupled) ODEs. In a similar manner to BSimOdeSingle, it is necessary to specify the derivatives and the initial conditions, however they must now be in the form of arrays as there are multiple values to consider. There is also a third method which must be specified which returns the numebr of equations present in the system. The implementation of these methods is left up to the user.
 
-
 
-
===An Example ODE System===
 
-
 
-
As an example, we show here how one would define a simple (damped) harmonic oscillator. The original equation is as follows:
 
-
 
-
(maths - SHM 2nd order ODE)
 
-
 
-
This is a second order ODE and so must be simplified to a system of first order equations with the substitution
 
-
 
-
(maths - y1'=y2 , and the full system)
 
-
 
-
One can then specify the initial conditions
 
-
 
-
(maths - ICs)
 
-
 
-
The Java implementation of this system is illustrated in the following segment of code:
 
-
 
-
<pre>
 
-
//Package, Imports etc here
 
-
 
-
// An example ODE system - Damped Simple Harmonic Motion
 
-
public class SHM implements BSimOdeSytem{
 
-
private int numEq = 2;
 
-
 
-
        public int getNumEq(){return numEq ;}
 
-
 
-
public double[] derivativeSystem(double x, double[] y){
 
-
double[] dy = new double[numEq];
 
-
dy[0] = y[1];
 
-
dy[1] = -2*y[0] - 0.1*y[1];
 
-
return dy;
 
-
}
 
-
 
-
public double[] getICs(){
 
-
double[] y0 = new double[numEq];
 
-
y0[0] = 0;
 
-
y0[1] = 1;
 
-
return y0;
 
-
}
 
-
}
 
-
</pre>
 
-
 
-
The class ''SHM'' can then be passed to the solver of choice.
 

Latest revision as of 00:09, 21 October 2009