/*
 * This code is generated by BioUML FrameWork 
 * for BIOMD0000000008.xml diagram  at 2008.03.20 15:03:19
 */
import biouml.plugins.simulation.ae.NewtonSolver;
import biouml.plugins.simulation.java.JavaBaseModel;
import ru.biosoft.math.MathRoutines;

public class BIOMD0000000008 extends JavaBaseModel
{

/*
 * Write rules to calculate equation parameters
 */
    private void __internalVarInitFunc_0(double time, double[] x)
    {
        V1 = x[0]*V1p*Math.pow((x[0] + K6), -1.0);
        V3 = x[1]*V3p;
    }


/*
 * Write rules to calculate equation parameters excluding internal variables.
 */
    public void __internalRateVarInitFunc_0(double time, double[] x)
    {
        rate_reaction1 = reaction1_vi;
        rate_reaction10 = reaction10_alpha*reaction10_d1*x[4];
        rate_reaction11 = reaction11_alpha*reaction11_kd*x[4];
        rate_reaction12 = reaction12_vs;
        rate_reaction13 = reaction13_d1*x[3];
        rate_reaction2 = x[0]*reaction2_k1*x[2]*Math.pow((x[0] + reaction2_K5), -1.0);
        rate_reaction3 = x[0]*reaction3_kd;
        rate_reaction4 = (1 + -1.0*x[1])*V1*Math.pow((reaction4_K1 + -1.0*x[1] + 1), -1.0);
        rate_reaction5 = x[1]*reaction5_V2*Math.pow((reaction5_K2 + x[1]), -1.0);
        rate_reaction6 = V3*(1 + -1.0*x[2])*Math.pow((reaction6_K3 + -1.0*x[2] + 1), -1.0);
        rate_reaction7 = reaction7_V4*x[2]*Math.pow((reaction7_K4 + x[2]), -1.0);
        rate_reaction8 = reaction8_a1*x[0]*x[3];
        rate_reaction9 = reaction9_a2*x[4];
    }

    public void Init()
    {
        initialValues = getInitialValues();
/*
 * Initialize variables
 */
        K6 = 0.3; // initial value of K6
        V1p = 0.75; // initial value of V1p
        V3p = 0.3; // initial value of V3p
        reaction10_alpha = 0.1; // initial value of reaction10_alpha
        reaction10_d1 = 0.05; // initial value of reaction10_d1
        reaction11_alpha = 0.1; // initial value of reaction11_alpha
        reaction11_kd = 0.02; // initial value of reaction11_kd
        reaction12_vs = 0.2; // initial value of reaction12_vs
        reaction13_d1 = 0.05; // initial value of reaction13_d1
        reaction1_vi = 0.1; // initial value of reaction1_vi
        reaction2_K5 = 0.02; // initial value of reaction2_K5
        reaction2_k1 = 0.5; // initial value of reaction2_k1
        reaction3_kd = 0.02; // initial value of reaction3_kd
        reaction4_K1 = 0.1; // initial value of reaction4_K1
        reaction5_K2 = 0.1; // initial value of reaction5_K2
        reaction5_V2 = 0.25; // initial value of reaction5_V2
        reaction6_K3 = 0.2; // initial value of reaction6_K3
        reaction7_K4 = 0.1; // initial value of reaction7_K4
        reaction7_V4 = 0.1; // initial value of reaction7_V4
        reaction8_a1 = 0.05; // initial value of reaction8_a1
        reaction9_a2 = 0.05; // initial value of reaction9_a2
    }

    /*
     * Model variables initial values
     */
    protected double rate_reaction1;
    protected double rate_reaction10;
    protected double rate_reaction11;
    protected double rate_reaction12;
    protected double rate_reaction13;
    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 rate_reaction8;
    protected double rate_reaction9;
    protected double K6;
    protected double V1;
    protected double V1p;
    protected double V3;
    protected double V3p;
    protected double reaction10_alpha;
    protected double reaction10_d1;
    protected double reaction11_alpha;
    protected double reaction11_kd;
    protected double reaction12_vs;
    protected double reaction13_d1;
    protected double reaction1_vi;
    protected double reaction2_K5;
    protected double reaction2_k1;
    protected double reaction3_kd;
    protected double reaction4_K1;
    protected double reaction5_K2;
    protected double reaction5_V2;
    protected double reaction6_K3;
    protected double reaction7_K4;
    protected double reaction7_V4;
    protected double reaction8_a1;
    protected double reaction9_a2;

    public double[] extendResult(double time,double [] x)
    {
        this.time = time;

        __internalVarInitFunc_0(time, x);

        double[] y = new double[7];
        y[0] = x[0];
        y[1] = x[1];
        y[2] = x[2];
        y[3] = x[3];
        y[4] = x[4];
        y[5] = V1;
        y[6] = V3;
        return y;
    }
    public double[] getInitialValues()
    {
        double [] x = new double[5];
        this.time = 0.0;
        x[0] = 0.0; // - $"Cell.C"
        x[1] = 0.0; // - $"Cell.M"
        x[2] = 0.0; // - $"Cell.X"
        x[3] = 1.0; // - $"Cell.Y"
        x[4] = 1.0; // - $"Cell.Z"

        __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 'BIOMD0000000008.xml' model
         */
    public void __internalDyDt_0(double time, double [] x, double[] result)
    {
        result[0] = +rate_reaction10+rate_reaction1-rate_reaction2-rate_reaction3-rate_reaction8+rate_reaction9;
        result[1] = +rate_reaction4-rate_reaction5;
        result[2] = +rate_reaction6-rate_reaction7;
        result[3] = +rate_reaction11+rate_reaction12-rate_reaction13-rate_reaction8+rate_reaction9;
        result[4] = -rate_reaction10-rate_reaction11+rate_reaction8-rate_reaction9;
    }
    protected double [] calculateResult(double time, double[] x)
    {
        double[] result = new double[5];
        __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 ...