/*
 * This code is generated by BioUML FrameWork 
 * for BIOMD0000000054.xml diagram  at 2008.03.20 15:04:39
 */
import biouml.plugins.simulation.ae.NewtonSolver;
import biouml.plugins.simulation.java.JavaBaseModel;
import ru.biosoft.math.MathRoutines;

public class BIOMD0000000054 extends JavaBaseModel
{

/*
 * Write rules to calculate equation parameters
 */
    private void __internalVarInitFunc_0(double time, double[] x)
    {
        T = (x[0] + 3*x[1] - Math.pow((6*x[0]*x[1] - 3*Math.pow(x[1], 2) + Math.pow(x[0], 2)), 0.5))/6;
        M = (7*x[0] - 3*x[1] - Math.pow((6*x[0]*x[1] - 3*Math.pow(x[1], 2) + Math.pow(x[0], 2)), 0.5))/6;
    }


/*
 * Write rules to calculate equation parameters excluding internal variables.
 */
    public void __internalRateVarInitFunc_0(double time, double[] x)
    {
        rate_U1 = cell*P*J;
        rate_U2 = cell*W2*x[2]*T;
        rate_U3 = cell*W3*Math.pow(T, 0.52)*Math.pow(M, 0.41);
        rate_U6_plus_3U7 = cell*2*U;
        rate_U6_plus_U7_minus_U8 = cell*U*(1 - W*Math.pow(T, n)*Math.pow(M, k));
    }

    public void Init()
    {
        initialValues = getInitialValues();
/*
 * Initialize variables
 */
        cell = 1.0; // initial value of $cell
        J = 100.0; // initial value of J
        M = 0.01; // initial value of M
        P = 0.121; // initial value of P
        T = 1.0; // initial value of T
        U = 0.02; // initial value of U
        W = 0.01; // initial value of W
        W2 = 0.2; // initial value of W2
        W3 = 13.48; // initial value of W3
        k = -1.0; // initial value of k
        n = 1.2; // initial value of n
    }

    /*
     * Model variables initial values
     */
    protected double rate_U1;
    protected double rate_U2;
    protected double rate_U3;
    protected double rate_U6_plus_3U7;
    protected double rate_U6_plus_U7_minus_U8;
    protected double cell;
    protected double J;
    protected double M;
    protected double P;
    protected double T;
    protected double U;
    protected double W;
    protected double W2;
    protected double W3;
    protected double k;
    protected double n;

    public double[] extendResult(double time,double [] x)
    {
        this.time = time;

        __internalVarInitFunc_0(time, x);

        double[] y = new double[5];
        y[0] = x[0];
        y[1] = x[1];
        y[2] = x[2];
        y[3] = M;
        y[4] = T;
        return y;
    }
    public double[] getInitialValues()
    {
        double [] x = new double[3];
        this.time = 0.0;
        x[0] = 1.11; // - $"cell.A"
        x[1] = 2.1; // - $"cell.E"
        x[2] = 10.0; // - $"cell.I"

        __internalVarInitFunc_0(time, x);
        __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)
    {

        __internalVarInitFunc_0(time, x);
        __internalRateVarInitFunc_0(time, x);

    }

        /*
         * calculate dy/dt for 'BIOMD0000000054.xml' model
         */
    public void __internalDyDt_0(double time, double [] x, double[] result)
    {
        result[0] = +rate_U6_plus_U7_minus_U8;
        result[1] = -rate_U2+rate_U3-rate_U6_plus_3U7;
        result[2] = +rate_U1-rate_U2*3;
    }
    protected double [] calculateResult(double time, double[] x)
    {
        double[] result = new double[3];
        __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 ...