/*
 * This code is generated by BioUML FrameWork 
 * for BIOMD0000000043.xml diagram  at 2008.03.20 15:04:22
 */
import biouml.plugins.simulation.ae.NewtonSolver;
import biouml.plugins.simulation.java.JavaBaseModel;
import ru.biosoft.math.MathRoutines;

public class BIOMD0000000043 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[2], 2)/(Math.pow(v2_K2, 2) + Math.pow(x[2], 2)));
        rate_v3 = _extracellular_cytosol_*(beta*(x[1]*(a/d)*Math.pow(x[2], 4.0)/(1.0 + a/d*Math.pow(x[2], 4.0)))*v3_Vm3*Math.pow(x[3], 2)/(Math.pow(v3_Ky, 2) + Math.pow(x[3], 2)));
        rate_v4 = _extracellular_cytosol_*v4_Kf*x[3];
        rate_v5 = extracellular*v5_K*x[2];
        rate_v6 = _extracellular_cytosol_*v6_Kd*Math.pow(x[2], 4)*x[1];
        rate_v7 = _extracellular_cytosol_*v7_Kr*(1 - x[1]);
        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
        a = 40000.0; // initial value of a
        beta = 1.0; // initial value of beta
        d = 100.0; // initial value of d
        v2_K2 = 0.1; // initial value of v2_K2
        v2_Vm2 = 6.5; // initial value of v2_Vm2
        v3_Ky = 0.2; // initial value of v3_Ky
        v3_Vm3 = 50.0; // initial value of v3_Vm3
        v4_Kf = 1.0; // initial value of v4_Kf
        v5_K = 10.0; // initial value of v5_K
        v6_Kd = 5000.0; // initial value of v6_Kd
        v7_Kr = 5.0; // initial value of v7_Kr
        vin_v0 = 1.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_vin;
    protected double extracellular;
    protected double a;
    protected double beta;
    protected double d;
    protected double v2_K2;
    protected double v2_Vm2;
    protected double v3_Ky;
    protected double v3_Vm3;
    protected double v4_Kf;
    protected double v5_K;
    protected double v6_Kd;
    protected double v7_Kr;
    protected double vin_v0;
    protected double vin_v1;

    public double[] extendResult(double time,double [] x)
    {
        this.time = time;


        double[] y = new double[5];
        y[0] = x[0];
        y[1] = x[1];
        y[2] = x[2];
        y[3] = x[3];
        y[4] = x[4];
        return y;
    }
    public double[] getInitialValues()
    {
        double [] x = new double[5];
        this.time = 0.0;
        x[0] = 0.0; // - $"extracellular.cytosol.Fraction_Inactive_Channels"
        x[1] = 0.0; // - $"extracellular.cytosol.Rho"
        x[2] = 0.0; // - $"extracellular.cytosol.Z"
        x[3] = 0.36; // - $"extracellular.cytosol.intravesicular.Y"
        x[4] = 0.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 'BIOMD0000000043.xml' model
         */
    public void __internalDyDt_0(double time, double [] x, double[] result)
    {
        result[0] = +rate_v6-rate_v7;
        result[1] = -rate_v6+rate_v7;
        result[2] = -rate_v2+rate_v3+rate_v4-rate_v5+rate_vin;
        result[3] = +rate_v2-rate_v3-rate_v4;
        result[4] = +rate_v5-rate_vin;
    }
    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 ...