/*
 * This code is generated by BioUML FrameWork 
 * for BIOMD0000000024.xml diagram  at 2008.03.20 15:04:01
 */
import biouml.plugins.simulation.ae.NewtonSolver;
import biouml.plugins.simulation.java.JavaBaseModel;
import ru.biosoft.math.MathRoutines;

public class BIOMD0000000024 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_Md = compartment_0000004*Md_qM*(x[0]/compartment_0000004);
        rate_Pd = compartment_0000004*Pd_qP*(x[1]/compartment_0000004);
        rate_TC = compartment_0000004*(TC_rM/(1 + Math.pow((x[1]/compartment_0000004/TC_k), TC_n)));
        rate_TL = compartment_0000004*TL_rP*Math.pow(delay(0, time - (TL_parameter_0000009)), TL_m);
    }

    public void Init()
    {
        initialValues = new double[2];
        initialValues = getInitialValues();
/*
 * Initialize variables
 */
        compartment_0000004 = 1.0E-15; // initial value of $compartment_0000004
        Md_qM = 0.21; // initial value of Md_qM
        Pd_qP = 0.21; // initial value of Pd_qP
        TC_k = 1.0; // initial value of TC_k
        TC_n = 2.0; // initial value of TC_n
        TC_rM = 1.0; // initial value of TC_rM
        TL_m = 3.0; // initial value of TL_m
        TL_parameter_0000009 = 4.0; // initial value of TL_parameter_0000009
        TL_rP = 1.0; // initial value of TL_rP
    }

    /*
     * Model variables initial values
     */
    protected double _compartment_0000004_EmptySet_;
    protected double rate_Md;
    protected double rate_Pd;
    protected double rate_TC;
    protected double rate_TL;
    protected double compartment_0000004;
    protected double Md_qM;
    protected double Pd_qP;
    protected double TC_k;
    protected double TC_n;
    protected double TC_rM;
    protected double TL_m;
    protected double TL_parameter_0000009;
    protected double TL_rP;

/*
 * Returns "historical" variables in one array
 */
    public double[] getHistory(double t, double[] extendedY)
    {
        double[] history = new double[1];
        history[0] = extendedY[0];
        return history;
    }

    public double[] extendResult(double time,double [] x)
    {
        this.time = time;


        double[] y = new double[2];
        y[0] = x[0];
        y[1] = x[1];
        return y;
    }
    public double[] getInitialValues()
    {
        double [] x = new double[2];
        this.time = 0.0;
        x[0] = 1.0E-15; // - $"compartment_0000004.M"
        x[1] = 1.0E-15; // - $"compartment_0000004.P"

        __internalRateVarInitFunc_0(time, x);

        return x;
    }

    public double[] getInitialValuesOfHistorycal()
    {
        double[] z = new double[1];
        return z;
    }
/*
 * 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 'BIOMD0000000024.xml' model
         */
    public void __internalDyDt_0(double time, double [] x, double[] result)
    {
        result[0] = -rate_Md+rate_TC;
        result[1] = -rate_Pd+rate_TL;
    }
    protected double [] calculateResult(double time, double[] x)
    {
        double[] result = new double[2];
        __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 ...