/*
 * This code is generated by BioUML FrameWork 
 * for BIOMD0000000065.xml diagram  at 2008.03.20 15:04:52
 */
import biouml.plugins.simulation.ae.NewtonSolver;
import biouml.plugins.simulation.java.JavaBaseModel;
import ru.biosoft.math.MathRoutines;

public class BIOMD0000000065 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_r_a1 = cell*x[0]*(gamma_A + mu);
        rate_r_a2 = cell*beta_A*x[1]*(x[0]/(K_A + x[0]));
        rate_r_a3_l1 = cell*alpha_A*x[1]*(x[2]/(K_L + x[2]));
        rate_r_b1 = cell*x[1]*(gamma_B + mu);
        rate_r_b2_i2 = cell*x[6]/tau_B;
        rate_r_i1 = cell*alpha_M*((K_1*Math.exp(mu*tau_M*-2.0)*Math.pow(x[0], 2) + 1)/(K + K_1*Math.exp(-2.0*mu*tau_M)*Math.pow(x[0], 2)));
        rate_r_i2 = cell*alpha_B*x[3]*Math.exp(-(mu*tau_B));
        rate_r_i3 = cell*alpha_P*x[3]*Math.exp(-1.0*mu*(tau_B + tau_P));
        rate_r_l2 = cell*x[2]*(gamma_L + mu);
        rate_r_l3 = cell*beta_L1*x[4]*(x[2]/(K_L1 + x[2]));
        rate_r_l4 = cell*alpha_L*x[4]*(_cell_L_e_/(K_Le + _cell_L_e_));
        rate_r_m1 = cell*gamma_0;
        rate_r_m2 = cell*x[3]*(gamma_M + mu);
        rate_r_m3_i1 = cell*x[5]/tau_M;
        rate_r_p1 = cell*x[4]*(gamma_P + mu);
        rate_r_p2_i3 = cell*x[7]/(tau_B + tau_P);
    }

    public void Init()
    {
        initialValues = getInitialValues();
/*
 * Initialize variables
 */
        _cell_L_e_ = 0.08; // initial value of $"cell.L_e"
        cell = 1.0; // initial value of $cell
        K = 7200.0; // initial value of K
        K_1 = 25200.0; // initial value of K_1
        K_A = 1.95; // initial value of K_A
        K_L = 0.97; // initial value of K_L
        K_L1 = 1.81; // initial value of K_L1
        K_Le = 0.26; // initial value of K_Le
        alpha_A = 17600.0; // initial value of alpha_A
        alpha_B = 0.0166; // initial value of alpha_B
        alpha_L = 2880.0; // initial value of alpha_L
        alpha_M = 9.97E-4; // initial value of alpha_M
        alpha_P = 10.0; // initial value of alpha_P
        beta_A = 21500.0; // initial value of beta_A
        beta_L1 = 2650.0; // initial value of beta_L1
        gamma_0 = 7.25E-7; // initial value of gamma_0
        gamma_A = 0.52; // initial value of gamma_A
        gamma_B = 8.33E-4; // initial value of gamma_B
        gamma_M = 0.411; // initial value of gamma_M
        gamma_P = 0.65; // initial value of gamma_P
        mu = 0.0226; // initial value of mu
        tau_B = 2.0; // initial value of tau_B
        tau_M = 0.1; // initial value of tau_M
        tau_P = 0.83; // initial value of tau_P
    }

    /*
     * Model variables initial values
     */
    protected double _cell_L_e_;
    protected double rate_r_a1;
    protected double rate_r_a2;
    protected double rate_r_a3_l1;
    protected double rate_r_b1;
    protected double rate_r_b2_i2;
    protected double rate_r_i1;
    protected double rate_r_i2;
    protected double rate_r_i3;
    protected double rate_r_l2;
    protected double rate_r_l3;
    protected double rate_r_l4;
    protected double rate_r_m1;
    protected double rate_r_m2;
    protected double rate_r_m3_i1;
    protected double rate_r_p1;
    protected double rate_r_p2_i3;
    protected double cell;
    protected double K;
    protected double K_1;
    protected double K_A;
    protected double K_L;
    protected double K_L1;
    protected double K_Le;
    protected double alpha_A;
    protected double alpha_B;
    protected double alpha_L;
    protected double alpha_M;
    protected double alpha_P;
    protected double beta_A;
    protected double beta_L1;
    protected double gamma_0;
    protected double gamma_A;
    protected double gamma_B;
    protected double gamma_L;
    protected double gamma_M;
    protected double gamma_P;
    protected double mu;
    protected double tau_B;
    protected double tau_M;
    protected double tau_P;

    public double[] extendResult(double time,double [] x)
    {
        this.time = time;


        double[] y = new double[8];
        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];
        y[7] = x[7];
        return y;
    }
    public double[] getInitialValues()
    {
        double [] x = new double[8];
        this.time = 0.0;
        x[0] = 0.038; // - $"cell.A"
        x[1] = 0.0; // - $"cell.B"
        x[2] = 0.372; // - $"cell.L"
        x[3] = 6.26E-4; // - $"cell.M"
        x[4] = 0.0149; // - $"cell.P"
        x[5] = 0.0; // - $cell.I1
        x[6] = 0.0; // - $cell.I2
        x[7] = 0.0; // - $cell.I3

        __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 'BIOMD0000000065.xml' model
         */
    public void __internalDyDt_0(double time, double [] x, double[] result)
    {
        result[0] = -rate_r_a1-rate_r_a2+rate_r_a3_l1;
        result[1] = -rate_r_b1+rate_r_b2_i2;
        result[2] = -rate_r_a3_l1-rate_r_l2-rate_r_l3+rate_r_l4;
        result[3] = +rate_r_m1-rate_r_m2+rate_r_m3_i1;
        result[4] = -rate_r_p1+rate_r_p2_i3;
        result[5] = +rate_r_i1-rate_r_m3_i1;
        result[6] = -rate_r_b2_i2+rate_r_i2;
        result[7] = +rate_r_i3-rate_r_p2_i3;
    }
    protected double [] calculateResult(double time, double[] x)
    {
        double[] result = new double[8];
        __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 ...