/*
 * This code is generated by BioUML FrameWork 
 * for BIOMD0000000098.xml diagram  at 2008.03.20 15:08:34
 */
import biouml.plugins.simulation.ae.NewtonSolver;
import biouml.plugins.simulation.java.JavaBaseModel;
import ru.biosoft.math.MathRoutines;

public class BIOMD0000000098 extends JavaBaseModel
{

/*
 * Write rules to calculate equation parameters
 */


/*
 * Write rules to calculate equation parameters excluding internal variables.
 */
    public void __internalRateVarInitFunc_0(double time, double[] x)
    {
        rate_R0 = cytosol*v0;
        rate_R1 = cytosol*v1*beta;
        rate_R2 = cytosol*(Vm2*Math.pow(x[0], n)/(Math.pow(K2, n) + Math.pow(x[0], n)));
        rate_R3 = store*(Vm3*Math.pow(x[1], m)*Math.pow(x[0], p)/((Math.pow(Kr, m) + Math.pow(x[1], m))*(Math.pow(Ka, p) + Math.pow(x[0], p))));
        rate_R_eff = cytosol*k*x[0];
        rate_Rf = store*kf*x[1];
    }

    public void Init()
    {
        initialValues = getInitialValues();
/*
 * Initialize variables
 */
        cytosol = 1.0; // initial value of $cytosol
        store = 1.0; // initial value of $store
        K2 = 1.0; // initial value of K2
        Ka = 0.9; // initial value of Ka
        Kr = 2.0; // initial value of Kr
        Vm2 = 65.0; // initial value of Vm2
        Vm3 = 500.0; // initial value of Vm3
        beta = 0.301; // initial value of beta
        k = 10.0; // initial value of k
        kf = 1.0; // initial value of kf
        m = 2.0; // initial value of m
        n = 2.0; // initial value of n
        p = 4.0; // initial value of p
        v0 = 1.0; // initial value of v0
        v1 = 7.3; // initial value of v1
    }

    /*
     * Model variables initial values
     */
    protected double rate_R0;
    protected double rate_R1;
    protected double rate_R2;
    protected double rate_R3;
    protected double rate_R_eff;
    protected double rate_Rf;
    protected double cytosol;
    protected double store;
    protected double K2;
    protected double Ka;
    protected double Kr;
    protected double Vm2;
    protected double Vm3;
    protected double beta;
    protected double k;
    protected double kf;
    protected double m;
    protected double n;
    protected double p;
    protected double v0;
    protected double v1;

    public double[] extendResult(double time,double [] x)
    {
        this.time = time;


        double[] y = new double[2];
        y[0] = x[0];
        y[1] = x[1];
        return y;
    }
    public double[] getInitialValues()
    {
        double [] x = new double[2];
        this.time = 0.0;
        x[0] = 0.15; // - $"cytosol.Z"
        x[1] = 1.6; // - $"store.Y"

        __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)
    {

        __internalRateVarInitFunc_0(time, x);

    }

        /*
         * calculate dy/dt for 'BIOMD0000000098.xml' model
         */
    public void __internalDyDt_0(double time, double [] x, double[] result)
    {
        result[0] = +rate_R0+rate_R1-rate_R2+rate_R3-rate_R_eff+rate_Rf;
        result[1] = +rate_R2-rate_R3-rate_Rf;
    }
    protected double [] calculateResult(double time, double[] x)
    {
        double[] result = new double[2];
        __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 ...