/*
 * This code is generated by BioUML FrameWork 
 * for BIOMD0000000100.xml diagram  at 2008.03.20 15:08:36
 */
import biouml.plugins.simulation.ae.NewtonSolver;
import biouml.plugins.simulation.java.JavaBaseModel;
import ru.biosoft.math.MathRoutines;

public class BIOMD0000000100 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_R2 = _extracellular_cytosol_*(Vm2*Math.pow(x[2], 2)/(Math.pow(K2, 2) + Math.pow(x[2], 2)));
        rate_R3 = _extracellular_cytosol_intravesicular_*Vm3*Math.pow(x[0], 4)*Math.pow(x[3], 2)*Math.pow(x[2], m)/((Math.pow(Ka, 4) + Math.pow(x[0], 4))*(Math.pow(Ky, 2) + Math.pow(x[3], 2))*(Math.pow(Kz, m) + Math.pow(x[2], m)));
        rate_R4 = _extracellular_cytosol_*beta*V4;
        rate_R5 = _extracellular_cytosol_*Vm5*Math.pow(x[0], p)*Math.pow(x[2], n)/((Math.pow(K5, p) + Math.pow(x[0], p))*(Math.pow(Kd, n) + Math.pow(x[2], n)));
        rate_R6 = _extracellular_cytosol_*epsilon*x[0];
        rate_R7 = _extracellular_cytosol_*(Vpm1*(1 + gamma*Math.pow(x[2], 4)/(Math.pow(Ka5, 4) + Math.pow(x[2], 4)))*(1 - x[1])/(K1/(1 + Math.pow(x[2], 4)/Math.pow(Ka6, 4)) + 1 - x[1]));
        rate_R8 = _extracellular_cytosol_*(Vpm2*(1 + alpha*G/(Ka1 + G))*x[1]/(Kp2/(1 + G/Ka2) + x[1]));
        rate_Rkf = _extracellular_cytosol_intravesicular_*Kf*x[3];
        rate_Rkz = _extracellular_cytosol_*K*x[2];
        rate_vin = extracellular*(v0 + v1*beta);
    }

    public void Init()
    {
        initialValues = getInitialValues();
/*
 * Initialize variables
 */
        _extracellular_cytosol_ = 1.0; // initial value of $"extracellular.cytosol"
        _extracellular_cytosol_intravesicular_ = 1.0; // initial value of $"extracellular.cytosol.intravesicular"
        extracellular = 1.0; // initial value of $extracellular
        extracellular_EC = 1000.0; // initial value of $extracellular.EC
        G = 10000.0; // initial value of G
        K = 10.0; // initial value of K
        K1 = 0.1; // initial value of K1
        K2 = 0.1; // initial value of K2
        K5 = 1.0; // initial value of K5
        Ka = 0.2; // initial value of Ka
        Ka1 = 10000.0; // initial value of Ka1
        Ka2 = 10000.0; // initial value of Ka2
        Ka5 = 0.5; // initial value of Ka5
        Ka6 = 0.5; // initial value of Ka6
        Kd = 0.4; // initial value of Kd
        Kf = 1.0; // initial value of Kf
        Kp2 = 0.2; // initial value of Kp2
        Ky = 0.2; // initial value of Ky
        Kz = 0.5; // initial value of Kz
        V4 = 2.0; // initial value of V4
        Vm2 = 6.0; // initial value of Vm2
        Vm3 = 20.0; // initial value of Vm3
        Vm5 = 30.0; // initial value of Vm5
        Vpm1 = 1.5; // initial value of Vpm1
        Vpm2 = 0.6; // initial value of Vpm2
        alpha = 9.0; // initial value of alpha
        beta = 0.5; // initial value of beta
        epsilon = 0.1; // initial value of epsilon
        gamma = 9.0; // initial value of gamma
        m = 2.0; // initial value of m
        n = 4.0; // initial value of n
        p = 2.0; // initial value of p
        v0 = 2.0; // initial value of v0
        v1 = 2.0; // initial value of v1
    }

    /*
     * Model variables initial values
     */
    protected double _extracellular_cytosol_;
    protected double _extracellular_cytosol_intravesicular_;
    protected double rate_R2;
    protected double rate_R3;
    protected double rate_R4;
    protected double rate_R5;
    protected double rate_R6;
    protected double rate_R7;
    protected double rate_R8;
    protected double rate_Rkf;
    protected double rate_Rkz;
    protected double rate_vin;
    protected double extracellular;
    protected double extracellular_EC;
    protected double G;
    protected double K;
    protected double K1;
    protected double K2;
    protected double K5;
    protected double Ka;
    protected double Ka1;
    protected double Ka2;
    protected double Ka5;
    protected double Ka6;
    protected double Kd;
    protected double Kf;
    protected double Kp2;
    protected double Ky;
    protected double Kz;
    protected double V4;
    protected double Vm2;
    protected double Vm3;
    protected double Vm5;
    protected double Vpm1;
    protected double Vpm2;
    protected double alpha;
    protected double beta;
    protected double epsilon;
    protected double gamma;
    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[4];
        y[0] = x[0];
        y[1] = x[1];
        y[2] = x[2];
        y[3] = x[3];
        return y;
    }
    public double[] getInitialValues()
    {
        double [] x = new double[4];
        this.time = 0.0;
        x[0] = 0.45; // - $"extracellular.cytosol.A"
        x[1] = 1.0; // - $"extracellular.cytosol.GP"
        x[2] = 0.0; // - $"extracellular.cytosol.Z"
        x[3] = 0.36; // - $"extracellular.cytosol.intravesicular.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 'BIOMD0000000100.xml' model
         */
    public void __internalDyDt_0(double time, double [] x, double[] result)
    {
        result[0] = +rate_R4-rate_R5-rate_R6;
        result[1] = +rate_R7-rate_R8;
        result[2] = -rate_R2+rate_R3+rate_Rkf-rate_Rkz+rate_vin;
        result[3] = +rate_R2-rate_R3-rate_Rkf;
    }
    protected double [] calculateResult(double time, double[] x)
    {
        double[] result = new double[4];
        __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 ...