/*
 * This code is generated by BioUML FrameWork 
 * for BIOMD0000000003.xml diagram  at 2008.03.20 15:03:14
 */
import biouml.plugins.simulation.ae.NewtonSolver;
import biouml.plugins.simulation.java.JavaBaseModel;
import ru.biosoft.math.MathRoutines;

public class BIOMD0000000003 extends JavaBaseModel
{

/*
 * Write rules to calculate equation parameters
 */
    private void __internalVarInitFunc_0(double time, double[] x)
    {
        V1 = x[0]*VM1*Math.pow((x[0] + Kc), -1.0);
        V3 = x[1]*VM3;
    }


/*
 * Write rules to calculate equation parameters excluding internal variables.
 */
    public void __internalRateVarInitFunc_0(double time, double[] x)
    {
        rate_reaction1 = cell*reaction1_vi;
        rate_reaction2 = x[0]*cell*reaction2_kd;
        rate_reaction3 = x[0]*cell*reaction3_vd*x[2]*Math.pow((x[0] + reaction3_Kd), -1.0);
        rate_reaction4 = cell*(1 + -1.0*x[1])*V1*Math.pow((reaction4_K1 + -1.0*x[1] + 1), -1.0);
        rate_reaction5 = cell*x[1]*reaction5_V2*Math.pow((reaction5_K2 + x[1]), -1.0);
        rate_reaction6 = cell*V3*(1 + -1.0*x[2])*Math.pow((reaction6_K3 + -1.0*x[2] + 1), -1.0);
        rate_reaction7 = cell*reaction7_V4*x[2]*Math.pow((reaction7_K4 + x[2]), -1.0);
    }

    public void Init()
    {
        initialValues = getInitialValues();
/*
 * Initialize variables
 */
        cell = 1.0; // initial value of $cell
        Kc = 0.5; // initial value of Kc
        VM1 = 3.0; // initial value of VM1
        VM3 = 1.0; // initial value of VM3
        reaction1_vi = 0.025; // initial value of reaction1_vi
        reaction2_kd = 0.01; // initial value of reaction2_kd
        reaction3_Kd = 0.02; // initial value of reaction3_Kd
        reaction3_vd = 0.25; // initial value of reaction3_vd
        reaction4_K1 = 0.0050; // initial value of reaction4_K1
        reaction5_K2 = 0.0050; // initial value of reaction5_K2
        reaction5_V2 = 1.5; // initial value of reaction5_V2
        reaction6_K3 = 0.0050; // initial value of reaction6_K3
        reaction7_K4 = 0.0050; // initial value of reaction7_K4
        reaction7_V4 = 0.5; // initial value of reaction7_V4
    }

    /*
     * Model variables initial values
     */
    protected double rate_reaction1;
    protected double rate_reaction2;
    protected double rate_reaction3;
    protected double rate_reaction4;
    protected double rate_reaction5;
    protected double rate_reaction6;
    protected double rate_reaction7;
    protected double cell;
    protected double Kc;
    protected double V1;
    protected double V3;
    protected double VM1;
    protected double VM3;
    protected double reaction1_vi;
    protected double reaction2_kd;
    protected double reaction3_Kd;
    protected double reaction3_vd;
    protected double reaction4_K1;
    protected double reaction5_K2;
    protected double reaction5_V2;
    protected double reaction6_K3;
    protected double reaction7_K4;
    protected double reaction7_V4;

    public double[] extendResult(double time,double [] x)
    {
        this.time = time;

        __internalVarInitFunc_0(time, x);

        double[] y = new double[5];
        y[0] = x[0];
        y[1] = x[1];
        y[2] = x[2];
        y[3] = V1;
        y[4] = V3;
        return y;
    }
    public double[] getInitialValues()
    {
        double [] x = new double[3];
        this.time = 0.0;
        x[0] = 0.01; // - $"cell.C"
        x[1] = 0.01; // - $"cell.M"
        x[2] = 0.01; // - $"cell.X"

        __internalVarInitFunc_0(time, x);
        __internalRateVarInitFunc_0(time, x);

        return x;
    }

/*
 * code for algebraic rules calculations
 */

/*
 * end of code for algebraic rules calculations
 */

    protected void calculateRates(double time, double[] x)
    {

        __internalVarInitFunc_0(time, x);
        __internalRateVarInitFunc_0(time, x);

    }

        /*
         * calculate dy/dt for 'BIOMD0000000003.xml' model
         */
    public void __internalDyDt_0(double time, double [] x, double[] result)
    {
        result[0] = +rate_reaction1-rate_reaction2-rate_reaction3;
        result[1] = +rate_reaction4-rate_reaction5;
        result[2] = +rate_reaction6-rate_reaction7;
    }
    protected double [] calculateResult(double time, double[] x)
    {
        double[] result = new double[3];
        __internalDyDt_0(time, x, result);
        return result;
    }
    public double[] dy_dt(double time, double[] x)
    {
        this.time = time;
        calculateRates( time,x );

        return calculateResult( time,x );
    }

} // class ...