/*
 * This code is generated by BioUML FrameWork 
 * for BIOMD0000000044.xml diagram  at 2008.03.20 15:04:23
 */
import biouml.plugins.simulation.ae.NewtonSolver;
import biouml.plugins.simulation.java.JavaBaseModel;
import ru.biosoft.math.MathRoutines;

public class BIOMD0000000044 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_v2 = _extracellular_cytosol_intravesicular_*(v2_Vm2*Math.pow(x[4], 2)/(Math.pow(v2_K2, 2) + Math.pow(x[4], 2)));
        rate_v3 = _extracellular_cytosol_*v3_Vm3*Math.pow(x[0], 4)*Math.pow(x[5], 2)*Math.pow(x[4], 4)/((Math.pow(v3_Ka, 4) + Math.pow(x[0], 4))*(Math.pow(v3_Ky, 2) + Math.pow(x[5], 2))*(Math.pow(v3_Kz, 4) + Math.pow(x[4], 4)));
        rate_v4 = _extracellular_cytosol_*v4_Kf*x[5];
        rate_v5 = extracellular*v5_K*x[4];
        rate_v6 = _extracellular_cytosol_*beta*v6_Vp;
        rate_v7 = _extracellular_cytosol_*v7_Vd*Math.pow(x[0], 2)*Math.pow(x[4], v7_n)/((Math.pow(v7_Kp, 2) + Math.pow(x[0], 2))*(Math.pow(v7_Kd, v7_n) + Math.pow(x[4], v7_n)));
        rate_v8 = _extracellular_cytosol_*v8_epsilon*x[0];
        rate_vin = _extracellular_cytosol_*(vin_v0 + vin_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
        beta = 0.5; // initial value of beta
        v2_K2 = 0.1; // initial value of v2_K2
        v2_Vm2 = 6.5; // initial value of v2_Vm2
        v3_Ka = 0.2; // initial value of v3_Ka
        v3_Ky = 0.2; // initial value of v3_Ky
        v3_Kz = 0.3; // initial value of v3_Kz
        v3_Vm3 = 19.5; // initial value of v3_Vm3
        v4_Kf = 1.0; // initial value of v4_Kf
        v5_K = 10.0; // initial value of v5_K
        v6_Vp = 2.5; // initial value of v6_Vp
        v7_Kd = 0.4; // initial value of v7_Kd
        v7_Kp = 1.0; // initial value of v7_Kp
        v7_Vd = 80.0; // initial value of v7_Vd
        v7_n = 4.0; // initial value of v7_n
        v8_epsilon = 0.1; // initial value of v8_epsilon
        vin_v0 = 2.0; // initial value of vin_v0
        vin_v1 = 1.0; // initial value of vin_v1
    }

    /*
     * Model variables initial values
     */
    protected double _extracellular_cytosol_;
    protected double _extracellular_cytosol_intravesicular_;
    protected double rate_v2;
    protected double rate_v3;
    protected double rate_v4;
    protected double rate_v5;
    protected double rate_v6;
    protected double rate_v7;
    protected double rate_v8;
    protected double rate_vin;
    protected double extracellular;
    protected double beta;
    protected double v2_K2;
    protected double v2_Vm2;
    protected double v3_Ka;
    protected double v3_Ky;
    protected double v3_Kz;
    protected double v3_Vm3;
    protected double v4_Kf;
    protected double v5_K;
    protected double v6_Vp;
    protected double v7_Kd;
    protected double v7_Kp;
    protected double v7_Vd;
    protected double v7_n;
    protected double v8_epsilon;
    protected double vin_v0;
    protected double vin_v1;

    public double[] extendResult(double time,double [] x)
    {
        this.time = time;


        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] = x[5];
        y[6] = x[6];
        return y;
    }
    public double[] getInitialValues()
    {
        double [] x = new double[7];
        this.time = 0.0;
        x[0] = 0.45; // - $"extracellular.cytosol.A"
        x[1] = 0.0; // - $"extracellular.cytosol.Agonist_stimulated_production_of_IP3"
        x[2] = 0.0; // - $"extracellular.cytosol.Ca_dependant_IP3_degradation"
        x[3] = 0.0; // - $"extracellular.cytosol.Ca_independant_IP3_degradation"
        x[4] = 0.0; // - $"extracellular.cytosol.Z"
        x[5] = 0.36; // - $"extracellular.cytosol.intravesicular.Y"
        x[6] = 1000.0; // - $extracellular.EC

        __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 'BIOMD0000000044.xml' model
         */
    public void __internalDyDt_0(double time, double [] x, double[] result)
    {
        result[0] = +rate_v6-rate_v7-rate_v8;
        result[1] = -rate_v6;
        result[2] = +rate_v7;
        result[3] = +rate_v8;
        result[4] = -rate_v2+rate_v3+rate_v4-rate_v5+rate_vin;
        result[5] = +rate_v2-rate_v3-rate_v4;
        result[6] = +rate_v5-rate_vin;
    }
    protected double [] calculateResult(double time, double[] x)
    {
        double[] result = new double[7];
        __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 ...